Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 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
aa0f853
refactor(uninstall): run uninstall through internal command
cv May 6, 2026
cf416a4
fix(cli): locate node for uninstall wrapper
cv May 6, 2026
359fefd
test(cli): exclude source-tested uninstall helpers from coverage ratchet
cv May 6, 2026
f729544
refactor(cli): wrap debug script with TypeScript command
cv May 6, 2026
ab60b4c
refactor(cli): move dev shim install behind internal command
cv May 6, 2026
f369bb8
merge(main): reconcile internal dev shim command
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
85 changes: 16 additions & 69 deletions scripts/npm-link-or-shim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,34 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Dev-install helper invoked by `npm install` via the package.json `prepare`
# script. Runs `npm link` so the local checkout exposes the `nemoclaw` CLI,
# and on failure falls back to a user-local wrapper at ~/.local/bin/nemoclaw.
# The wrapper preserves the Node directory that was on PATH at install time
# so the shim still works in shells where Node is provisioned via nvm and
# may not be on a fresh login PATH (matches scripts/install.sh's wrapper).
# Dev-install helper invoked by `npm install` via package.json `prepare`.
# The implementation lives in TypeScript behind an internal oclif command;
# this wrapper exists so existing prepare scripts and manual invocations keep
# working from source checkouts.

set -eu

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
BIN_PATH="$REPO_ROOT/bin/nemoclaw.js"
SHIM_DIR="${HOME}/.local/bin"
SHIM_PATH="$SHIM_DIR/nemoclaw"
SHIM_MARKER="# NemoClaw dev-shim - managed by scripts/npm-link-or-shim.sh"

if [ -n "${NEMOCLAW_INSTALLING:-}" ]; then
exit 0
fi
export NEMOCLAW_INSTALLING=1

if [ ! -x "$BIN_PATH" ]; then
printf '[nemoclaw] cannot expose CLI: %s is missing or not executable\n' "$BIN_PATH" >&2
exit 0
fi

LINK_LOG="$(mktemp -t nemoclaw-link.XXXXXX.log 2>/dev/null || mktemp)"
trap 'rm -f "$LINK_LOG"' EXIT

if (cd "$REPO_ROOT" && npm link >"$LINK_LOG" 2>&1); then
exit 0
fi
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
CLI_JS="${NEMOCLAW_CLI_JS:-$REPO_ROOT/dist/nemoclaw.js}"
NODE_BIN="${NEMOCLAW_NODE:-${NODE:-}}"

printf '[nemoclaw] npm link failed; falling back to user-local shim.\n' >&2
if [ -s "$LINK_LOG" ]; then
sed 's/^/[nemoclaw] /' "$LINK_LOG" >&2
if [ -z "$NODE_BIN" ]; then
NODE_BIN="$(command -v node 2>/dev/null || true)"
fi

NODE_PATH="$(command -v node 2>/dev/null || true)"
if [ -z "$NODE_PATH" ] || [ ! -x "$NODE_PATH" ]; then
printf '[nemoclaw] cannot create shim: node is not on PATH\n' >&2
if [ -z "$NODE_BIN" ] || [ ! -x "$NODE_BIN" ]; then
printf '[nemoclaw] cannot expose CLI: node is not available\n' >&2
exit 1
fi
NODE_DIR="$(cd -- "$(dirname -- "$NODE_PATH")" && pwd)"

if [ -e "$SHIM_PATH" ] || [ -L "$SHIM_PATH" ]; then
if ! grep -qFx "$SHIM_MARKER" "$SHIM_PATH" 2>/dev/null; then
printf '[nemoclaw] %s already exists and is not managed by NemoClaw; not overwriting.\n' "$SHIM_PATH" >&2
printf "[nemoclaw] Move it aside and re-run 'npm install' to install the dev shim.\n" >&2
exit 1
fi
fi

mkdir -p "$SHIM_DIR"

