@lizard-build/cli 4.0.105 โ 4.0.108
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.js +30 -8
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/support.d.ts +2 -0
- package/dist/commands/support.js +100 -0
- package/dist/commands/support.js.map +1 -0
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/api.js +13 -2
- package/dist/lib/api.js.map +1 -1
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.js +1 -1
- package/dist/lib/config.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/support.d.ts +28 -0
- package/dist/lib/support.js +112 -0
- package/dist/lib/support.js.map +1 -0
- package/dist/lib/updater.d.ts +1 -1
- package/dist/lib/updater.js +1 -1
- package/package.json +1 -1
- package/skill-data/core/SKILL.md +22 -1
- package/skill-data/core/references/sandboxes.md +1 -1
- package/src/commands/sandbox.ts +27 -7
- package/src/commands/support.ts +103 -0
- package/src/index.ts +20 -1
- package/src/lib/api.ts +12 -2
- package/src/lib/config.ts +1 -1
- package/src/lib/support.ts +112 -0
- package/src/lib/updater.ts +1 -1
- package/test/unit/sandbox.test.ts +5 -0
- package/test/unit/support.test.ts +52 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Support tickets from the CLI: what `lizard support` attaches, and the support inbox.
|
|
2
|
+
//
|
|
3
|
+
// Two small pieces of local state in ~/.lizard/support.json:
|
|
4
|
+
// - the last failed platform calls (method, path, status, error), so a ticket carries the real
|
|
5
|
+
// error even when an agent describes it vaguely;
|
|
6
|
+
// - which support replies have been shown, so a reply is printed after the next commands (twice
|
|
7
|
+
// at most) and then stays in `lizard support show`.
|
|
8
|
+
// The inbox is checked after a command at most once a minute (GET /api/support/unread) and
|
|
9
|
+
// printed to stderr, so --json output on stdout never changes.
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import chalk from "chalk";
|
|
14
|
+
import { configDir } from "./config.js";
|
|
15
|
+
import { CURRENT_VERSION } from "./updater.js";
|
|
16
|
+
import { detectAgent } from "./agent.js";
|
|
17
|
+
const CHECK_EVERY_MS = 60_000;
|
|
18
|
+
const SHOW_TIMES = 2;
|
|
19
|
+
function stateFile() { return path.join(configDir(), "support.json"); }
|
|
20
|
+
function load() {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(fs.readFileSync(stateFile(), "utf8"));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function save(s) {
|
|
29
|
+
try {
|
|
30
|
+
fs.mkdirSync(configDir(), { recursive: true, mode: 0o700 });
|
|
31
|
+
fs.writeFileSync(stateFile(), JSON.stringify(s), { mode: 0o600 });
|
|
32
|
+
}
|
|
33
|
+
catch { /* best effort */ }
|
|
34
|
+
}
|
|
35
|
+
/** Called for every failed platform call. Never throws. */
|
|
36
|
+
export function recordFailedCall(method, urlPath, status, error, requestId) {
|
|
37
|
+
if (urlPath.startsWith("/api/support/"))
|
|
38
|
+
return;
|
|
39
|
+
const s = load();
|
|
40
|
+
const entry = {
|
|
41
|
+
method, path: urlPath.split("?")[0], status,
|
|
42
|
+
error: String(error).replace(/\bliz_[A-Za-z0-9_-]{8,}/g, "liz_[redacted]").slice(0, 400),
|
|
43
|
+
...(requestId ? { requestId } : {}), at: new Date().toISOString(),
|
|
44
|
+
};
|
|
45
|
+
s.lastErrors = [...(s.lastErrors ?? []), entry].slice(-5);
|
|
46
|
+
save(s);
|
|
47
|
+
}
|
|
48
|
+
/** What a new ticket carries besides the message. Only the last hour's failures. */
|
|
49
|
+
export function ticketContext() {
|
|
50
|
+
const hourAgo = Date.now() - 3600_000;
|
|
51
|
+
const lastErrors = (load().lastErrors ?? []).filter((e) => Date.parse(e.at) > hourAgo);
|
|
52
|
+
return {
|
|
53
|
+
cliVersion: CURRENT_VERSION,
|
|
54
|
+
os: `${os.platform()} ${os.arch()} node ${process.versions.node}`,
|
|
55
|
+
...(lastErrors.length ? { lastErrors } : {}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function agentName() {
|
|
59
|
+
return detectAgent() ?? undefined;
|
|
60
|
+
}
|
|
61
|
+
/** Server-side or network failures are worth a ticket; a 4xx about the request usually is not. */
|
|
62
|
+
export function isPlatformFailure(status, netCode) {
|
|
63
|
+
if (process.env.AGENT_SUPPORT === "0")
|
|
64
|
+
return false;
|
|
65
|
+
if (status === undefined)
|
|
66
|
+
return !!netCode;
|
|
67
|
+
return status >= 500 || status === 408;
|
|
68
|
+
}
|
|
69
|
+
export const SUPPORT_HINT = 'If this keeps failing, tell the Lizard team: lizard support open "<what you ran and what happened>" (the error above is attached automatically)';
|
|
70
|
+
/**
|
|
71
|
+
* Prints support replies the user has not seen yet, after a command. Throttled to one request
|
|
72
|
+
* a minute; each reply is printed at most twice. Never throws and never waits more than 2 s.
|
|
73
|
+
*/
|
|
74
|
+
export async function printSupportInbox(fetchUnread, opts = {}) {
|
|
75
|
+
try {
|
|
76
|
+
const s = load();
|
|
77
|
+
if (!opts.force && s.checkedAt && Date.now() - s.checkedAt < CHECK_EVERY_MS)
|
|
78
|
+
return;
|
|
79
|
+
s.checkedAt = Date.now();
|
|
80
|
+
save(s);
|
|
81
|
+
const res = await Promise.race([
|
|
82
|
+
fetchUnread(),
|
|
83
|
+
new Promise((r) => setTimeout(() => r(null), 2000).unref()),
|
|
84
|
+
]);
|
|
85
|
+
if (!res?.tickets?.length)
|
|
86
|
+
return;
|
|
87
|
+
const shown = { ...(load().shown ?? {}) };
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const t of res.tickets) {
|
|
90
|
+
const fresh = t.messages.filter((m) => (shown[`${t.ticket}@${m.at}`] ?? 0) < SHOW_TIMES);
|
|
91
|
+
if (!fresh.length)
|
|
92
|
+
continue;
|
|
93
|
+
out.push(chalk.bold.green(`๐ฌ Lizard support replied on ${t.ticket}`) + chalk.dim(` (${t.subject})`));
|
|
94
|
+
for (const m of fresh) {
|
|
95
|
+
shown[`${t.ticket}@${m.at}`] = (shown[`${t.ticket}@${m.at}`] ?? 0) + 1;
|
|
96
|
+
out.push(chalk.dim(` ${m.from}:`));
|
|
97
|
+
for (const line of m.body.split("\n"))
|
|
98
|
+
out.push(` ${line}`);
|
|
99
|
+
}
|
|
100
|
+
out.push(chalk.dim(` โ answer: lizard support reply ${t.ticket} "<your answer>" ยท full thread: lizard support show ${t.ticket}`));
|
|
101
|
+
}
|
|
102
|
+
// Forget entries for replies that are no longer unread.
|
|
103
|
+
const live = new Set(res.tickets.flatMap((t) => t.messages.map((m) => `${t.ticket}@${m.at}`)));
|
|
104
|
+
const next = load();
|
|
105
|
+
next.shown = Object.fromEntries(Object.entries(shown).filter(([k]) => live.has(k)));
|
|
106
|
+
save(next);
|
|
107
|
+
if (out.length)
|
|
108
|
+
process.stderr.write("\n" + out.join("\n") + "\n");
|
|
109
|
+
}
|
|
110
|
+
catch { /* the inbox must never break a command */ }
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"support.js","sourceRoot":"","sources":["../../src/lib/support.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,EAAE;AACF,6DAA6D;AAC7D,gGAAgG;AAChG,oDAAoD;AACpD,iGAAiG;AACjG,uDAAuD;AACvD,2FAA2F;AAC3F,+DAA+D;AAC/D,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc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AAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpF,IAAI,CAAC,IAAI,CAAC,CAAC;QACX,IAAI,GAAG,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC,CAAC,0CAA0C,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/lib/updater.d.ts
CHANGED
package/dist/lib/updater.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Readable } from "node:stream";
|
|
|
4
4
|
import { join, dirname } from "node:path";
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
|
-
export const CURRENT_VERSION = "4.0.
|
|
7
|
+
export const CURRENT_VERSION = "4.0.108";
|
|
8
8
|
const RELEASES_API = "https://api.github.com/repos/lizard-build/lizard-cli/releases/latest";
|
|
9
9
|
const RELEASE_BASE = "https://github.com/lizard-build/lizard-cli/releases/latest/download";
|
|
10
10
|
/** Minimum gap between background update checks. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lizard-build/cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.108",
|
|
4
4
|
"description": "Lizard CLI โ deploy apps, databases and sandboxes to Lizard (lizard.build) from your terminal or your coding agent. Detects Go, Node, Python, Rust, Ruby, PHP, Java and static sites; adds Managed Postgres, Managed Redis and Managed Object Storage in one command.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/skill-data/core/SKILL.md
CHANGED
|
@@ -26,6 +26,7 @@ If `$ARGUMENTS` is non-empty, treat it as the user's request and act on it. If e
|
|
|
26
26
|
4. Resolve context before any change: `lizard status --json` shows whether this exact folder is linked. `linked: false` means commands go to the [default project](#default-project); pass `--project` when it matters. Confirm the project, service or sandbox you target.
|
|
27
27
|
5. A network error (`fetch failed`, `UND_ERR_SOCKET`, `ECONNRESET`) is not an answer: run the command again. Before repeating a create, check with `list` / `ps` that the first attempt did not land.
|
|
28
28
|
6. For destructive actions (delete a service, sandbox, volume or project, drop an addon, overwrite a project-wide secret, restart production), confirm with the user first. Without a terminal the CLI never asks: `sandbox rm`, `volume delete`, `keys delete` and `workspace rm` delete at once; `service`, `project`, `secrets` and `domain` deletes and billing changes refuse until you add `-y`. Add `-y` only after the user agrees.
|
|
29
|
+
7. When Lizard itself is broken, or a plan or limit blocks the task, open a support ticket: see [Support](#support). After any command, read stderr for `๐ฌ Lizard support replied`: answer support's questions there.
|
|
29
30
|
|
|
30
31
|
## Deploy command output
|
|
31
32
|
|
|
@@ -296,6 +297,25 @@ Skip command-by-command transcripts unless they explain a failure.
|
|
|
296
297
|
5. Don't generate Dockerfiles unsolicited โ lizardpack auto-detects most stacks. Try a deploy first; write one only if it fails. Ask before either.
|
|
297
298
|
6. Don't put runtime secrets (DB credentials, API keys, RPC creds, S3 keys) in `--global` "just in case another service needs it later". Scope to the services that consume them โ see [Secrets and config](#secrets-and-config).
|
|
298
299
|
|
|
300
|
+
## Support
|
|
301
|
+
|
|
302
|
+
`lizard support` sends a ticket to the Lizard team (a person reads it within minutes in working hours). When to open one:
|
|
303
|
+
|
|
304
|
+
- **Bug, open it yourself without asking** (it describes Lizard's failure, not the user's code) when Lizard fails: the same command fails twice with a 5xx, a timeout or `internal error`; a sandbox, app or database is stuck (`creating`, `pausing`, `deploying` for minutes) or crashed with no cause in its own logs; a documented command behaves differently from this guide. Failed commands print a hint on stderr (`support` in the JSON error) when this applies.
|
|
305
|
+
- **Limits or billing, ask the user first** (it asks the team for more on their behalf): a plan or limit blocks what the user is doing and they need more, such as vCPU or sandbox limits, a region or size their plan does not include, rate limits, a bigger plan. With their OK, use `--type limits` (or `billing`) and say what is needed and why (numbers, for how long).
|
|
306
|
+
|
|
307
|
+
```sh
|
|
308
|
+
lizard support open "sandbox create in eu-west-lim-a returns 500" --expected "sandbox running" --actual "500 internal error, 3 tries since 17:40" --sandbox <id> --json
|
|
309
|
+
lizard support open "need 100 vCPU of sandboxes for a batch job next week; trial allows 8" --type limits --json
|
|
310
|
+
lizard support list --json # tickets, status, unread replies
|
|
311
|
+
lizard support show T-1043 --json # the whole thread; marks replies read
|
|
312
|
+
lizard support reply T-1043 "request id r_8f2โฆ, still failing at 18:05" --json
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Write the ticket like a bug report: what you ran, what happened (the exact error), what you expected, since when. Your last failed Lizard calls, CLI version and OS are attached automatically; `--sandbox` / `--app` attach that resource's state. Never put secrets, keys or customer data in a ticket. Types: `bug` (default), `limits`, `billing`, `question`. Filing the same problem again does not open a new ticket: the answer has `similarId` (the open ticket) and `similarCount`; add details there with `lizard support reply`. At most 5 new tickets an hour. `AGENT_SUPPORT=0` in the environment means the user turned agent tickets off: don't open any.
|
|
316
|
+
|
|
317
|
+
After opening one, tell the user the ticket id and continue with whatever does not depend on the fix. Replies from the team are printed on stderr after your next `lizard` command (`๐ฌ Lizard support replied on T-1043`) and emailed to the account owner. When support asks a question, answer with `lizard support reply` and tell the user what was asked. Don't open tickets for the user's own build errors, app bugs or wrong commands.
|
|
318
|
+
|
|
299
319
|
## Billing
|
|
300
320
|
|
|
301
321
|
Billing belongs to the account owner. `lizard billing --workspace <id> --json` shows the plan of another workspace's owner.
|
|
@@ -354,7 +374,8 @@ and `body.status` with the links:
|
|
|
354
374
|
vCPU of sandboxes at once, or too many starts per minute, hour or day, is HTTP 429,
|
|
355
375
|
not a billing problem. `SANDBOX_LIMIT_REACHED` has `unit: "vcpu"`, `limit`, `running` (vCPU in use)
|
|
356
376
|
and `needed` (vCPU the new sandbox needs): pause or delete idle sandboxes, pick a
|
|
357
|
-
smaller size, or ask the user about a higher Pro tier
|
|
377
|
+
smaller size, or ask the user about a higher Pro tier; if the task needs more than any tier
|
|
378
|
+
gives, open a `lizard support open โฆ --type limits` ticket. `SANDBOX_RATE_LIMITED` has
|
|
358
379
|
`retryAfterS`: wait that long; on the trial, the first paid invoice lifts the start
|
|
359
380
|
limits. A workspace can also have its own limits, set by its owner
|
|
360
381
|
(`lizard workspace limits <ws>` shows them with current use): `WORKSPACE_SANDBOX_LIMIT`
|
|
@@ -167,7 +167,7 @@ A volume attaches to one sandbox at a time (409 `Volume is already attached to a
|
|
|
167
167
|
|
|
168
168
|
## Snapshots and pause/resume
|
|
169
169
|
|
|
170
|
-
- `lizard sandbox snapshot <sandbox-id> --name my-app` saves files and running
|
|
170
|
+
- `lizard sandbox snapshot <sandbox-id> --name my-app` saves the sandbox's files (about a second whatever its RAM); sandboxes started from it boot fresh with them. `--full` (API `{"full": true}` / `{"memory": true}`) also saves memory and running processes, so new sandboxes continue where it was (a warmed-up REPL, a started server); it takes longer the more RAM is in use. The answer says what was kept (`withMemory`); where a files-only snapshot is not available yet it is taken with memory and says so in `fastSnapshotUnavailable`. You and the members of its project can list, restore and delete it; only you change its scope. By default it restores into any of your projects and workspaces; `--scope workspace` keeps it to the sandbox's workspace and `--scope project` to its project, and `sandbox snapshot-scope <id> <user|workspace|project>` changes that later. A Firecracker snapshot is ready as soon as the capture ends; the command waits until ready; `--no-wait` returns the queued capture.
|
|
171
171
|
- `lizard sandbox restore <snapshot-id> [--project <project>] [--timeout <ms>]` starts a new sandbox from it (five-minute lifetime by default), in the snapshot's project unless `--project` names another. `--volume <volume>` mounts a volume at `/workspace` in the restored sandbox (Firecracker snapshots of a sandbox that had no volume attached; the volume must be in the snapshot's region). `sandbox create --snapshot <id> --project <project> [--volume <volume>]` also works. Restores stay in the snapshot's region. A snapshot restores at its source's size and bills flat at that size. `--size` with `--snapshot` is an error.
|
|
172
172
|
- `lizard sandbox snapshots --project <project>` lists a project's snapshots; `--mine` lists every snapshot you took. `sandbox snapshot-rm <id>` deletes the snapshot; sandboxes already started from it keep running.
|
|
173
173
|
- `lizard sandbox fork <sandbox-id> [-n <count>] [--timeout <ms>] --json` starts 1โ100 live copies of a running sandbox: the platform pauses it for a moment, captures memory, processes and files once, and boots every copy from that capture; the source keeps its id and lifetime. Use it to fan out work from one prepared sandbox (tools installed, app loaded) without repeating the setup. Each copy is a sandbox start: it counts toward the running and start limits, runs at the source's size and bills like a new sandbox. The JSON is one entry per copy, `{ "sandbox": {โฆ} }` or `{ "error": "โฆ" }` (for example `Sandbox limit reached`); if any copy failed the command exits `1`, and the copies that did start keep running until you delete them. `--timeout` takes at least `1000`; leave it out to keep the source's lifetime. A sandbox with a volume attached can't be forked (409), and `fork` needs a running sandbox (409 for a paused one).
|
package/src/commands/sandbox.ts
CHANGED
|
@@ -4,7 +4,7 @@ import fs from "node:fs";
|
|
|
4
4
|
import * as https from "node:https";
|
|
5
5
|
import * as http from "node:http";
|
|
6
6
|
import * as p from "@clack/prompts";
|
|
7
|
-
import { Command, Option } from "commander";
|
|
7
|
+
import { Command, InvalidArgumentError, Option } from "commander";
|
|
8
8
|
import open from "open";
|
|
9
9
|
import { api, APIError, getBaseURL, getRawBytes, apiErrorFrom, clientHeaders, getRequestToken, withQuery, withScope, type ResourceScope } from "../lib/api.js";
|
|
10
10
|
import { getToken } from "../lib/auth.js";
|
|
@@ -27,6 +27,14 @@ const TEMPLATE_HINT = "base, interpreter, codex, claude, opencode, pi, prime, de
|
|
|
27
27
|
// platform rejects anything else, so the CLI offers exactly these.
|
|
28
28
|
const SANDBOX_SIZES = ["small", "medium", "large"] as const;
|
|
29
29
|
const SIZE_HINT = "small 2 vCPU/4 GB, medium 4/8, large 8/16";
|
|
30
|
+
// Sizes open only to accounts the platform enables (mini: 1 vCPU/2 GB). Accepted here but not
|
|
31
|
+
// advertised in the help; the server refuses them for everyone else (SANDBOX_SIZE_NOT_ALLOWED).
|
|
32
|
+
const GATED_SANDBOX_SIZES = ["mini"] as const;
|
|
33
|
+
|
|
34
|
+
function parseSandboxSize(v: string): string {
|
|
35
|
+
if ((SANDBOX_SIZES as readonly string[]).includes(v) || (GATED_SANDBOX_SIZES as readonly string[]).includes(v)) return v;
|
|
36
|
+
throw new InvalidArgumentError(`Allowed choices are ${SANDBOX_SIZES.join(", ")}.`);
|
|
37
|
+
}
|
|
30
38
|
|
|
31
39
|
interface SandboxRecord {
|
|
32
40
|
sandboxId: string;
|
|
@@ -170,7 +178,7 @@ export function registerSandbox(program: Command) {
|
|
|
170
178
|
sb.command("create")
|
|
171
179
|
.description("Create a sandbox")
|
|
172
180
|
.option("-t, --template <name>", `Template (${TEMPLATE_HINT}; server validates)`, "base")
|
|
173
|
-
.addOption(new Option("-s, --size <size>", `Machine size (${SIZE_HINT}); default medium, small during the Pro trial (Small in US regions only)`).
|
|
181
|
+
.addOption(new Option("-s, --size <size>", `Machine size (${SIZE_HINT}); default medium, small during the Pro trial (Small in US regions only)`).argParser(parseSandboxSize))
|
|
174
182
|
.option("--timeout <ms>", "Lifetime in milliseconds; 0 disables expiration", parseTimeoutOption, 300_000)
|
|
175
183
|
.option("--region <code>", `Region to create the sandbox in (default ${DEFAULT_REGION}; with --volume or --snapshot, theirs)`)
|
|
176
184
|
.option("--snapshot <id>", "Create from a private saved snapshot, at the size it was taken at")
|
|
@@ -598,14 +606,26 @@ Examples:
|
|
|
598
606
|
.addOption(new Option("--scope <scope>", "Where it may be restored: user = any of your projects and workspaces, workspace = only this workspace, project = only this project. Default: user, or with a workspace/project-scoped key only what the key covers")
|
|
599
607
|
.choices(SNAPSHOT_SCOPES))
|
|
600
608
|
.option("--no-wait", "Return once capture is queued")
|
|
601
|
-
|
|
609
|
+
// Files only by default (the platform's): about a second whatever the RAM, sandboxes started
|
|
610
|
+
// from it boot fresh. --full keeps memory and processes too. Sent as memory: true/false, which
|
|
611
|
+
// servers older than the "full" name accept; no flag = the platform's default.
|
|
612
|
+
.option("--full", "Also save memory and running processes: sandboxes started from it continue where this one was (slower to take)")
|
|
613
|
+
.option("--fast", "Files only (the default)")
|
|
614
|
+
.description("Save a running sandbox's files (--full: also its memory and running processes)")
|
|
602
615
|
.action(async (id: string, opts) => {
|
|
616
|
+
if (opts.full && opts.fast) throw new Error("Use either --full or --fast, not both");
|
|
603
617
|
// No pool size: Firecracker and gVisor snapshots keep no warm copies, and a runc pod
|
|
604
618
|
// (the fallback when a Firecracker create fails) gets the server's default.
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
619
|
+
const choice = opts.full ? { memory: true } : opts.fast ? { memory: false } : {};
|
|
620
|
+
const taken = await api.post<SnapshotRecord & { withMemory?: boolean; fastSnapshotUnavailable?: string }>(`/api/sandboxes/${id}/snapshot`, { name: opts.name, scope: opts.scope, ...choice });
|
|
621
|
+
let snapshot: SnapshotRecord = taken;
|
|
622
|
+
if (opts.wait) snapshot = await waitForSnapshot(taken.id);
|
|
623
|
+
if (isJSONMode()) printJSON({ ...snapshot, ...(taken.withMemory !== undefined ? { withMemory: taken.withMemory } : {}), ...(taken.fastSnapshotUnavailable ? { fastSnapshotUnavailable: taken.fastSnapshotUnavailable } : {}) });
|
|
624
|
+
else {
|
|
625
|
+
success(`Snapshot ${chalk.bold(snapshot.id)}: ${snapshot.status}${taken.withMemory === true ? " (with memory)" : taken.withMemory === false ? " (files only)" : ""}`);
|
|
626
|
+
if (taken.withMemory === false) info(`Sandboxes started from it boot fresh with these files (use ${chalk.bold("--full")} to keep running processes).`);
|
|
627
|
+
if (taken.fastSnapshotUnavailable) info(taken.fastSnapshotUnavailable + ".");
|
|
628
|
+
}
|
|
609
629
|
});
|
|
610
630
|
|
|
611
631
|
for (const operation of ["pause", "resume"] as const) {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { Command, Option } from "commander";
|
|
3
|
+
import { api } from "../lib/api.js";
|
|
4
|
+
import { getProjectLink } from "../lib/config.js";
|
|
5
|
+
import { fail, isJSONMode, printJSON, table, timeAgo } from "../lib/format.js";
|
|
6
|
+
import { agentName, ticketContext } from "../lib/support.js";
|
|
7
|
+
|
|
8
|
+
/** AGENT_SUPPORT=0 turns off agent-opened tickets on this machine (support.md proposal 4.4). A person
|
|
9
|
+
* typing the command is not an agent, so it still works for them. */
|
|
10
|
+
function agentSupportOff(): boolean {
|
|
11
|
+
return process.env.AGENT_SUPPORT === "0" && !!agentName();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface TicketView { id: string; type: string; subject: string; status: string; source: string; createdAt: string; updatedAt: string; unread: number }
|
|
15
|
+
|
|
16
|
+
const TYPES = ["bug", "limits", "billing", "question"];
|
|
17
|
+
|
|
18
|
+
function joinMessage(words: string[]): string {
|
|
19
|
+
const m = words.join(" ").trim();
|
|
20
|
+
if (!m) fail("Write what happened, e.g. lizard support open \"sandbox create in eu returns 500 since 10:00\"", 1, "MISSING_MESSAGE");
|
|
21
|
+
return m;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function registerSupport(program: Command) {
|
|
25
|
+
const support = program
|
|
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.");
|
|
28
|
+
|
|
29
|
+
support
|
|
30
|
+
.command("open")
|
|
31
|
+
.description("Open a ticket. Your last failed Lizard calls, CLI version and OS are attached automatically.")
|
|
32
|
+
.argument("<message...>", "What you did, what happened, what you expected")
|
|
33
|
+
.addOption(new Option("-t, --type <type>", "bug | limits | billing | question").choices(TYPES).default("bug"))
|
|
34
|
+
.option("--sandbox <id>", "The sandbox this is about (its state is attached)")
|
|
35
|
+
.option("--app <name-or-id>", "The app this is about (its state is attached)")
|
|
36
|
+
.option("--expected <text>", "What should have happened")
|
|
37
|
+
.option("--actual <text>", "What happened instead (the exact error)")
|
|
38
|
+
.option("--repro <text>", "Shortest steps or commands that show it")
|
|
39
|
+
.action(async (words: string[], opts: { type: string; sandbox?: string; app?: string; expected?: string; actual?: string; repro?: string }) => {
|
|
40
|
+
if (agentSupportOff()) fail("Agent support tickets are turned off on this machine (AGENT_SUPPORT=0). Tell the user what failed instead.", 1, "AGENT_SUPPORT_OFF");
|
|
41
|
+
const message = joinMessage(words);
|
|
42
|
+
const link = getProjectLink();
|
|
43
|
+
const res = await api.post<TicketView & { similarId?: string; similarCount?: number; note?: string }>("/api/support/tickets", {
|
|
44
|
+
message,
|
|
45
|
+
type: opts.type,
|
|
46
|
+
source: "cli",
|
|
47
|
+
agent: agentName(),
|
|
48
|
+
sandboxId: opts.sandbox,
|
|
49
|
+
appId: opts.app,
|
|
50
|
+
expected: opts.expected,
|
|
51
|
+
actual: opts.actual,
|
|
52
|
+
repro: opts.repro,
|
|
53
|
+
workspaceId: link?.workspaceId ?? undefined,
|
|
54
|
+
context: ticketContext(),
|
|
55
|
+
});
|
|
56
|
+
if (isJSONMode()) return printJSON(res);
|
|
57
|
+
console.log(chalk.green("โ") + ` ${res.similarId ? "Already open as" : "Opened"} ${chalk.bold(res.id)} โ ${res.subject}`);
|
|
58
|
+
if (res.note) console.log(chalk.dim(res.note));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
support
|
|
62
|
+
.command("list")
|
|
63
|
+
.alias("ls")
|
|
64
|
+
.description("Your tickets, newest activity first")
|
|
65
|
+
.action(async () => {
|
|
66
|
+
const { tickets } = await api.get<{ tickets: TicketView[] }>("/api/support/tickets");
|
|
67
|
+
if (isJSONMode()) return printJSON(tickets);
|
|
68
|
+
if (!tickets.length) return console.log("No tickets.");
|
|
69
|
+
table(["Ticket", "Type", "Status", "Updated", "Subject"], tickets.map((t) => [
|
|
70
|
+
t.unread ? chalk.green(`${t.id} โข${t.unread} new`) : t.id, t.type, t.status, timeAgo(t.updatedAt), t.subject,
|
|
71
|
+
]));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
support
|
|
75
|
+
.command("show")
|
|
76
|
+
.description("A ticket with every message; marks support's replies as read")
|
|
77
|
+
.argument("<ticket>", "Ticket id, e.g. T-1043")
|
|
78
|
+
.action(async (ref: string) => {
|
|
79
|
+
const t = await api.get<TicketView & { messages: Array<{ from: string; body: string; at: string }> }>(
|
|
80
|
+
`/api/support/tickets/${encodeURIComponent(ref)}`);
|
|
81
|
+
if (isJSONMode()) return printJSON(t);
|
|
82
|
+
console.log(chalk.bold(`${t.id} ยท ${t.type} ยท ${t.status}`) + chalk.dim(` opened ${timeAgo(t.createdAt)}`));
|
|
83
|
+
for (const m of t.messages) {
|
|
84
|
+
console.log("");
|
|
85
|
+
console.log((m.from === "you" ? chalk.cyan(m.from) : chalk.green(m.from)) + chalk.dim(` ${timeAgo(m.at)}`));
|
|
86
|
+
console.log(m.body);
|
|
87
|
+
}
|
|
88
|
+
console.log("");
|
|
89
|
+
console.log(chalk.dim(`Answer: lizard support reply ${t.id} "โฆ"`));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
support
|
|
93
|
+
.command("reply")
|
|
94
|
+
.description("Add to a ticket: answer support's question, or add new details")
|
|
95
|
+
.argument("<ticket>", "Ticket id, e.g. T-1043")
|
|
96
|
+
.argument("<message...>", "Your answer")
|
|
97
|
+
.action(async (ref: string, words: string[]) => {
|
|
98
|
+
const res = await api.post<{ ok: boolean; ticket: string }>(
|
|
99
|
+
`/api/support/tickets/${encodeURIComponent(ref)}/messages`, { message: joinMessage(words) });
|
|
100
|
+
if (isJSONMode()) return printJSON(res);
|
|
101
|
+
console.log(chalk.green("โ") + ` Sent to the Lizard team on ${res.ticket}`);
|
|
102
|
+
});
|
|
103
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Command } from "commander";
|
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { setJSONMode, isJSONMode, error } from "./lib/format.js";
|
|
6
6
|
import { requireAuth, isLoggedIn } from "./lib/auth.js";
|
|
7
|
-
import { setBaseURL, setAccessToken, APIError, isProjectDeletedError, isAccountScopeError } from "./lib/api.js";
|
|
7
|
+
import { api, getRequestToken, setBaseURL, setAccessToken, APIError, isProjectDeletedError, isAccountScopeError } from "./lib/api.js";
|
|
8
8
|
import { checkForUpdateInBackground, runBackgroundUpdate, CURRENT_VERSION } from "./lib/updater.js";
|
|
9
9
|
|
|
10
10
|
const BANNER = chalk.rgb(16, 185, 129)(
|
|
@@ -102,6 +102,8 @@ import { registerUp } from "./commands/up.js";
|
|
|
102
102
|
import { registerUpgrade } from "./commands/upgrade.js";
|
|
103
103
|
import { registerVolume } from "./commands/volume.js";
|
|
104
104
|
import { registerWhoami } from "./commands/whoami.js";
|
|
105
|
+
import { registerSupport } from "./commands/support.js";
|
|
106
|
+
import { printSupportInbox, isPlatformFailure, SUPPORT_HINT } from "./lib/support.js";
|
|
105
107
|
import { registerWorkspace } from "./commands/workspace.js";
|
|
106
108
|
|
|
107
109
|
const program = new Command();
|
|
@@ -197,6 +199,7 @@ registerSleep(program);
|
|
|
197
199
|
registerSecrets(program);
|
|
198
200
|
registerService(program);
|
|
199
201
|
registerSkill(program);
|
|
202
|
+
registerSupport(program);
|
|
200
203
|
registerSSH(program);
|
|
201
204
|
registerStatus(program);
|
|
202
205
|
registerUnlink(program);
|
|
@@ -342,6 +345,16 @@ function writeAndExit(payload: string, code: number): void {
|
|
|
342
345
|
process.stdout.write(payload, () => process.exit(code));
|
|
343
346
|
}
|
|
344
347
|
|
|
348
|
+
/** Support replies not seen yet, on stderr after the command (lib/support.ts). Skipped when not
|
|
349
|
+
* signed in and for `lizard support show`, which prints the thread itself. */
|
|
350
|
+
async function supportInbox(): Promise<void> {
|
|
351
|
+
const args = process.argv.slice(2).filter((a) => !a.startsWith("-"));
|
|
352
|
+
if (args[0] === "support" && args[1] === "show") return;
|
|
353
|
+
if (["login", "logout", "upgrade", "help", "docs", "skills"].includes(args[0] ?? "")) return;
|
|
354
|
+
if (!getRequestToken()) return;
|
|
355
|
+
await printSupportInbox(() => api.get("/api/support/unread"));
|
|
356
|
+
}
|
|
357
|
+
|
|
345
358
|
async function main() {
|
|
346
359
|
// Hidden entry point: detached child spawned by checkForUpdateInBackground.
|
|
347
360
|
// Handled before commander so it never shows up in help or telemetry.
|
|
@@ -414,6 +427,7 @@ async function main() {
|
|
|
414
427
|
|
|
415
428
|
try {
|
|
416
429
|
await program.parseAsync(process.argv);
|
|
430
|
+
await supportInbox();
|
|
417
431
|
} catch (err: any) {
|
|
418
432
|
// Commander throws for --help, --version, etc. โ ignore those
|
|
419
433
|
if (err.code === "commander.helpDisplayed" || err.code === "commander.version") {
|
|
@@ -494,6 +508,8 @@ async function main() {
|
|
|
494
508
|
netCode === "UND_ERR_CONNECT_TIMEOUT";
|
|
495
509
|
|
|
496
510
|
const exitCode = isAuth ? 2 : isNotFound ? 3 : isTimeout ? 4 : 1;
|
|
511
|
+
// Lizard itself failed (5xx, timeout, network): point the agent at a ticket.
|
|
512
|
+
const showSupportHint = isPlatformFailure(status, netCode) && !process.argv.slice(2).includes("support");
|
|
497
513
|
|
|
498
514
|
if (isJSONMode()) {
|
|
499
515
|
// Through writeAndExit, not console.log + exit: `body` carries the raw
|
|
@@ -506,6 +522,7 @@ async function main() {
|
|
|
506
522
|
status: status ?? null,
|
|
507
523
|
message: msg,
|
|
508
524
|
body: apiErr?.body ?? null,
|
|
525
|
+
...(showSupportHint ? { support: SUPPORT_HINT } : {}),
|
|
509
526
|
},
|
|
510
527
|
},
|
|
511
528
|
null,
|
|
@@ -517,6 +534,8 @@ async function main() {
|
|
|
517
534
|
}
|
|
518
535
|
|
|
519
536
|
error(msg);
|
|
537
|
+
if (showSupportHint) process.stderr.write(chalk.dim(SUPPORT_HINT) + "\n");
|
|
538
|
+
await supportInbox();
|
|
520
539
|
if (status === 401) {
|
|
521
540
|
process.stderr.write("Run `lizard login` to re-authenticate.\n");
|
|
522
541
|
}
|
package/src/lib/api.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getToken } from "./auth.js";
|
|
2
2
|
import { CURRENT_VERSION } from "./updater.js";
|
|
3
3
|
import { detectAgent } from "./agent.js";
|
|
4
|
+
import { recordFailedCall } from "./support.js";
|
|
4
5
|
import * as https from "node:https";
|
|
5
6
|
import * as http from "node:http";
|
|
6
7
|
|
|
@@ -226,14 +227,23 @@ async function request<T = any>(
|
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
const init = { method, headers, body: body !== undefined ? JSON.stringify(body) : undefined };
|
|
229
|
-
|
|
230
|
+
let res: Response;
|
|
231
|
+
try {
|
|
232
|
+
res = method === "GET" ? await fetchWithRetry(url, init) : await fetch(url, init);
|
|
233
|
+
} catch (e: any) {
|
|
234
|
+
// Kept for `lizard support open`, which attaches the last failures to a ticket.
|
|
235
|
+
recordFailedCall(method, path, e?.cause?.code ?? e?.code ?? "network", e?.cause?.message ?? e?.message ?? String(e));
|
|
236
|
+
throw e;
|
|
237
|
+
}
|
|
230
238
|
|
|
231
239
|
if (!res.ok) {
|
|
232
240
|
let body: unknown = null;
|
|
233
241
|
try {
|
|
234
242
|
body = await res.json();
|
|
235
243
|
} catch {}
|
|
236
|
-
|
|
244
|
+
const err = apiErrorFrom(res.status, res.statusText, body);
|
|
245
|
+
recordFailedCall(method, path, res.status, err.message, res.headers.get("x-request-id"));
|
|
246
|
+
throw err;
|
|
237
247
|
}
|
|
238
248
|
|
|
239
249
|
const text = await res.text();
|
package/src/lib/config.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const DEFAULT_REGION = "us-east-1";
|
|
|
7
7
|
// Resolve at every call so tests (and exotic shells that mutate HOME) get a
|
|
8
8
|
// fresh path. Cost is negligible โ we hit disk anyway. LIZARD_HOME lets tests
|
|
9
9
|
// (and power users) point the config dir somewhere other than ~/.lizard.
|
|
10
|
-
function configDir(): string {
|
|
10
|
+
export function configDir(): string {
|
|
11
11
|
return process.env.LIZARD_HOME
|
|
12
12
|
? path.join(process.env.LIZARD_HOME, ".lizard")
|
|
13
13
|
: path.join(os.homedir(), ".lizard");
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Support tickets from the CLI: what `lizard support` attaches, and the support inbox.
|
|
2
|
+
//
|
|
3
|
+
// Two small pieces of local state in ~/.lizard/support.json:
|
|
4
|
+
// - the last failed platform calls (method, path, status, error), so a ticket carries the real
|
|
5
|
+
// error even when an agent describes it vaguely;
|
|
6
|
+
// - which support replies have been shown, so a reply is printed after the next commands (twice
|
|
7
|
+
// at most) and then stays in `lizard support show`.
|
|
8
|
+
// The inbox is checked after a command at most once a minute (GET /api/support/unread) and
|
|
9
|
+
// printed to stderr, so --json output on stdout never changes.
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import chalk from "chalk";
|
|
14
|
+
import { configDir } from "./config.js";
|
|
15
|
+
import { CURRENT_VERSION } from "./updater.js";
|
|
16
|
+
import { detectAgent } from "./agent.js";
|
|
17
|
+
|
|
18
|
+
interface FailedCall { method: string; path: string; status: number | string; error: string; requestId?: string; at: string }
|
|
19
|
+
interface SupportState { lastErrors?: FailedCall[]; checkedAt?: number; shown?: Record<string, number> }
|
|
20
|
+
|
|
21
|
+
const CHECK_EVERY_MS = 60_000;
|
|
22
|
+
const SHOW_TIMES = 2;
|
|
23
|
+
|
|
24
|
+
function stateFile(): string { return path.join(configDir(), "support.json"); }
|
|
25
|
+
|
|
26
|
+
function load(): SupportState {
|
|
27
|
+
try { return JSON.parse(fs.readFileSync(stateFile(), "utf8")) as SupportState; } catch { return {}; }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function save(s: SupportState): void {
|
|
31
|
+
try {
|
|
32
|
+
fs.mkdirSync(configDir(), { recursive: true, mode: 0o700 });
|
|
33
|
+
fs.writeFileSync(stateFile(), JSON.stringify(s), { mode: 0o600 });
|
|
34
|
+
} catch { /* best effort */ }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Called for every failed platform call. Never throws. */
|
|
38
|
+
export function recordFailedCall(method: string, urlPath: string, status: number | string, error: string, requestId?: string | null): void {
|
|
39
|
+
if (urlPath.startsWith("/api/support/")) return;
|
|
40
|
+
const s = load();
|
|
41
|
+
const entry: FailedCall = {
|
|
42
|
+
method, path: urlPath.split("?")[0], status,
|
|
43
|
+
error: String(error).replace(/\bliz_[A-Za-z0-9_-]{8,}/g, "liz_[redacted]").slice(0, 400),
|
|
44
|
+
...(requestId ? { requestId } : {}), at: new Date().toISOString(),
|
|
45
|
+
};
|
|
46
|
+
s.lastErrors = [...(s.lastErrors ?? []), entry].slice(-5);
|
|
47
|
+
save(s);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** What a new ticket carries besides the message. Only the last hour's failures. */
|
|
51
|
+
export function ticketContext(): Record<string, unknown> {
|
|
52
|
+
const hourAgo = Date.now() - 3600_000;
|
|
53
|
+
const lastErrors = (load().lastErrors ?? []).filter((e) => Date.parse(e.at) > hourAgo);
|
|
54
|
+
return {
|
|
55
|
+
cliVersion: CURRENT_VERSION,
|
|
56
|
+
os: `${os.platform()} ${os.arch()} node ${process.versions.node}`,
|
|
57
|
+
...(lastErrors.length ? { lastErrors } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function agentName(): string | undefined {
|
|
62
|
+
return detectAgent() ?? undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Server-side or network failures are worth a ticket; a 4xx about the request usually is not. */
|
|
66
|
+
export function isPlatformFailure(status: number | undefined, netCode?: string): boolean {
|
|
67
|
+
if (process.env.AGENT_SUPPORT === "0") return false;
|
|
68
|
+
if (status === undefined) return !!netCode;
|
|
69
|
+
return status >= 500 || status === 408;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const SUPPORT_HINT =
|
|
73
|
+
'If this keeps failing, tell the Lizard team: lizard support open "<what you ran and what happened>" (the error above is attached automatically)';
|
|
74
|
+
|
|
75
|
+
interface UnreadTicket { ticket: string; subject: string; status: string; messages: Array<{ from: string; body: string; at: string }> }
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Prints support replies the user has not seen yet, after a command. Throttled to one request
|
|
79
|
+
* a minute; each reply is printed at most twice. Never throws and never waits more than 2 s.
|
|
80
|
+
*/
|
|
81
|
+
export async function printSupportInbox(fetchUnread: () => Promise<{ tickets: UnreadTicket[] }>, opts: { force?: boolean } = {}): Promise<void> {
|
|
82
|
+
try {
|
|
83
|
+
const s = load();
|
|
84
|
+
if (!opts.force && s.checkedAt && Date.now() - s.checkedAt < CHECK_EVERY_MS) return;
|
|
85
|
+
s.checkedAt = Date.now();
|
|
86
|
+
save(s);
|
|
87
|
+
const res = await Promise.race([
|
|
88
|
+
fetchUnread(),
|
|
89
|
+
new Promise<null>((r) => setTimeout(() => r(null), 2000).unref()),
|
|
90
|
+
]);
|
|
91
|
+
if (!res?.tickets?.length) return;
|
|
92
|
+
const shown = { ...(load().shown ?? {}) };
|
|
93
|
+
const out: string[] = [];
|
|
94
|
+
for (const t of res.tickets) {
|
|
95
|
+
const fresh = t.messages.filter((m) => (shown[`${t.ticket}@${m.at}`] ?? 0) < SHOW_TIMES);
|
|
96
|
+
if (!fresh.length) continue;
|
|
97
|
+
out.push(chalk.bold.green(`๐ฌ Lizard support replied on ${t.ticket}`) + chalk.dim(` (${t.subject})`));
|
|
98
|
+
for (const m of fresh) {
|
|
99
|
+
shown[`${t.ticket}@${m.at}`] = (shown[`${t.ticket}@${m.at}`] ?? 0) + 1;
|
|
100
|
+
out.push(chalk.dim(` ${m.from}:`));
|
|
101
|
+
for (const line of m.body.split("\n")) out.push(` ${line}`);
|
|
102
|
+
}
|
|
103
|
+
out.push(chalk.dim(` โ answer: lizard support reply ${t.ticket} "<your answer>" ยท full thread: lizard support show ${t.ticket}`));
|
|
104
|
+
}
|
|
105
|
+
// Forget entries for replies that are no longer unread.
|
|
106
|
+
const live = new Set(res.tickets.flatMap((t) => t.messages.map((m) => `${t.ticket}@${m.at}`)));
|
|
107
|
+
const next = load();
|
|
108
|
+
next.shown = Object.fromEntries(Object.entries(shown).filter(([k]) => live.has(k)));
|
|
109
|
+
save(next);
|
|
110
|
+
if (out.length) process.stderr.write("\n" + out.join("\n") + "\n");
|
|
111
|
+
} catch { /* the inbox must never break a command */ }
|
|
112
|
+
}
|
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.108";
|
|
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
|
|
|
@@ -200,6 +200,11 @@ describe("private sandbox snapshots", () => {
|
|
|
200
200
|
// No scope unless asked: the server picks 'user', or for a scoped key only what it covers.
|
|
201
201
|
expect(api.post).toHaveBeenCalledWith('/api/sandboxes/sandbox-test/snapshot', { name: 'My app', scope: undefined });
|
|
202
202
|
});
|
|
203
|
+
it.each([[['--full'], { memory: true }], [['--fast'], { memory: false }]])("snapshot %j sends %j", async (flags, choice) => {
|
|
204
|
+
const program = new Command().exitOverride(); registerSandbox(program);
|
|
205
|
+
await program.parseAsync(['sandbox', 'snapshot', 'sandbox-test', '--name', 'My app', ...flags as string[], '--no-wait'], { from: 'user' });
|
|
206
|
+
expect(api.post).toHaveBeenCalledWith('/api/sandboxes/sandbox-test/snapshot', { name: 'My app', scope: undefined, ...choice });
|
|
207
|
+
});
|
|
203
208
|
it("no longer takes --warm", async () => {
|
|
204
209
|
const program = new Command().exitOverride(); registerSandbox(program);
|
|
205
210
|
await expect(program.parseAsync(['sandbox', 'snapshot', 'sandbox-test', '--name', 'app', '--warm', '3', '--no-wait'], { from: 'user' })).rejects.toThrow(/unknown option/);
|