Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ rli snapshot list # List all snapshots
rli snapshot create <devbox-id> # Create a snapshot of a devbox
rli snapshot delete <id> # Delete a snapshot
rli snapshot get <id> # Get snapshot details
rli snapshot prune <devbox-id> # Delete old snapshots for a devbox, ke...
rli snapshot status <snapshot-id> # Get snapshot operation status
```

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"access": "public"
},
"dependencies": {
"@js-temporal/polyfill": "^0.5.1",
"@modelcontextprotocol/sdk": "^1.26.0",
"@runloop/api-client": "1.6.0",
"@types/express": "^5.0.6",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 4 additions & 26 deletions src/commands/blueprint/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as readline from "readline";
import { getClient } from "../../utils/client.js";
import { output, outputError } from "../../utils/output.js";
import { formatRelativeTime } from "../../utils/time.js";
import type { Blueprint } from "../../store/blueprintStore.js";

interface PruneBlueprintsOptions {
Expand Down Expand Up @@ -87,29 +88,6 @@ function categorizeBlueprints(blueprints: Blueprint[], keepCount: number) {
};
}

/**
* Format a timestamp for display
*/
function formatTimestamp(createTimeMs?: number): string {
if (!createTimeMs) {
return "unknown time";
}

const now = Date.now();
const diffMs = now - createTimeMs;
const diffMinutes = Math.floor(diffMs / 60000);
const diffHours = Math.floor(diffMs / 3600000);
const diffDays = Math.floor(diffMs / 86400000);

if (diffMinutes < 60) {
return `${diffMinutes} minute${diffMinutes !== 1 ? "s" : ""} ago`;
} else if (diffHours < 24) {
return `${diffHours} hour${diffHours !== 1 ? "s" : ""} ago`;
} else {
return `${diffDays} day${diffDays !== 1 ? "s" : ""} ago`;
}
}

/**
* Display a summary of what will be kept and deleted
*/
Expand Down Expand Up @@ -145,7 +123,7 @@ function displaySummary(
} else {
for (const blueprint of result.toKeep) {
console.log(
` ✓ ${blueprint.id} - Created ${formatTimestamp(blueprint.create_time_ms)}`,
` ✓ ${blueprint.id} - Created ${formatRelativeTime(blueprint.create_time_ms)}`,
);
}
}
Expand All @@ -163,7 +141,7 @@ function displaySummary(
const statusLabel =
blueprint.status === "build_complete" ? "successful" : "failed";
console.log(
` ${icon} ${blueprint.id} - Created ${formatTimestamp(blueprint.create_time_ms)} (${statusLabel})`,
` ${icon} ${blueprint.id} - Created ${formatRelativeTime(blueprint.create_time_ms)} (${statusLabel})`,
);
}
}
Expand All @@ -183,7 +161,7 @@ function displayDeletedBlueprints(deleted: Blueprint[]) {
const statusLabel =
blueprint.status === "build_complete" ? "successful" : "failed";
console.log(
` ${icon} ${blueprint.id} - Created ${formatTimestamp(blueprint.create_time_ms)} (${statusLabel})`,
` ${icon} ${blueprint.id} - Created ${formatRelativeTime(blueprint.create_time_ms)} (${statusLabel})`,
);
}
}
Expand Down
18 changes: 14 additions & 4 deletions src/commands/snapshot/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { Box, Text, useInput, useApp } from "ink";
import figures from "figures";
import type { DiskSnapshotsCursorIDPage } from "@runloop/api-client/pagination";
import type { DevboxSnapshotView } from "@runloop/api-client/resources/devboxes/devboxes";
import { getClient } from "../../utils/client.js";
import { Header } from "../../components/Header.js";
import { SpinnerComponent } from "../../components/Spinner.js";
Expand Down Expand Up @@ -696,10 +697,19 @@ export async function listSnapshots(options: ListOptions) {
// Fetch snapshots
const page = (await client.devboxes.listDiskSnapshots(
queryParams,
)) as DiskSnapshotsCursorIDPage<{ id: string }>;

// Extract snapshots array
const snapshots = page.snapshots || [];
)) as DiskSnapshotsCursorIDPage<DevboxSnapshotView>;

// Extract snapshots array and strip to plain objects to avoid
// camelCase aliases added by the API client library
const snapshots = (page.snapshots || []).map((s) => ({
id: s.id,
name: s.name ?? undefined,
create_time_ms: s.create_time_ms,
metadata: s.metadata,
source_devbox_id: s.source_devbox_id,
source_blueprint_id: s.source_blueprint_id ?? undefined,
commit_message: s.commit_message ?? undefined,
}));

output(snapshots, { format: options.output, defaultFormat: "json" });
} catch (error) {
Expand Down
Loading
Loading