Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4b7a4a2
refactor(cli): extract sandbox live state helpers
cv May 2, 2026
2ce87dd
refactor(cli): extract sandbox skill install action
cv May 2, 2026
4cd3cf3
refactor(cli): extract sandbox connect action
cv May 3, 2026
e9dd46e
refactor(cli): extract sandbox status action
cv May 3, 2026
aab6c86
refactor(cli): extract sandbox doctor action
cv May 3, 2026
8908521
refactor(cli): extract sandbox destroy action
cv May 3, 2026
56e4f05
refactor(cli): extract sandbox rebuild action
cv May 3, 2026
8bf1958
refactor(cli): extract upgrade sandboxes action
cv May 3, 2026
38eb84d
refactor(cli): remove runtime bridge
cv May 3, 2026
b2ad5da
refactor(cli): remove legacy dispatch fallbacks
cv May 3, 2026
edd2650
refactor(cli): expose explicit main entrypoint
cv May 3, 2026
a15da95
refactor(cli): add oclif examples for utility commands
cv May 3, 2026
4f57ebb
refactor(cli): validate logs flags with oclif
cv May 3, 2026
8b2d077
refactor(cli): improve sandbox diagnostic command metadata
cv May 3, 2026
a09cc51
refactor(cli): tighten policy and channel parser validation
cv May 3, 2026
75857dc
refactor(cli): improve snapshot command metadata
cv May 3, 2026
11c0676
refactor(cli): require skill install path in oclif
cv May 3, 2026
05f9eca
refactor(cli): add lifecycle confirmation flag aliases
cv May 3, 2026
4ebeae4
refactor(cli): split share into oclif subcommands
cv May 3, 2026
7d72437
Revert "refactor(cli): split share into oclif subcommands"
cv May 3, 2026
0ee5ca5
refactor(cli): split share into oclif subcommands
cv May 3, 2026
928219c
refactor(cli): model debug flags with oclif
cv May 3, 2026
36cce5e
refactor(cli): model onboard flags with oclif
cv May 3, 2026
702afb1
docs: sync oclif UX command reference
cv May 3, 2026
3224350
refactor(cli): extract public argv normalizer
cv May 3, 2026
cd4cdb8
refactor(cli): rename oclif dispatch module
cv May 3, 2026
9499ca6
refactor(cli): normalize policy command ids
cv May 3, 2026
42028ef
test(cli): require oclif command metadata
cv May 3, 2026
a05c6b3
refactor(cli): return typed debug parse results
cv May 3, 2026
1875fe9
refactor(cli): add public command display ids
cv May 3, 2026
36f1dbe
refactor(cli): use oclif summaries in root help
cv May 3, 2026
78bfd5a
refactor(cli): table-drive sandbox dispatch
cv May 3, 2026
96ce61f
refactor(cli): normalize gateway token command id
cv May 3, 2026
266ebc9
refactor(cli): render public oclif help
cv May 3, 2026
dc98994
refactor(cli): add shared oclif command base
cv May 3, 2026
d0d2a70
refactor(cli): use oclif flag relationships
cv May 3, 2026
8396c06
refactor(cli): pass lifecycle typed options
cv May 3, 2026
1532b19
refactor(cli): parse durations with oclif flags
cv May 3, 2026
7c0445a
refactor(cli): project public help through oclif
cv May 3, 2026
3978c32
test(cli): cover oclif metadata routing helpers
cv May 3, 2026
591eabb
test(cli): cover global oclif command adapters
cv May 3, 2026
8a6ecbc
test(cli): cover sandbox oclif command adapters
cv May 3, 2026
e5aa22f
refactor(cli): split share oclif commands
cv May 3, 2026
e179336
test(cli): narrow sandbox logs coverage ignores
cv May 3, 2026
a629813
test(cli): cover remaining global oclif adapters
cv May 3, 2026
c5954e7
test(cli): cover credentials oclif adapter
cv May 3, 2026
3380de9
test(cli): cover runtime utility helpers
cv May 3, 2026
f60a190
test(cli): improve global adapter coverage
cv May 3, 2026
78a16d1
merge: sync simple global adapter coverage
cv May 3, 2026
a58dc90
merge: sync credentials adapter coverage
cv May 3, 2026
034454f
merge: include credentials adapter coverage
cv May 3, 2026
28bc497
merge: sync combined global adapter coverage
cv May 3, 2026
e9ed6ba
test(cli): cover global action facade
cv May 3, 2026
00b288c
merge: sync global action facade coverage
cv May 3, 2026
7bd5f32
test(cli): stabilize coverage dist sourcemaps
cv May 4, 2026
d4b55d9
test(cli): rebaseline clean-dist function coverage
cv May 4, 2026
b872474
refactor(cli): extract maintenance image helpers
cv May 4, 2026
b6c0f5a
test(cli): allow clean coverage variance
cv May 4, 2026
5c98bd1
merge: sync coverage stabilization
cv May 4, 2026
151abad
merge(main): reconcile maintenance image helpers
cv May 5, 2026
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
19 changes: 3 additions & 16 deletions src/lib/maintenance-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
normalizeGarbageCollectImagesOptions,
} from "./lifecycle-options";
import { dockerListImagesFormat, dockerRmi } from "./docker";
import { findOrphanedSandboxImages, parseSandboxImageRows } from "./maintenance-image-helpers";
import { captureOpenshell } from "./openshell-runtime";
import * as registry from "./registry";
import { parseLiveSandboxNames } from "./runtime-recovery";
Expand Down Expand Up @@ -83,29 +84,15 @@ export async function garbageCollectImages(
process.exit(1);
}

