Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions docs/reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ The `/nemoclaw` slash command is available inside the OpenClaw chat interface fo
|---|---|
| `/nemoclaw` | Show slash-command help and host CLI pointers |
| `/nemoclaw status` | Show sandbox and inference state |
| `/nemoclaw shields [status]` | Show read-only shields posture; default mutable or missing state reports `NOT CONFIGURED` |
| `/nemoclaw onboard` | Show onboarding status and reconfiguration guidance |
| `/nemoclaw eject` | Show rollback instructions for returning to the host installation |

Use host-side `$$nemoclaw <sandbox> shields up|down` commands to change shields posture.

</AgentOnly>
<AgentOnly variant="hermes">

Expand Down
39 changes: 39 additions & 0 deletions nemoclaw/src/blueprint/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,45 @@ describe("blueprint/state", () => {
expect(loaded.shieldsDownTimeout).toBeNull();
expect(loaded.shieldsDownReason).toBeNull();
});

it("does not treat legacy shieldsDown false as configured lockdown", () => {
store.set(
STATE_PATH,
JSON.stringify({
sandboxName: "sb",
shieldsDown: false,
updatedAt: "2026-03-01T12:00:00.000Z",
}),
);
const loaded = loadState();
expect(loaded.shieldsDown).toBe(false);
expect(loaded.shieldsConfigured).toBeUndefined();
});

it("marks shields configured when persisted state has lock evidence", () => {
store.set(
STATE_PATH,
JSON.stringify({
sandboxName: "sb",
shieldsDown: false,
fileHashes: { "/sandbox/.openclaw/openclaw.json": "abc123" },
updatedAt: "2026-03-01T12:00:00.000Z",
}),
);
expect(loadState().shieldsConfigured).toBe(true);
});

