Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 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
4965762
refactor(cli): extract upgrade sandbox helpers
cv May 4, 2026
9acd660
refactor(cli): extract sandbox destroy helpers
cv May 4, 2026
cc0eaa1
refactor(cli): extract sandbox logs helpers
cv May 4, 2026
847e115
refactor(cli): extract policy channel 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
4754f3e
merge: sync maintenance helper extraction
cv May 4, 2026
96f0758
merge: sync upgrade helper extraction
cv May 4, 2026
b6bd105
merge: sync destroy helper extraction
cv May 4, 2026
98fb75d
merge: sync logs helper extraction
cv May 4, 2026
5920d5b
test(cli): keep destroy helpers outside coverage ratchet
cv May 4, 2026
64d1646
merge: sync destroy helper coverage boundary
cv May 4, 2026
717c482
test(cli): keep logs helpers outside coverage ratchet
cv May 4, 2026
688074f
merge: sync logs helper coverage boundary
cv May 4, 2026
1314270
test(cli): keep policy channel helpers outside coverage ratchet
cv May 4, 2026
79d81c2
refactor(cli): group oclif core modules
cv May 4, 2026
5453a89
refactor(cli): split oclif commands by command tree
cv May 4, 2026
bbc297f
test(cli): reset credential command helper cache
cv May 4, 2026
25224c1
test(cli): avoid generic warning assertion in debug output
cv May 4, 2026
1ed9256
refactor(cli): group pure domain helpers
cv May 4, 2026
51799e4
refactor(cli): group openshell adapters
cv May 4, 2026
0b1e877
test(cli): enforce initial layer import boundaries
cv May 4, 2026
91d750b
refactor(cli): group sandbox actions
cv May 4, 2026
4321d63
refactor(cli): group global actions
cv May 4, 2026
5bc2242
test(cli): format layer boundary checker
cv May 4, 2026
073225e
ci(prek): tolerate unmatched biome format chunks
cv May 4, 2026
29a26ae
refactor(cli): group state modules
cv May 4, 2026
523e2d9
refactor(cli): group docker adapters
cv May 4, 2026
f25fcce
Merge branch 'test/layer-import-boundaries' into refactor/layer-sandb…
cv May 4, 2026
301b0a7
Merge branch 'refactor/layer-sandbox-actions' into refactor/layer-glo…
cv May 4, 2026
668235a
Merge branch 'refactor/layer-global-actions' into refactor/layer-stat…
cv May 4, 2026
392bebb
Merge branch 'refactor/layer-state-modules' into refactor/layer-docke…
cv May 4, 2026
e25e0a3
refactor(cli): discover oclif commands by pattern
cv May 6, 2026
bb7ebc3
refactor(cli): move coredns patcher behind internal command
cv May 6, 2026
489198d
refactor(cli): move dns proxy setup behind internal command
cv May 6, 2026
b5cdf50
refactor(uninstall): extract plan domain helpers
cv May 6, 2026
cc93aae
fix(uninstall): allow optional host env fields in plan tests
cv May 6, 2026
853719a
merge(main): reconcile uninstall plan helpers
cv May 6, 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
56 changes: 56 additions & 0 deletions src/lib/actions/uninstall-plan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";

import { buildHostUninstallPlan, classifyShimPath } from "./uninstall-plan";
import { flattenUninstallPlan } from "../domain/uninstall/plan";

describe("uninstall plan actions", () => {
it("classifies an on-disk dev shim", () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-uninstall-plan-shim-"));
const shim = path.join(tmp, "nemoclaw");
try {
fs.writeFileSync(
shim,
[
"#!/usr/bin/env bash",
"# NemoClaw dev-shim - managed by scripts/npm-link-or-shim.sh",
'export PATH="/tmp/node-bin:$PATH"',
'exec "/tmp/checkout/bin/nemoclaw.js" "$@"',
"",
].join("\n"),
);

expect(classifyShimPath(shim)).toMatchObject({ kind: "managed-dev-shim", remove: true });
} finally {
fs.rmSync(tmp, { force: true, recursive: true });
}
});

it("builds a host uninstall plan with shim classification and env-derived paths", () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-uninstall-plan-"));
const shimDir = path.join(tmp, ".local", "bin");
const shim = path.join(shimDir, "nemoclaw");
fs.mkdirSync(shimDir, { recursive: true });
fs.writeFileSync(shim, "#!/usr/bin/env bash\necho user\n");

try {
const plan = buildHostUninstallPlan({
deleteModels: false,
env: { HOME: tmp, TMPDIR: path.join(tmp, "tmp") },
keepOpenShell: false,
});
const actions = flattenUninstallPlan(plan);

expect(actions).toEqual(expect.arrayContaining([{ kind: "preserve-shim", reason: "regular file is not an installer-managed shim" }]));
expect(actions).toEqual(expect.arrayContaining([{ kind: "delete-path", path: path.join(tmp, ".nemoclaw") }]));
expect(actions).toEqual(expect.arrayContaining([{ kind: "delete-runtime-glob", pattern: path.join(tmp, "tmp", "nemoclaw-create-*.log") }]));
} finally {
fs.rmSync(tmp, { force: true, recursive: true });
}
});
});
54 changes: 54 additions & 0 deletions src/lib/actions/uninstall-plan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import fs from "node:fs";