# Write to a sibling tempfile and rename so a mid-write failure (disk full,
# etc.) cannot leave an unrecognisable partial shim that the marker check
# would later refuse to overwrite.
SHIM_TMP="$(mktemp "$SHIM_DIR/nemoclaw.tmp.XXXXXX")"
trap 'rm -f "$LINK_LOG" "$SHIM_TMP"' EXIT

cat >"$SHIM_TMP" <<EOF
#!/usr/bin/env bash
$SHIM_MARKER
export PATH="$NODE_DIR:\$PATH"
exec "$BIN_PATH" "\$@"
EOF
chmod +x "$SHIM_TMP"
mv -f "$SHIM_TMP" "$SHIM_PATH"

if [ ! -x "$SHIM_PATH" ]; then
printf '[nemoclaw] shim creation failed: %s is not executable after write\n' "$SHIM_PATH" >&2
exit 1
if [ ! -f "$CLI_JS" ]; then
printf '[nemoclaw] skipping dev shim: %s is missing. Run npm run build:cli and retry.\n' "$CLI_JS" >&2
exit 0
fi

printf '[nemoclaw] Created user-local shim at %s -> %s\n' "$SHIM_PATH" "$BIN_PATH" >&2

case ":${PATH:-}:" in
*":$SHIM_DIR:"*) ;;
*)
printf '[nemoclaw] %s is not on PATH. Add it to your shell profile, e.g.:\n' "$SHIM_DIR" >&2
printf "[nemoclaw] echo 'export PATH=\"%s:\$PATH\"' >> ~/.bashrc\n" "$SHIM_DIR" >&2
;;
esac
exec "$NODE_BIN" "$CLI_JS" internal dev npm-link-or-shim --repo-root "$REPO_ROOT"
26 changes: 26 additions & 0 deletions src/commands/internal/dev/npm-link-or-shim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { Flags } from "@oclif/core";

import { runNpmLinkOrShim } from "../../../lib/actions/dev-shim";
import { NemoClawCommand } from "../../../lib/cli/nemoclaw-oclif-command";

export default class InternalDevNpmLinkOrShimCommand extends NemoClawCommand {
static hidden = true;
static strict = true;
static summary = "Internal: link the checkout CLI or create a dev shim";
static description = "Run npm link, falling back to a user-local NemoClaw development shim.";
static usage = ["internal dev npm-link-or-shim [--repo-root <path>]"];
static examples = ["<%= config.bin %> internal dev npm-link-or-shim"];
static flags = {
help: Flags.help({ char: "h" }),
"repo-root": Flags.string({ description: "Repository root to expose", hidden: true }),
};

public async run(): Promise<void> {
const { flags } = await this.parse(InternalDevNpmLinkOrShimCommand);
const result = runNpmLinkOrShim({ repoRoot: flags["repo-root"] ?? this.config.root });
if (result.status !== 0) process.exit(result.status);
}
}
123 changes: 123 additions & 0 deletions src/lib/actions/dev-shim.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// 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, vi } from "vitest";

import { DEV_SHIM_MARKER } from "../domain/dev-shim";
import { runNpmLinkOrShim } from "./dev-shim";

function setupRepo(): { binPath: string; homeDir: string; repoDir: string; tmpDir: string } {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dev-shim-action-"));
const repoDir = path.join(tmpDir, "repo");
const homeDir = path.join(tmpDir, "home");
const binPath = path.join(repoDir, "bin", "nemoclaw.js");
fs.mkdirSync(path.dirname(binPath), { recursive: true });
fs.mkdirSync(homeDir, { recursive: true });
fs.writeFileSync(binPath, "#!/usr/bin/env node\n", { mode: 0o755 });
return { binPath, homeDir, repoDir, tmpDir };
}

function failingNpm() {
return vi.fn(() => ({ status: 1, stdout: "", stderr: "npm error code EACCES\n" }));
}