it("marks shields configured when persisted state is temporarily unlocked", () => {
store.set(
STATE_PATH,
JSON.stringify({
sandboxName: "sb",
shieldsDown: true,
updatedAt: "2026-03-01T12:00:00.000Z",
}),
);
expect(loadState().shieldsConfigured).toBe(true);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Cover the remaining shieldsConfigured inference branches.

These regressions exercise fileHashes and shieldsDown, but the new parser logic also treats chattrApplied and shieldsPolicySnapshotPath as configuration evidence. Please add cases for those branches too, otherwise a future refactor can silently regress posture reporting in this security-sensitive path.

As per coding guidelines, nemoclaw/src/blueprint/**/*.test.ts: Security-sensitive code paths in nemoclaw/src/blueprint/ require extra test coverage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nemoclaw/src/blueprint/state.test.ts` around lines 158 - 181, The
`loadState()` coverage in `state.test.ts` still misses two `shieldsConfigured`
inference branches in the parser logic. Add tests alongside the existing
`shieldsDown` and `fileHashes` cases to verify `chattrApplied` and
`shieldsPolicySnapshotPath` also cause `shieldsConfigured` to be true, using the
same persisted-state setup pattern so the behavior in `loadState` is fully
covered.

Source: Coding guidelines

});

describe("saveState", () => {
Expand Down
21 changes: 19 additions & 2 deletions nemoclaw/src/blueprint/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface NemoClawState {
lastRebuildBackupPath: string | null;

// Shields state (RFC: Sandbox Management Commands, Phase 1)
shieldsConfigured?: boolean;
shieldsDown: boolean;
shieldsDownAt: string | null;
shieldsDownTimeout: number | null;
Expand All @@ -47,6 +48,10 @@ function readBoolean(value: unknown): boolean | undefined {
return typeof value === "boolean" ? value : undefined;
}

function hasStringMap(value: unknown): boolean {
return isRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

function readNullableNumber(value: unknown): number | null | undefined {
return value === undefined || value === null || typeof value === "number" ? value : undefined;
}
Expand Down Expand Up @@ -77,8 +82,13 @@ function readStatePatch(value: unknown): Partial<NemoClawState> {
patch.lastRebuildAt = readNullableString(value.lastRebuildAt);
if (readNullableString(value.lastRebuildBackupPath) !== undefined)
patch.lastRebuildBackupPath = readNullableString(value.lastRebuildBackupPath);
if (readBoolean(value.shieldsDown) !== undefined)
patch.shieldsDown = readBoolean(value.shieldsDown);
if (readBoolean(value.shieldsConfigured) !== undefined)
patch.shieldsConfigured = readBoolean(value.shieldsConfigured);
const shieldsDown = readBoolean(value.shieldsDown);
if (shieldsDown !== undefined) {
patch.shieldsDown = shieldsDown;
if (shieldsDown) patch.shieldsConfigured = true;
}
if (readNullableString(value.shieldsDownAt) !== undefined)
patch.shieldsDownAt = readNullableString(value.shieldsDownAt);
if (readNullableNumber(value.shieldsDownTimeout) !== undefined)
Expand All @@ -89,6 +99,13 @@ function readStatePatch(value: unknown): Partial<NemoClawState> {
patch.shieldsDownPolicy = readNullableString(value.shieldsDownPolicy);
if (readNullableString(value.shieldsPolicySnapshotPath) !== undefined)
patch.shieldsPolicySnapshotPath = readNullableString(value.shieldsPolicySnapshotPath);
if (
hasStringMap(value.fileHashes) ||
readBoolean(value.chattrApplied) !== undefined ||
typeof value.shieldsPolicySnapshotPath === "string"
) {
patch.shieldsConfigured = true;
}

return patch;
}
Expand Down
26 changes: 20 additions & 6 deletions nemoclaw/src/commands/shields-status.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, it, expect, vi, beforeEach } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { NemoClawState } from "../blueprint/state.js";

vi.mock("../blueprint/state.js", () => ({
loadState: vi.fn(),
}));

import { slashShieldsStatus } from "./shields-status.js";
import { loadState } from "../blueprint/state.js";
import { slashShieldsStatus } from "./shields-status.js";

const mockedLoadState = vi.mocked(loadState);

Expand Down Expand Up @@ -40,7 +40,20 @@ describe("commands/shields-status", () => {
mockedLoadState.mockReturnValue(blankState());
});

it("reports shields UP when not down", () => {
it("reports shields NOT CONFIGURED for the default mutable state", () => {
const result = slashShieldsStatus();
expect(result.text).toContain("Shields: NOT CONFIGURED");
expect(result.text).toContain("default mutable state");
expect(result.text).toContain("shields up");
expect(result.text).not.toContain("normal security level");
});

it("reports shields UP when explicitly configured and not down", () => {
mockedLoadState.mockReturnValue({
...blankState(),
shieldsConfigured: true,
shieldsDown: false,
});
const result = slashShieldsStatus();
expect(result.text).toContain("Shields: UP");
expect(result.text).toContain("normal security level");
Expand All @@ -49,6 +62,7 @@ describe("commands/shields-status", () => {
it("shows last-lowered info when UP with a previous snapshot", () => {
mockedLoadState.mockReturnValue({
...blankState(),
shieldsConfigured: true,
shieldsDown: false,
shieldsPolicySnapshotPath: "/home/user/.nemoclaw/state/policy-snapshot-123.yaml",
});
Expand Down Expand Up @@ -134,17 +148,17 @@ describe("commands/shields-status", () => {

it("treats an empty string argument as a read-only status request", () => {
const result = slashShieldsStatus("");
expect(result.text).toContain("Shields: UP");
expect(result.text).toContain("Shields: NOT CONFIGURED");
});

it("treats whitespace-only argument as a read-only status request", () => {
const result = slashShieldsStatus(" ");
expect(result.text).toContain("Shields: UP");
expect(result.text).toContain("Shields: NOT CONFIGURED");
});

it("treats explicit `status` argument as a read-only status request", () => {
const result = slashShieldsStatus("status");
expect(result.text).toContain("Shields: UP");
expect(result.text).toContain("Shields: NOT CONFIGURED");
});

it("returns a host-only guidance message for `down`", () => {
Expand Down
14 changes: 12 additions & 2 deletions nemoclaw/src/commands/shields-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Shields can only be lowered or raised from the host CLI (security invariant).
*/

import type { PluginCommandResult } from "../index.js";
import { loadState } from "../blueprint/state.js";
import type { PluginCommandResult } from "../index.js";

const MAX_ARG_DISPLAY_LEN = 32;

Expand Down Expand Up @@ -57,7 +57,7 @@ export function slashShieldsStatus(arg?: string): PluginCommandResult {

const state = loadState();

if (!state.shieldsDown) {
if (!state.shieldsDown && state.shieldsConfigured) {
const lines = ["**Shields: UP**", "", "Sandbox policy is at normal security level."];

if (state.shieldsPolicySnapshotPath) {
Expand All @@ -67,6 +67,16 @@ export function slashShieldsStatus(arg?: string): PluginCommandResult {
return { text: lines.join("\n") };
}

if (!state.shieldsDown) {
return {
text: [
"**Shields: NOT CONFIGURED (default mutable state)**",
"",
"Sandbox policy is mutable. Run `nemoclaw <name> shields up` from the host to opt into lockdown.",
].join("\n"),
};
}

const downSince = state.shieldsDownAt ? new Date(state.shieldsDownAt) : null;
const elapsed = downSince ? Math.floor((Date.now() - downSince.getTime()) / 1000) : 0;
const remaining =
Expand Down
Loading