import { defaultUninstallPaths } from "../domain/uninstall/paths";
import { buildUninstallPlan, type UninstallPlan, type UninstallPlanOptions } from "../domain/uninstall/plan";
import { classifyNemoclawShim, type ShimClassification } from "../domain/uninstall/shims";

export interface FileSystemDeps {
lstatSync?: typeof fs.lstatSync;
readFileSync?: typeof fs.readFileSync;
}

export interface HostUninstallPlanOptions extends Omit<UninstallPlanOptions, "shim"> {
env: Partial<Pick<NodeJS.ProcessEnv, "HOME" | "TMPDIR" | "XDG_BIN_HOME">>;
fs?: FileSystemDeps;
}

export function classifyShimPath(shimPath: string, deps: FileSystemDeps = {}): ShimClassification {
const lstatSync = deps.lstatSync ?? fs.lstatSync;
const readFileSync = deps.readFileSync ?? fs.readFileSync;
try {
const stat = lstatSync(shimPath);
const isFile = stat.isFile();
return classifyNemoclawShim({
contents: isFile ? String(readFileSync(shimPath, "utf-8")) : undefined,
exists: true,
isFile,
isSymlink: stat.isSymbolicLink(),
});
} catch (error) {
const code = error && typeof error === "object" ? (error as { code?: string }).code : undefined;
if (code === "ENOENT") {
return classifyNemoclawShim({ exists: false, isFile: false, isSymlink: false });
}
throw error;
}
}

export function buildHostUninstallPlan(options: HostUninstallPlanOptions): UninstallPlan {
const home = options.env.HOME || "/tmp";
const paths = defaultUninstallPaths({
home,
tmpDir: options.env.TMPDIR,
xdgBinHome: options.env.XDG_BIN_HOME,
});
return buildUninstallPlan(paths, {
deleteModels: options.deleteModels,
gatewayName: options.gatewayName,
keepOpenShell: options.keepOpenShell,
shim: classifyShimPath(paths.nemoclawShimPath, options.fs),
});
}
37 changes: 37 additions & 0 deletions src/lib/domain/uninstall/paths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import path from "node:path";
import { describe, expect, it } from "vitest";

import { defaultUninstallPaths, gatewayVolumeCandidates, uninstallStatePaths } from "./paths";

describe("uninstall paths", () => {
it("returns the gateway volume candidate used by uninstall.sh", () => {
expect(gatewayVolumeCandidates("nemoclaw")).toEqual(["openshell-cluster-nemoclaw"]);
});

it("builds host state, shim, OpenShell, and temp cleanup paths", () => {
const paths = defaultUninstallPaths({ home: "/home/test", tmpDir: "/tmp/nemo", xdgBinHome: "/xdg/bin" });

expect(paths.nemoclawStateDir).toBe(path.join("/home/test", ".nemoclaw"));
expect(paths.openshellConfigDir).toBe(path.join("/home/test", ".config", "openshell"));
expect(paths.nemoclawConfigDir).toBe(path.join("/home/test", ".config", "nemoclaw"));
expect(paths.nemoclawShimPath).toBe(path.join("/home/test", ".local", "bin", "nemoclaw"));
expect(paths.openshellInstallPaths).toEqual(["/usr/local/bin/openshell", path.join("/xdg/bin", "openshell")]);
expect(paths.helperServiceGlob).toBe(path.join("/tmp/nemo", "nemoclaw-services-*"));
expect(paths.runtimeTempGlobs).toEqual([
path.join("/tmp/nemo", "nemoclaw-create-*.log"),
path.join("/tmp/nemo", "nemoclaw-tg-ssh-*.conf"),
]);
});

it("returns state removal paths in shell cleanup order", () => {
const paths = defaultUninstallPaths({ home: "/home/test" });
expect(uninstallStatePaths(paths)).toEqual([
path.join("/home/test", ".nemoclaw"),
path.join("/home/test", ".config", "openshell"),
path.join("/home/test", ".config", "nemoclaw"),
]);
});
});
52 changes: 52 additions & 0 deletions src/lib/domain/uninstall/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import path from "node:path";

