diff --git a/docs/reference/commands.mdx b/docs/reference/commands.mdx index bcea4279e70..d1ab647a0af 100644 --- a/docs/reference/commands.mdx +++ b/docs/reference/commands.mdx @@ -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]` | Explain that shields status is unavailable inside the sandbox and point to `$$nemoclaw shields status` on the host | | `/nemoclaw onboard` | Show onboarding status and reconfiguration guidance | | `/nemoclaw eject` | Show rollback instructions for returning to the host installation | +Use host-side `$$nemoclaw shields status|up|down` commands to inspect or change shields posture. + diff --git a/nemoclaw/src/blueprint/state.test.ts b/nemoclaw/src/blueprint/state.test.ts index c0f549453f5..ed29b439ceb 100644 --- a/nemoclaw/src/blueprint/state.test.ts +++ b/nemoclaw/src/blueprint/state.test.ts @@ -55,13 +55,6 @@ describe("blueprint/state", () => { expect(state.hostBackupPath).toBeNull(); expect(state.createdAt).toBeNull(); expect(state.updatedAt).toBeDefined(); - // Shields defaults - expect(state.shieldsDown).toBe(false); - expect(state.shieldsDownAt).toBeNull(); - expect(state.shieldsDownTimeout).toBeNull(); - expect(state.shieldsDownReason).toBeNull(); - expect(state.shieldsDownPolicy).toBeNull(); - expect(state.shieldsPolicySnapshotPath).toBeNull(); }); it("returns parsed state when file exists", () => { @@ -76,48 +69,15 @@ describe("blueprint/state", () => { updatedAt: "2026-03-01T12:00:00.000Z", lastRebuildAt: null, lastRebuildBackupPath: null, - shieldsDown: false, - shieldsDownAt: null, - shieldsDownTimeout: null, - shieldsDownReason: null, - shieldsDownPolicy: null, - shieldsPolicySnapshotPath: null, }; store.set(STATE_PATH, JSON.stringify(saved)); expect(loadState()).toEqual(saved); }); - it("fills shields defaults for pre-shields state files", () => { - // Simulate a state file written before shields fields were added - const legacyState = { - lastRunId: "run-1", - lastAction: "deploy", - blueprintVersion: "1.0.0", - sandboxName: "sb", - migrationSnapshot: null, - hostBackupPath: null, - createdAt: "2026-03-01T00:00:00.000Z", - updatedAt: "2026-03-01T12:00:00.000Z", - }; - store.set(STATE_PATH, JSON.stringify(legacyState)); - const loaded = loadState(); - // Original fields preserved - expect(loaded.lastRunId).toBe("run-1"); - expect(loaded.lastAction).toBe("deploy"); - // Shields fields filled with defaults - expect(loaded.shieldsDown).toBe(false); - expect(loaded.shieldsDownAt).toBeNull(); - expect(loaded.shieldsDownTimeout).toBeNull(); - expect(loaded.shieldsDownReason).toBeNull(); - expect(loaded.shieldsDownPolicy).toBeNull(); - expect(loaded.shieldsPolicySnapshotPath).toBeNull(); - }); - it("falls back to blank defaults when the persisted JSON root is not an object", () => { store.set(STATE_PATH, JSON.stringify(["not", "an", "object"])); const loaded = loadState(); expect(loaded.lastRunId).toBeNull(); - expect(loaded.shieldsDown).toBe(false); }); it("ignores malformed persisted field types while preserving valid partial state", () => { @@ -127,18 +87,12 @@ describe("blueprint/state", () => { lastRunId: "run-1", sandboxName: "sb", updatedAt: {}, - shieldsDown: "false", - shieldsDownTimeout: "300", - shieldsDownReason: ["bad"], }), ); const loaded = loadState(); expect(loaded.lastRunId).toBe("run-1"); expect(loaded.sandboxName).toBe("sb"); expect(typeof loaded.updatedAt).toBe("string"); - expect(loaded.shieldsDown).toBe(false); - expect(loaded.shieldsDownTimeout).toBeNull(); - expect(loaded.shieldsDownReason).toBeNull(); }); }); diff --git a/nemoclaw/src/blueprint/state.ts b/nemoclaw/src/blueprint/state.ts index 01e2618a5b2..096f2677fc2 100644 --- a/nemoclaw/src/blueprint/state.ts +++ b/nemoclaw/src/blueprint/state.ts @@ -19,14 +19,6 @@ export interface NemoClawState { updatedAt: string; lastRebuildAt: string | null; lastRebuildBackupPath: string | null; - - // Shields state (RFC: Sandbox Management Commands, Phase 1) - shieldsDown: boolean; - shieldsDownAt: string | null; - shieldsDownTimeout: number | null; - shieldsDownReason: string | null; - shieldsDownPolicy: string | null; - shieldsPolicySnapshotPath: string | null; } type UnknownRecord = { [key: string]: unknown }; @@ -43,14 +35,6 @@ function readString(value: unknown): string | undefined { return typeof value === "string" ? value : undefined; } -function readBoolean(value: unknown): boolean | undefined { - return typeof value === "boolean" ? value : undefined; -} - -function readNullableNumber(value: unknown): number | null | undefined { - return value === undefined || value === null || typeof value === "number" ? value : undefined; -} - function readStatePatch(value: unknown): Partial { if (!isRecord(value)) { return {}; @@ -77,18 +61,6 @@ function readStatePatch(value: unknown): Partial { 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 (readNullableString(value.shieldsDownAt) !== undefined) - patch.shieldsDownAt = readNullableString(value.shieldsDownAt); - if (readNullableNumber(value.shieldsDownTimeout) !== undefined) - patch.shieldsDownTimeout = readNullableNumber(value.shieldsDownTimeout); - if (readNullableString(value.shieldsDownReason) !== undefined) - patch.shieldsDownReason = readNullableString(value.shieldsDownReason); - if (readNullableString(value.shieldsDownPolicy) !== undefined) - patch.shieldsDownPolicy = readNullableString(value.shieldsDownPolicy); - if (readNullableString(value.shieldsPolicySnapshotPath) !== undefined) - patch.shieldsPolicySnapshotPath = readNullableString(value.shieldsPolicySnapshotPath); return patch; } @@ -119,12 +91,6 @@ function blankState(): NemoClawState { updatedAt: new Date().toISOString(), lastRebuildAt: null, lastRebuildBackupPath: null, - shieldsDown: false, - shieldsDownAt: null, - shieldsDownTimeout: null, - shieldsDownReason: null, - shieldsDownPolicy: null, - shieldsPolicySnapshotPath: null, }; } @@ -136,8 +102,8 @@ export function loadState(): NemoClawState { } try { - // Merge over blankState so that state files created before shields fields - // were added still return valid NemoClawState with sensible defaults. + // Merge validated persisted values over current defaults so older state + // files remain compatible as the plugin state schema evolves. const persisted: unknown = JSON.parse(readFileSync(path, "utf-8")); return { ...blankState(), ...readStatePatch(persisted) }; } catch { diff --git a/nemoclaw/src/commands/shields-status.test.ts b/nemoclaw/src/commands/shields-status.test.ts index b58924b4c4d..a638efd3805 100644 --- a/nemoclaw/src/commands/shields-status.test.ts +++ b/nemoclaw/src/commands/shields-status.test.ts @@ -1,190 +1,54 @@ // 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 type { NemoClawState } from "../blueprint/state.js"; - -vi.mock("../blueprint/state.js", () => ({ - loadState: vi.fn(), -})); - +import { describe, expect, it } from "vitest"; import { slashShieldsStatus } from "./shields-status.js"; -import { loadState } from "../blueprint/state.js"; - -const mockedLoadState = vi.mocked(loadState); - -function blankState(): NemoClawState { - return { - lastRunId: null, - lastAction: null, - blueprintVersion: null, - sandboxName: null, - migrationSnapshot: null, - hostBackupPath: null, - createdAt: null, - updatedAt: new Date().toISOString(), - lastRebuildAt: null, - lastRebuildBackupPath: null, - shieldsDown: false, - shieldsDownAt: null, - shieldsDownTimeout: null, - shieldsDownReason: null, - shieldsDownPolicy: null, - shieldsPolicySnapshotPath: null, - }; -} describe("commands/shields-status", () => { - beforeEach(() => { - vi.clearAllMocks(); - mockedLoadState.mockReturnValue(blankState()); - }); - - it("reports shields UP when not down", () => { - const result = slashShieldsStatus(); - expect(result.text).toContain("Shields: UP"); - expect(result.text).toContain("normal security level"); - }); - - it("shows last-lowered info when UP with a previous snapshot", () => { - mockedLoadState.mockReturnValue({ - ...blankState(), - shieldsDown: false, - shieldsPolicySnapshotPath: "/home/user/.nemoclaw/state/policy-snapshot-123.yaml", - }); - const result = slashShieldsStatus(); - expect(result.text).toContain("Shields: UP"); - expect(result.text).toContain("policy-snapshot-123.yaml"); - }); - - it("reports shields DOWN with details", () => { - mockedLoadState.mockReturnValue({ - ...blankState(), - shieldsDown: true, - shieldsDownAt: "2026-04-13T14:30:00Z", - shieldsDownTimeout: 300, - shieldsDownReason: "Installing Slack plugin", - shieldsDownPolicy: "permissive", - shieldsPolicySnapshotPath: "/home/user/.nemoclaw/state/policy-snapshot-1681394200.yaml", - }); - - const result = slashShieldsStatus(); - expect(result.text).toContain("Shields: DOWN"); - expect(result.text).toContain("2026-04-13T14:30:00Z"); - expect(result.text).toContain("Installing Slack plugin"); - expect(result.text).toContain("permissive"); - }); - - it("shows remaining time when shields are down", () => { - const fiveMinutesAgo = new Date(Date.now() - 2 * 60 * 1000).toISOString(); - mockedLoadState.mockReturnValue({ - ...blankState(), - shieldsDown: true, - shieldsDownAt: fiveMinutesAgo, - shieldsDownTimeout: 300, // 5 minutes total - shieldsDownReason: "Testing", - shieldsDownPolicy: "permissive", - }); - - const result = slashShieldsStatus(); - expect(result.text).toContain("remaining"); - }); - - it("handles shields DOWN with no timeout set", () => { - mockedLoadState.mockReturnValue({ - ...blankState(), - shieldsDown: true, - shieldsDownAt: new Date().toISOString(), - shieldsDownTimeout: null, - shieldsDownReason: "Manual override", - shieldsDownPolicy: "custom", - }); - - const result = slashShieldsStatus(); - expect(result.text).toContain("Shields: DOWN"); - expect(result.text).toContain("Manual override"); - expect(result.text).not.toContain("remaining"); - }); - - it("includes security warning when shields are down", () => { - mockedLoadState.mockReturnValue({ - ...blankState(), - shieldsDown: true, - shieldsDownAt: new Date().toISOString(), - shieldsDownTimeout: 300, - }); + it.each([ + { label: "an omitted", arg: undefined }, + { label: "an empty", arg: "" }, + { label: "a whitespace-only", arg: " " }, + { label: "an explicit", arg: "status" }, + ])("directs $label status request to the authoritative host CLI", ({ arg }) => { + const result = slashShieldsStatus(arg); - const result = slashShieldsStatus(); - expect(result.text).toContain("Warning"); - expect(result.text).toContain("nemoclaw shields up"); + expect(result.text).toContain("Shields status unavailable inside the sandbox"); + expect(result.text).toContain("cannot verify the host-side shields posture"); + expect(result.text).toContain("nemoclaw shields status"); + expect(result.text).not.toMatch(/Shields: (UP|DOWN|NOT CONFIGURED)/); }); - it("shows default values when reason and policy are not specified", () => { - mockedLoadState.mockReturnValue({ - ...blankState(), - shieldsDown: true, - shieldsDownAt: new Date().toISOString(), - shieldsDownTimeout: 300, - }); + it.each(["up", "down"])("returns host-only guidance for `%s`", (action) => { + const result = slashShieldsStatus(action); - const result = slashShieldsStatus(); - expect(result.text).toContain("not specified"); - expect(result.text).toContain("permissive"); - }); - - it("treats an empty string argument as a read-only status request", () => { - const result = slashShieldsStatus(""); - expect(result.text).toContain("Shields: UP"); - }); - - it("treats whitespace-only argument as a read-only status request", () => { - const result = slashShieldsStatus(" "); - expect(result.text).toContain("Shields: UP"); - }); - - it("treats explicit `status` argument as a read-only status request", () => { - const result = slashShieldsStatus("status"); - expect(result.text).toContain("Shields: UP"); - }); - - it("returns a host-only guidance message for `down`", () => { - const result = slashShieldsStatus("down"); - expect(result.text).toContain("Shields down"); + expect(result.text).toContain(`Shields ${action}`); expect(result.text).toContain("host-only"); - expect(result.text).toContain("nemoclaw shields down"); - expect(mockedLoadState).not.toHaveBeenCalled(); + expect(result.text).toContain(`nemoclaw shields ${action}`); + expect(result.text).toContain("cannot verify shields status"); }); - it("returns a host-only guidance message for `up`", () => { - const result = slashShieldsStatus("up"); - expect(result.text).toContain("Shields up"); + it("trims surrounding whitespace before classifying the sub-argument", () => { + const result = slashShieldsStatus(" down "); + expect(result.text).toContain("Shields down"); expect(result.text).toContain("host-only"); - expect(result.text).toContain("nemoclaw shields up"); - expect(mockedLoadState).not.toHaveBeenCalled(); }); - it("returns an `Unknown argument` message for an unrecognised sub-argument", () => { + it("returns usage for an unrecognised sub-argument", () => { const result = slashShieldsStatus("abcxyz"); expect(result.text).toContain("Unknown argument"); expect(result.text).toContain("abcxyz"); expect(result.text).toContain("/nemoclaw shields [status]"); - expect(mockedLoadState).not.toHaveBeenCalled(); }); - it("trims surrounding whitespace before classifying the sub-argument", () => { - const result = slashShieldsStatus(" down "); - expect(result.text).toContain("Shields down"); - expect(result.text).toContain("host-only"); - }); - - it("strips backticks from the echoed unknown argument so inline-code formatting cannot be broken", () => { + it("strips Markdown delimiters from an echoed unknown argument", () => { const result = slashShieldsStatus("`evil`"); expect(result.text).toContain("Unknown argument"); expect(result.text).not.toContain("`evil`"); expect(result.text).toContain("?evil?"); }); - it("strips ASCII control characters from the echoed unknown argument", () => { + it("strips ASCII control characters from an echoed unknown argument", () => { const result = slashShieldsStatus("ab\x01cd\x1Fef"); expect(result.text).toContain("Unknown argument"); expect(result.text).toContain("ab?cd?ef"); @@ -192,10 +56,8 @@ describe("commands/shields-status", () => { expect(result.text).not.toContain("\x1F"); }); - it("truncates an overly long unknown argument with an ellipsis", () => { - const long = "a".repeat(64); - const result = slashShieldsStatus(long); - expect(result.text).toContain("Unknown argument"); + it("truncates an overly long unknown argument", () => { + const result = slashShieldsStatus("a".repeat(64)); expect(result.text).toContain(`${"a".repeat(32)}…`); expect(result.text).not.toContain("a".repeat(33)); }); diff --git a/nemoclaw/src/commands/shields-status.ts b/nemoclaw/src/commands/shields-status.ts index de0a752689b..9c45b03ec1a 100644 --- a/nemoclaw/src/commands/shields-status.ts +++ b/nemoclaw/src/commands/shields-status.ts @@ -5,15 +5,14 @@ * Slash command handler for `/nemoclaw shields`. * * Routes the optional sub-argument: - * - empty / `status` — reports the current shields state (read-only). + * - empty / `status` — points to authoritative host-side status. * - `up` / `down` — returns host-only guidance pointing at the host CLI. * - anything else — returns an `Unknown argument` message with usage. * - * Shields can only be lowered or raised from the host CLI (security invariant). + * Shields state is owned by the host CLI and is not projected into the plugin. */ import type { PluginCommandResult } from "../index.js"; -import { loadState } from "../blueprint/state.js"; const MAX_ARG_DISPLAY_LEN = 32; @@ -38,7 +37,7 @@ export function slashShieldsStatus(arg?: string): PluginCommandResult { `nemoclaw shields ${trimmed}`, "```", "", - "Inside the sandbox, `/nemoclaw shields` is read-only. Use `/nemoclaw shields` or `/nemoclaw shields status` to see the current state.", + "Inside the sandbox, `/nemoclaw shields` is read-only and cannot verify shields status.", ].join("\n"), }; } @@ -55,37 +54,11 @@ export function slashShieldsStatus(arg?: string): PluginCommandResult { }; } - const state = loadState(); - - if (!state.shieldsDown) { - const lines = ["**Shields: UP**", "", "Sandbox policy is at normal security level."]; - - if (state.shieldsPolicySnapshotPath) { - lines.push("", `Last lowered: policy snapshot at ${state.shieldsPolicySnapshotPath}`); - } - - return { text: lines.join("\n") }; - } - - const downSince = state.shieldsDownAt ? new Date(state.shieldsDownAt) : null; - const elapsed = downSince ? Math.floor((Date.now() - downSince.getTime()) / 1000) : 0; - const remaining = - state.shieldsDownTimeout != null ? Math.max(0, state.shieldsDownTimeout - elapsed) : null; - - const lines = ["**Shields: DOWN**", "", `Since: ${state.shieldsDownAt ?? "unknown"}`]; - - if (remaining !== null) { - const mins = Math.floor(remaining / 60); - const secs = remaining % 60; - lines.push(`Timeout: ${String(mins)}m ${String(secs)}s remaining`); - } - - lines.push(`Reason: ${state.shieldsDownReason ?? "not specified"}`); - lines.push(`Policy: ${state.shieldsDownPolicy ?? "permissive"}`); - lines.push( - "", - "**Warning:** Sandbox security is relaxed. Run `nemoclaw shields up` from the host when done.", - ); - - return { text: lines.join("\n") }; + return { + text: [ + "**Shields status unavailable inside the sandbox**", + "", + "This command cannot verify the host-side shields posture. Run `nemoclaw shields status` from the host for authoritative status.", + ].join("\n"), + }; } diff --git a/nemoclaw/src/commands/slash.test.ts b/nemoclaw/src/commands/slash.test.ts index 2b9928886b3..1110cc7d395 100644 --- a/nemoclaw/src/commands/slash.test.ts +++ b/nemoclaw/src/commands/slash.test.ts @@ -1,9 +1,9 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import { describe, it, expect, beforeEach, vi } from "vitest"; -import type { PluginCommandContext, OpenClawPluginApi } from "../index.js"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import type { NemoClawState } from "../blueprint/state.js"; +import type { OpenClawPluginApi, PluginCommandContext } from "../index.js"; import type { NemoClawOnboardConfig } from "../onboard/config.js"; vi.mock("../blueprint/state.js", () => ({ @@ -17,21 +17,21 @@ vi.mock("../onboard/config.js", () => ({ })); vi.mock("./shields-status.js", () => ({ - slashShieldsStatus: vi.fn(() => ({ text: "**Shields: UP**" })), + slashShieldsStatus: vi.fn(() => ({ text: "**Shields status unavailable**" })), })); vi.mock("./config-show.js", () => ({ slashConfigShow: vi.fn(() => ({ text: "**NemoClaw Config**" })), })); -import { handleSlashCommand } from "./slash.js"; import { loadState } from "../blueprint/state.js"; import { - loadOnboardConfig, describeOnboardEndpoint, describeOnboardProvider, + loadOnboardConfig, } from "../onboard/config.js"; import { slashShieldsStatus } from "./shields-status.js"; +import { handleSlashCommand } from "./slash.js"; const mockedLoadState = vi.mocked(loadState); const mockedLoadOnboardConfig = vi.mocked(loadOnboardConfig); @@ -75,12 +75,6 @@ function blankState(): NemoClawState { updatedAt: new Date().toISOString(), lastRebuildAt: null, lastRebuildBackupPath: null, - shieldsDown: false, - shieldsDownAt: null, - shieldsDownTimeout: null, - shieldsDownReason: null, - shieldsDownPolicy: null, - shieldsPolicySnapshotPath: null, }; } @@ -102,6 +96,8 @@ describe("commands/slash", () => { expect(result.text).toContain("Subcommands:"); expect(result.text).toContain("status"); expect(result.text).toContain("shields"); + expect(result.text).toContain("Show how to check shields status from the host"); + expect(result.text).not.toContain("up/down, timeout, policy"); expect(result.text).toContain("config"); expect(result.text).toContain("eject"); expect(result.text).toContain("onboard"); diff --git a/nemoclaw/src/commands/slash.ts b/nemoclaw/src/commands/slash.ts index c125f3a4da0..9c4436ee1e6 100644 --- a/nemoclaw/src/commands/slash.ts +++ b/nemoclaw/src/commands/slash.ts @@ -12,20 +12,20 @@ * /nemoclaw - show help */ +import { loadState } from "../blueprint/state.js"; import { getPluginConfig, type OpenClawPluginApi, type PluginCommandContext, type PluginCommandResult, } from "../index.js"; -import { loadState } from "../blueprint/state.js"; import { describeOnboardEndpoint, describeOnboardProvider, loadOnboardConfig, } from "../onboard/config.js"; -import { slashShieldsStatus } from "./shields-status.js"; import { slashConfigShow } from "./config-show.js"; +import { slashShieldsStatus } from "./shields-status.js"; export function handleSlashCommand( ctx: PluginCommandContext, @@ -60,7 +60,7 @@ function slashHelp(): PluginCommandResult { "", "Subcommands:", " `status` - Show sandbox, blueprint, and inference state", - " `shields` - Show shields status (up/down, timeout, policy)", + " `shields` - Show how to check shields status from the host", " `config` - Show sandbox configuration (credentials redacted)", " `eject` - Show rollback instructions", " `onboard` - Show onboarding status and instructions", diff --git a/nemoclaw/src/runtime-context.test.ts b/nemoclaw/src/runtime-context.test.ts index 861b5234892..48c9d88b277 100644 --- a/nemoclaw/src/runtime-context.test.ts +++ b/nemoclaw/src/runtime-context.test.ts @@ -33,12 +33,6 @@ function blankState(patch: Partial = {}): NemoClawState { updatedAt: "2026-03-01T00:00:00.000Z", lastRebuildAt: null, lastRebuildBackupPath: null, - shieldsDown: false, - shieldsDownAt: null, - shieldsDownTimeout: null, - shieldsDownReason: null, - shieldsDownPolicy: null, - shieldsPolicySnapshotPath: null, ...patch, }; }