@sandblocks/cli 0.6.9 → 0.6.11

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/cli.js CHANGED
@@ -12578,6 +12578,23 @@ class SandblocksClient {
12578
12578
  listSandboxes(projectId) {
12579
12579
  return this.request(`/v1/projects/${encodeURIComponent(projectId)}/sandboxes`);
12580
12580
  }
12581
+ cleanupSandboxes(input) {
12582
+ return this.request(`/v1/projects/${encodeURIComponent(input.projectId)}/sandboxes/cleanup`, {
12583
+ method: "POST",
12584
+ body: JSON.stringify({
12585
+ ids: input.ids,
12586
+ stack: input.stack,
12587
+ deploymentType: input.deploymentType,
12588
+ statuses: input.statuses,
12589
+ olderThanHours: input.olderThanHours,
12590
+ dryRun: input.dryRun,
12591
+ purge: input.purge
12592
+ })
12593
+ });
12594
+ }
12595
+ removeSandbox(projectId, sandboxId, purge = true) {
12596
+ return this.cleanupSandboxes({ projectId, ids: [sandboxId], purge });
12597
+ }
12581
12598
  listAgentSessions(projectId, sandboxId) {
12582
12599
  return this.request(`/v1/projects/${encodeURIComponent(projectId)}/sandboxes/${encodeURIComponent(sandboxId)}/agent-sessions`);
12583
12600
  }
@@ -15679,6 +15696,9 @@ var HELP = `Sandblocks CLI
15679
15696
  sandblocks sandbox redeploy [directory] [--environment <id>] [--build-pool <pool>]
15680
15697
  sandblocks sandbox status [directory] [--environment <id>] [--json]
15681
15698
  sandblocks sandbox promote --project <id> --sandbox <id> [--json]
15699
+ sandblocks sandbox cleanup --project <id> [--sandbox <id>] [--stack <id>]
15700
+ [--deployment-type <id>] [--status <status>] [--older-than-hours <n>]
15701
+ [--dry-run] [--keep-records] [--json]
15682
15702
  sandblocks sandbox agent <run|list|get|cancel|redeploy> --project <id> --sandbox <id>
15683
15703
  [--repository <id>] [--provider <codex|claude-code|pi>] [--model <id>]
15684
15704
  [--prompt <text> | --prompt-file <path>] [--session <id>] [--wait] [--json]
@@ -16147,6 +16167,9 @@ function printResources(kind, action, body) {
16147
16167
  function objectRecord(value) {
16148
16168
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
16149
16169
  }
16170
+ function multiValue(value) {
16171
+ return Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
16172
+ }
16150
16173
  async function sandbox(args) {
16151
16174
  const [subcommand, ...rest] = args;
16152
16175
  if (isStatefulSandboxCommand(subcommand) && !(subcommand === "deploy" && rest.includes("--workspace"))) {
@@ -16161,6 +16184,8 @@ async function sandbox(args) {
16161
16184
  return sandboxDeploy(rest);
16162
16185
  if (subcommand === "promote")
16163
16186
  return sandboxPromote(rest);
16187
+ if (subcommand === "cleanup" || subcommand === "remove")
16188
+ return sandboxCleanup(rest);
16164
16189
  if (subcommand === "agent")
16165
16190
  return sandboxAgent(rest);
16166
16191
  if (subcommand !== "import")
@@ -16274,6 +16299,45 @@ async function waitForAgentSession(apiUrl, apiKey, projectId, sandboxId, session
16274
16299
  await Bun.sleep(1000);
16275
16300
  }
16276
16301
  }
16302
+ async function sandboxCleanup(args) {
16303
+ const options = parse2(args);
16304
+ const projectId = option2(options, "project");
16305
+ const apiUrl = (option2(options, "api-url") ?? process.env.SANDBLOCKS_API_URL ?? "").replace(/\/$/, "");
16306
+ const apiKey = option2(options, "api-key") ?? process.env.SANDBLOCKS_API_KEY;
16307
+ if (!projectId)
16308
+ throw new Error("sandbox cleanup requires --project");
16309
+ if (!apiUrl || !apiKey)
16310
+ throw new Error("sandbox cleanup requires API URL and API key");
16311
+ const ids = multiValue(options.sandbox);
16312
+ const statuses = multiValue(options.status);
16313
+ const stack = option2(options, "stack");
16314
+ const deploymentType = option2(options, "deployment-type");
16315
+ const olderThanHours = option2(options, "older-than-hours");
16316
+ if (!ids.length && !statuses.length && !stack && !deploymentType && !olderThanHours)
16317
+ throw new Error("sandbox cleanup requires --sandbox, --stack, --deployment-type, --status, or --older-than-hours");
16318
+ const result = await sandblocksRequest(apiUrl, apiKey, `/v1/projects/${encodeURIComponent(projectId)}/sandboxes/cleanup`, {
16319
+ method: "POST",
16320
+ body: JSON.stringify({
16321
+ ...ids.length ? { ids } : {},
16322
+ ...statuses.length ? { statuses } : {},
16323
+ ...stack ? { stack } : {},
16324
+ ...deploymentType ? { deploymentType } : {},
16325
+ ...olderThanHours ? { olderThanHours: Number(olderThanHours) } : {},
16326
+ dryRun: options["dry-run"] === true,
16327
+ purge: options["keep-records"] !== true
16328
+ })
16329
+ });
16330
+ if (options.json)
16331
+ console.log(JSON.stringify(result, null, 2));
16332
+ else {
16333
+ const selected = result.removed ?? result.matched ?? [];
16334
+ console.log(`${result.dryRun ? "matched" : "removed"} ${selected.length} deployment(s)`);
16335
+ for (const id2 of selected)
16336
+ console.log(` ${id2}`);
16337
+ for (const skipped of result.skipped ?? [])
16338
+ console.log(`skipped ${skipped.id}: ${skipped.reason}`);
16339
+ }
16340
+ }
16277
16341
  async function sandboxPromote(args) {
16278
16342
  const options = parse2(args);
16279
16343
  const projectId = option2(options, "project");
@@ -16595,7 +16659,9 @@ function parse2(args) {
16595
16659
  "rootless",
16596
16660
  "allow-unpinned-images",
16597
16661
  "read-only-root",
16598
- "resume"
16662
+ "resume",
16663
+ "dry-run",
16664
+ "keep-records"
16599
16665
  ].includes(rawKey)) {
16600
16666
  output[rawKey] = inline === undefined ? true : inline !== "false";
16601
16667
  continue;
@@ -16661,3 +16727,5 @@ export {
16661
16727
  run3 as run,
16662
16728
  parse2 as parse
16663
16729
  };
16730
+
16731
+ //# debugId=D7067CF7EF69C62A64756E2164756E21