const allImages = imagesOutput
.split("\n")
.map((line: string) => line.trim())
.filter(Boolean)
.map((line: string) => {
const [tag, size] = line.split("\t");
return { tag, size: size || "unknown" };
});
const allImages = parseSandboxImageRows(imagesOutput);

if (allImages.length === 0) {
console.log(" No sandbox images found on the host.");
return;
}

const registeredTags = new Set();
const { sandboxes } = registry.listSandboxes();
for (const sb of sandboxes) {
if (sb.imageTag) registeredTags.add(sb.imageTag);
}

const orphans = allImages.filter(
(img: { tag: string; size: string }) => !registeredTags.has(img.tag),
);
const orphans = findOrphanedSandboxImages(allImages, sandboxes);

if (orphans.length === 0) {
console.log(` All ${allImages.length} sandbox image(s) are in use. Nothing to clean up.`);
Expand Down
43 changes: 43 additions & 0 deletions src/lib/maintenance-image-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it } from "vitest";

import {
findOrphanedSandboxImages,
getRegisteredImageTags,
parseSandboxImageRows,
} from "./maintenance-image-helpers";

describe("maintenance image helpers", () => {
it("parses Docker image rows and fills missing sizes", () => {
expect(
parseSandboxImageRows("openshell/sandbox-from:one\t1GB\nopenshell/sandbox-from:two\n\n"),
).toEqual([
{ tag: "openshell/sandbox-from:one", size: "1GB" },
{ tag: "openshell/sandbox-from:two", size: "unknown" },
]);
});

it("collects registered sandbox image tags", () => {
expect(
getRegisteredImageTags([
{ imageTag: "openshell/sandbox-from:one" },
{ imageTag: null },
{},
]),
).toEqual(new Set(["openshell/sandbox-from:one"]));
});

it("finds orphaned sandbox images by registry image tags", () => {
expect(
findOrphanedSandboxImages(
[
{ tag: "openshell/sandbox-from:one", size: "1GB" },
{ tag: "openshell/sandbox-from:two", size: "2GB" },
],
[{ imageTag: "openshell/sandbox-from:one" }, { imageTag: null }],
),
).toEqual([{ tag: "openshell/sandbox-from:two", size: "2GB" }]);
});
});
39 changes: 39 additions & 0 deletions src/lib/maintenance-image-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export type SandboxImageRow = { tag: string; size: string };

export function parseSandboxImageRows(imagesOutput: string): SandboxImageRow[] {
const rows: SandboxImageRow[] = [];
for (const rawLine of imagesOutput.split("\n")) {
const line = rawLine.trim();
if (!line) continue;
const [tag, size] = line.split("\t");
rows.push({ tag, size: size || "unknown" });
}
return rows;
}

export function getRegisteredImageTags(
sandboxes: Array<{ imageTag?: string | null }>,
): Set<string> {
const registeredTags = new Set<string>();
for (const sandbox of sandboxes) {
if (sandbox.imageTag) registeredTags.add(sandbox.imageTag);
}
return registeredTags;
}

export function findOrphanedSandboxImages(
images: SandboxImageRow[],
sandboxes: Array<{ imageTag?: string | null }>,
): SandboxImageRow[] {
const registeredTags = getRegisteredImageTags(sandboxes);
const orphans: SandboxImageRow[] = [];
for (const image of images) {
if (!registeredTags.has(image.tag)) {
orphans.push(image);
}
}
return orphans;
}
Loading