export const DEFAULT_GATEWAY_NAME = "nemoclaw";
export const NEMOCLAW_PROVIDERS = [
"nvidia-nim",
"vllm-local",
"ollama-local",
"nvidia-ncp",
"nim-local",
] as const;
export const NEMOCLAW_OLLAMA_MODELS = ["nemotron-3-super:120b", "nemotron-3-nano:30b"] as const;

export interface UninstallPathOptions {
home: string;
tmpDir?: string;
xdgBinHome?: string;
}

export interface UninstallPaths {
helperServiceGlob: string;
nemoclawConfigDir: string;
nemoclawShimPath: string;
nemoclawStateDir: string;
openshellConfigDir: string;
openshellInstallPaths: string[];
runtimeTempGlobs: string[];
}

export function gatewayVolumeCandidates(gatewayName = DEFAULT_GATEWAY_NAME): string[] {
return [`openshell-cluster-${gatewayName}`];
}

export function defaultUninstallPaths(options: UninstallPathOptions): UninstallPaths {
const xdgBinHome = options.xdgBinHome || path.join(options.home, ".local", "bin");
const tmpDir = options.tmpDir || "/tmp";
return {
helperServiceGlob: path.join(tmpDir, "nemoclaw-services-*"),
nemoclawConfigDir: path.join(options.home, ".config", "nemoclaw"),
nemoclawShimPath: path.join(options.home, ".local", "bin", "nemoclaw"),
nemoclawStateDir: path.join(options.home, ".nemoclaw"),
openshellConfigDir: path.join(options.home, ".config", "openshell"),
openshellInstallPaths: ["/usr/local/bin/openshell", path.join(xdgBinHome, "openshell")],
runtimeTempGlobs: [path.join(tmpDir, "nemoclaw-create-*.log"), path.join(tmpDir, "nemoclaw-tg-ssh-*.conf")],
};
}

export function uninstallStatePaths(paths: Pick<UninstallPaths, "nemoclawConfigDir" | "nemoclawStateDir" | "openshellConfigDir">): string[] {
return [paths.nemoclawStateDir, paths.openshellConfigDir, paths.nemoclawConfigDir];
}
58 changes: 58 additions & 0 deletions src/lib/domain/uninstall/plan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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

import { defaultUninstallPaths } from "./paths";
import { buildUninstallPlan, flattenUninstallPlan } from "./plan";

describe("uninstall plan", () => {
it("models the six uninstall.sh cleanup steps", () => {
const paths = defaultUninstallPaths({ home: "/home/test", tmpDir: "/tmp/nemo" });
const plan = buildUninstallPlan(paths, {
deleteModels: false,
keepOpenShell: false,
shim: { kind: "managed-wrapper", reason: "installer-managed wrapper contents", remove: true },
});

expect(plan.steps.map((step) => step.name)).toEqual([
"Stopping services",
"OpenShell resources",
"NemoClaw CLI",
"Docker resources",
"Ollama models",
"State and binaries",
]);
expect(flattenUninstallPlan(plan)).toEqual(
expect.arrayContaining([
{ kind: "delete-openshell-provider", name: "nvidia-nim" },
{ kind: "destroy-openshell-gateway", name: "nemoclaw" },
{ kind: "delete-shim", reason: "installer-managed wrapper contents" },
{ kind: "delete-docker-volume", name: "openshell-cluster-nemoclaw" },
{ kind: "preserve-ollama-models", names: ["nemotron-3-super:120b", "nemotron-3-nano:30b"] },
{ kind: "delete-openshell-binary", path: "/usr/local/bin/openshell" },
]),
);
});

it("respects delete-models, keep-openshell, custom gateway, and foreign shim decisions", () => {
const paths = defaultUninstallPaths({ home: "/home/test", xdgBinHome: "/bin" });
const actions = flattenUninstallPlan(
buildUninstallPlan(paths, {
deleteModels: true,
gatewayName: "custom",
keepOpenShell: true,
shim: { kind: "preserve-foreign-file", reason: "regular file is not an installer-managed shim", remove: false },
}),
);

expect(actions).toEqual(expect.arrayContaining([{ kind: "delete-docker-volume", name: "openshell-cluster-custom" }]));
expect(actions).toEqual(expect.arrayContaining([{ kind: "delete-ollama-model", name: "nemotron-3-super:120b" }]));
expect(actions).toEqual(
expect.arrayContaining([{ kind: "preserve-openshell-binary", paths: ["/usr/local/bin/openshell", "/bin/openshell"] }]),
);
expect(actions).toEqual(
expect.arrayContaining([{ kind: "preserve-shim", reason: "regular file is not an installer-managed shim" }]),
);
});
});
106 changes: 106 additions & 0 deletions src/lib/domain/uninstall/plan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import {
DEFAULT_GATEWAY_NAME,
gatewayVolumeCandidates,
NEMOCLAW_OLLAMA_MODELS,
NEMOCLAW_PROVIDERS,
type UninstallPaths,
uninstallStatePaths,
} from "./paths";
import type { ShimClassification } from "./shims";