describe("runNpmLinkOrShim", () => {
it("returns without side effects during prepare recursion", () => {
const { homeDir, repoDir } = setupRepo();
const run = failingNpm();

const result = runNpmLinkOrShim({ env: { HOME: homeDir, NEMOCLAW_INSTALLING: "1" }, repoRoot: repoDir }, { run });

expect(result.status).toBe(0);
expect(run).not.toHaveBeenCalled();
});

it("does not create a shim when npm link succeeds", () => {
const { homeDir, repoDir } = setupRepo();
const result = runNpmLinkOrShim(
{ env: { HOME: homeDir }, repoRoot: repoDir },
{ run: () => ({ status: 0, stdout: "", stderr: "" }) },
);

expect(result.status).toBe(0);
expect(fs.existsSync(path.join(homeDir, ".local", "bin", "nemoclaw"))).toBe(false);
});

it("creates a managed shim after npm link fails", () => {
const { binPath, homeDir, repoDir } = setupRepo();
const errors: string[] = [];

const result = runNpmLinkOrShim(
{ env: { HOME: homeDir, PATH: "/usr/bin" }, repoRoot: repoDir },
{
commandPath: () => process.execPath,
logError: (message) => errors.push(message),
run: failingNpm(),
},
);

const shimPath = path.join(homeDir, ".local", "bin", "nemoclaw");
expect(result.status).toBe(0);
expect(fs.existsSync(shimPath)).toBe(true);
expect((fs.statSync(shimPath).mode & 0o111) !== 0).toBe(true);
const shim = fs.readFileSync(shimPath, "utf-8");
expect(shim).toContain(DEV_SHIM_MARKER);
expect(shim).toContain(`exec "${binPath}" "$@"`);
expect(errors.join("\n")).toContain("npm link failed");
expect(errors.join("\n")).toContain("Created user-local shim");
});

it("refuses to overwrite a foreign shim", () => {
const { homeDir, repoDir } = setupRepo();
const shimPath = path.join(homeDir, ".local", "bin", "nemoclaw");
fs.mkdirSync(path.dirname(shimPath), { recursive: true });
fs.writeFileSync(shimPath, "user-script\n", { mode: 0o755 });
const errors: string[] = [];

const result = runNpmLinkOrShim(
{ env: { HOME: homeDir }, repoRoot: repoDir },
{ commandPath: () => process.execPath, logError: (message) => errors.push(message), run: failingNpm() },
);

expect(result.status).toBe(1);
expect(fs.readFileSync(shimPath, "utf-8")).toBe("user-script\n");
expect(errors.join("\n")).toContain("not managed by NemoClaw");
});

it("refreshes an existing managed shim", () => {
const { binPath, homeDir, repoDir } = setupRepo();
const shimPath = path.join(homeDir, ".local", "bin", "nemoclaw");
fs.mkdirSync(path.dirname(shimPath), { recursive: true });
fs.writeFileSync(shimPath, `#!/usr/bin/env bash\n${DEV_SHIM_MARKER}\nexec /old/stale "$@"\n`, {
mode: 0o755,
});

const result = runNpmLinkOrShim(
{ env: { HOME: homeDir }, repoRoot: repoDir },
{ commandPath: () => process.execPath, logError: vi.fn(), run: failingNpm() },
);

expect(result.status).toBe(0);
const refreshed = fs.readFileSync(shimPath, "utf-8");
expect(refreshed).toContain(`exec "${binPath}" "$@"`);
expect(refreshed).not.toContain("/old/stale");
});

it("fails clearly when the shim directory cannot be created", () => {
const { homeDir, repoDir } = setupRepo();
fs.writeFileSync(path.join(homeDir, ".local"), "not-a-directory\n");
const errors: string[] = [];

const result = runNpmLinkOrShim(
{ env: { HOME: homeDir }, repoRoot: repoDir },
{ commandPath: () => process.execPath, logError: (message) => errors.push(message), run: failingNpm() },
);

expect(result.status).toBe(1);
expect(errors.join("\n")).toContain("shim creation failed");
expect(fs.readFileSync(path.join(homeDir, ".local"), "utf-8")).toBe("not-a-directory\n");
});
});
Loading
Loading