export interface UninstallPlanOptions {
deleteModels: boolean;
gatewayName?: string;
keepOpenShell: boolean;
shim?: ShimClassification;
}

export type UninstallPlanAction =
| { kind: "delete-docker-volume"; name: string }
| { kind: "delete-ollama-model"; name: string }
| { kind: "delete-openshell-binary"; path: string }
| { kind: "delete-openshell-provider"; name: string }
| { kind: "delete-path"; path: string }
| { kind: "delete-runtime-glob"; pattern: string }
| { kind: "delete-shim"; reason: string }
| { kind: "destroy-openshell-gateway"; name: string }
| { kind: "preserve-ollama-models"; names: string[] }
| { kind: "preserve-openshell-binary"; paths: string[] }
| { kind: "preserve-shim"; reason: string }
| { kind: "stop-helper-services" }
| { kind: "stop-openshell-forward-processes" }
| { kind: "stop-orphaned-openshell-processes" }
| { kind: "uninstall-npm-package"; name: "nemoclaw" };

export interface UninstallPlanStep {
actions: UninstallPlanAction[];
name: string;
}

export interface UninstallPlan {
gatewayName: string;
steps: UninstallPlanStep[];
}

function cliActions(shim?: ShimClassification): UninstallPlanAction[] {
const actions: UninstallPlanAction[] = [{ kind: "uninstall-npm-package", name: "nemoclaw" }];
if (!shim) return actions;
actions.push(shim.remove ? { kind: "delete-shim", reason: shim.reason } : { kind: "preserve-shim", reason: shim.reason });
return actions;
}

export function buildUninstallPlan(paths: UninstallPaths, options: UninstallPlanOptions): UninstallPlan {
const gatewayName = options.gatewayName || DEFAULT_GATEWAY_NAME;
return {
gatewayName,
steps: [
{
name: "Stopping services",
actions: [
{ kind: "stop-helper-services" },
{ kind: "delete-runtime-glob", pattern: paths.helperServiceGlob },
{ kind: "stop-openshell-forward-processes" },
{ kind: "stop-orphaned-openshell-processes" },
],
},
{
name: "OpenShell resources",
actions: [
...NEMOCLAW_PROVIDERS.map((name) => ({ kind: "delete-openshell-provider" as const, name })),
{ kind: "destroy-openshell-gateway", name: gatewayName },
],
},
{
name: "NemoClaw CLI",
actions: cliActions(options.shim),
},
{
name: "Docker resources",
actions: gatewayVolumeCandidates(gatewayName).map((name) => ({ kind: "delete-docker-volume" as const, name })),
},
{
name: "Ollama models",
actions: options.deleteModels
? NEMOCLAW_OLLAMA_MODELS.map((name) => ({ kind: "delete-ollama-model" as const, name }))
: [{ kind: "preserve-ollama-models", names: [...NEMOCLAW_OLLAMA_MODELS] }],
},
{
name: "State and binaries",
actions: [
...paths.runtimeTempGlobs.map((pattern) => ({ kind: "delete-runtime-glob" as const, pattern })),
...(options.keepOpenShell
? [{ kind: "preserve-openshell-binary" as const, paths: paths.openshellInstallPaths }]
: paths.openshellInstallPaths.map((path) => ({ kind: "delete-openshell-binary" as const, path }))),
...uninstallStatePaths(paths).map((path) => ({ kind: "delete-path" as const, path })),
],
},
],
};
}

export function flattenUninstallPlan(plan: UninstallPlan): UninstallPlanAction[] {
return plan.steps.flatMap((step) => step.actions);
}
Loading
Loading