Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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: 13 additions & 6 deletions docs/reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@ If the preset is unknown or not currently applied, the command exits non-zero wi

Unchecking a preset in the onboard TUI checkbox also removes it from the sandbox.

### `$$nemoclaw <name> policy exclude`
### `$$nemoclaw <name> policy exclude <key>`

Persistently exclude one exact entry from the agent baseline policy after previewing the egress and support impact that the change removes.
The preview names the supported features that may stop working.
Expand All @@ -1972,21 +1972,28 @@ $$nemoclaw my-assistant policy exclude nous_research --dry-run
$$nemoclaw my-assistant policy exclude nous_research --force
```

When a release changes an excluded entry, first run `policy restore <key>` to clear the stale record, preview the current scope with `policy exclude <key> --dry-run`, and then explicitly exclude it again if you still accept the support impact.
When a release removes the entry, run `policy restore <key>` only to clear the stale exclusion record; there is no replacement scope to review or re-approve.
When a release changes an excluded entry, first run `$$nemoclaw <name> policy restore <key> --force` to clear the stale record, preview the current scope with `$$nemoclaw <name> policy exclude <key> --dry-run`, and then explicitly exclude it again if you still accept the support impact.
When a release removes the entry, run `$$nemoclaw <name> policy restore <key> --force` only to clear the stale exclusion record; there is no replacement scope to review or re-approve.

### `$$nemoclaw <name> policy restore`
### `$$nemoclaw <name> policy restore <key>`

Restore a previously excluded entry from the current agent baseline and clear its durable exclusion record.
Use `--dry-run` to preview the egress that would be restored.
When the current baseline still defines the entry, the command prints the egress it re-allows.
When the baseline no longer defines the entry, the command states that it will clear only the stale exclusion record.
Both paths require explicit acknowledgement unless you use `--dry-run`; use `--force` or `--yes` for non-interactive acknowledgement.
If a restore is interrupted, NemoClaw finalizes it only when the durable exclusion still exactly matches the staged exclusion and the current release baseline still exactly matches the journaled live target.
If either value changed or the current baseline is unreadable, the journal remains in `repair required` state so you can inspect and re-review the current scope instead of silently accepting a different entry.

```bash
$$nemoclaw my-assistant policy restore nous_research --dry-run
$$nemoclaw my-assistant policy restore nous_research
$$nemoclaw my-assistant policy restore nous_research --force
```

| Flag | Description |
|------|-------------|
| `--yes`, `-y`, `--force` | Skip the confirmation prompt |
| `--dry-run` | Preview the restored egress without applying changes |

### `$$nemoclaw <name> policy explain`

Print a redacted summary of the active policy context for a sandbox so an agent or operator can reason about what is allowed, what is blocked, and how to request a change.
Expand Down
10 changes: 7 additions & 3 deletions docs/reference/network-policies.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ To recover from baseline drift, first check whether the release changed the entr
If the entry still exists with different content, clear the stale record, review the current scope, and explicitly approve it again only if you still accept the impact:

```bash
$$nemoclaw <sandbox-name> policy restore <key>
$$nemoclaw <sandbox-name> policy restore <key> --force
$$nemoclaw <sandbox-name> policy exclude <key> --dry-run
$$nemoclaw <sandbox-name> policy exclude <key> --force
```
Expand All @@ -325,7 +325,7 @@ If the release removed the entry entirely, `policy exclude <key>` fails with "Un
Clear the stale record instead:

```bash
$$nemoclaw <sandbox-name> policy restore <key>
$$nemoclaw <sandbox-name> policy restore <key> --force
```

List active exclusions with `policy list`.
Expand All @@ -335,7 +335,11 @@ An unreadable live policy is unverified, while a live policy that contains the k
Restore an entry against the current baseline and clear its exclusion:

```bash
$$nemoclaw <sandbox-name> policy restore <key>
$$nemoclaw <sandbox-name> policy restore <key> --force
```

When the current baseline still defines the entry, `policy restore` prints the egress it re-allows.
When the baseline no longer defines the entry, the command states that it will clear only the stale exclusion record.
Both paths require explicit acknowledgement unless you use `--dry-run`; use `--force` or `--yes` for non-interactive acknowledgement.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Excluding a baseline entry leaves agent features that depend on it unsupported for that sandbox.
2 changes: 1 addition & 1 deletion src/commands/sandbox/policy/exclude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class PolicyExcludeCommand extends NemoClawCommand {
static summary = "Exclude an entry from the agent baseline policy";
static description =
"Persistently exclude an exact baseline network policy entry from a sandbox. The removed egress and its support impact are previewed before mutation, and the exclusion is replayed across rebuild.";
static usage = ["<name> <key> [--force|-f] [--yes|-y] [--dry-run]"];
static usage = ["<name> <key> [--force] [--yes|-y] [--dry-run]"];
static examples = [
"<%= config.bin %> sandbox policy exclude alpha nous_research --force",
"<%= config.bin %> sandbox policy exclude alpha nous_research --dry-run",
Expand Down
29 changes: 29 additions & 0 deletions src/commands/sandbox/policy/mutate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ describe("policy mutation oclif commands", () => {
});
});

it("accepts the same acknowledgement flags on restore as on exclude (#8114)", async () => {
await PolicyRestoreCommand.run(["alpha", "nous_research", "-y"], rootDir);

expect(mocks.restoreSandboxBaseline).toHaveBeenCalledWith("alpha", {
key: "nous_research",
yes: true,
force: false,
dryRun: false,
});

await PolicyRestoreCommand.run(["alpha", "nous_research", "--yes"], rootDir);

expect(mocks.restoreSandboxBaseline).toHaveBeenLastCalledWith("alpha", {
key: "nous_research",
yes: true,
force: false,
dryRun: false,
});

await PolicyRestoreCommand.run(["alpha", "nous_research", "--force"], rootDir);

expect(mocks.restoreSandboxBaseline).toHaveBeenLastCalledWith("alpha", {
key: "nous_research",
yes: false,
force: true,
dryRun: false,
});
});

it("requires an explicit baseline key before dispatch", async () => {
await expect(PolicyExcludeCommand.run(["alpha"], rootDir)).rejects.toThrow();

Expand Down
7 changes: 4 additions & 3 deletions src/commands/sandbox/policy/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NemoClawCommand } from "../../../lib/cli/nemoclaw-oclif-command";
import {
commonPolicyOptions,
policyBaselineArgs,
policyBaselineRestoreFlags,
policyMutationFlags,
} from "../../../lib/sandbox/policy-command-support";

export default class PolicyRestoreCommand extends NemoClawCommand {
Expand All @@ -16,13 +16,14 @@ export default class PolicyRestoreCommand extends NemoClawCommand {
static summary = "Restore a previously excluded baseline entry";
static description =
"Restore an excluded baseline network policy entry against the current release baseline and drop its recorded exclusion.";
static usage = ["<name> <key> [--dry-run]"];
static usage = ["<name> <key> [--force] [--yes|-y] [--dry-run]"];
static examples = [
"<%= config.bin %> sandbox policy restore alpha nous_research",
"<%= config.bin %> sandbox policy restore alpha nous_research --yes",
"<%= config.bin %> sandbox policy restore alpha nous_research --dry-run",
];
static args = policyBaselineArgs;
static flags = policyBaselineRestoreFlags;
static flags = policyMutationFlags;

public async run(): Promise<void> {
const { args, flags } = await this.parse(PolicyRestoreCommand);
Expand Down
72 changes: 71 additions & 1 deletion src/lib/actions/sandbox/policy-channel-baseline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,82 @@ describe("restoreSandboxBaseline (#7178)", () => {
expect(restoreBaselineEntryMock).not.toHaveBeenCalled();
});

it("restores a recorded exclusion", async () => {
it("restores a recorded exclusion after interactive acknowledgement", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
await restoreSandboxBaseline("alpha", { key: "nous_research" });
expect(promptMock).toHaveBeenCalledOnce();
expect(restoreBaselineEntryMock).toHaveBeenCalledWith("alpha", "nous_research");
});

it("requires explicit acknowledgement in non-interactive mode (#8114)", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
process.env.NEMOCLAW_NON_INTERACTIVE = "1";
const code = await captureExit(() => restoreSandboxBaseline("alpha", { key: "nous_research" }));
expect(code).toBe(1);
expect(console.error).toHaveBeenCalledWith(
expect.stringContaining("Non-interactive restore requires explicit acknowledgement"),
);
expect(promptMock).not.toHaveBeenCalled();
expect(restoreBaselineEntryMock).not.toHaveBeenCalled();
});

it("does not restore when standard input closes before acknowledgement (#8114)", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
promptMock.mockRejectedValue(
Object.assign(new Error("Prompt closed before input"), { code: "EOF" }),
);

const code = await captureExit(() => restoreSandboxBaseline("alpha", { key: "nous_research" }));

expect(code).toBe(1);
expect(console.error).toHaveBeenCalledWith(
expect.stringContaining("No input available on stdin"),
);
expect(restoreBaselineEntryMock).not.toHaveBeenCalled();
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it("restores without prompting when acknowledged via --yes (#8114)", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
process.env.NEMOCLAW_NON_INTERACTIVE = "1";
await restoreSandboxBaseline("alpha", { key: "nous_research", yes: true });
expect(promptMock).not.toHaveBeenCalled();
expect(restoreBaselineEntryMock).toHaveBeenCalledWith("alpha", "nous_research");
});

it("restores without prompting when acknowledged via --force (#8114)", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
await restoreSandboxBaseline("alpha", { key: "nous_research", force: true });
expect(promptMock).not.toHaveBeenCalled();
expect(restoreBaselineEntryMock).toHaveBeenCalledWith("alpha", "nous_research");
});

it("discloses the restored egress before interactive acknowledgement (#8114)", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
promptMock.mockImplementation(async () => {
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("re-allows:"));
return "n";
});

await restoreSandboxBaseline("alpha", { key: "nous_research" });

expect(promptMock).toHaveBeenCalledOnce();
expect(restoreBaselineEntryMock).not.toHaveBeenCalled();
});

it("aborts when the interactive confirmation is declined (#8114)", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
promptMock.mockResolvedValue("n");
await restoreSandboxBaseline("alpha", { key: "nous_research" });
expect(restoreBaselineEntryMock).not.toHaveBeenCalled();
});

it("does not mutate on --dry-run", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
await restoreSandboxBaseline("alpha", { key: "nous_research", dryRun: true });
expect(promptMock).not.toHaveBeenCalled();
expect(restoreBaselineEntryMock).not.toHaveBeenCalled();
});

it("does not mutate when a recorded agent baseline cannot be resolved (#7194)", async () => {
getBaselineExclusionsMock.mockReturnValue([{ key: "nous_research", digest: "digest-1" }]);
vi.mocked(policies.resolveSandboxBaselinePolicy).mockImplementation(() => {
Expand Down
27 changes: 26 additions & 1 deletion src/lib/actions/sandbox/policy-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2014,10 +2014,13 @@ async function restoreSandboxBaselineUnlocked(
options: PolicyBaselineOptions,
): Promise<void> {
const dryRun = Boolean(options.dryRun);
const explicitAck = Boolean(options.yes || options.force);
const key = options.key?.trim();
if (!key) {
console.error(" A baseline key is required.");
console.error(` Usage: ${CLI_NAME} <sandbox> policy restore <key> [--dry-run]`);
console.error(
` Usage: ${CLI_NAME} <sandbox> policy restore <key> [--yes|-y] [--force] [--dry-run]`,
);
process.exit(1);
}

Expand Down Expand Up @@ -2053,6 +2056,28 @@ async function restoreSandboxBaselineUnlocked(
return;
}

if (isNonInteractive() && !explicitAck) {
console.error(
" Non-interactive restore requires explicit acknowledgement: pass --force (or --yes).",
);
process.exit(1);
}
if (!explicitAck) {
let confirm: string;
try {
confirm = await askPrompt(` Restore '${key}' for sandbox '${sandboxName}'? [y/N]: `);
} catch (error) {
const code = (error as NodeJS.ErrnoException | null)?.code;
if (code !== "EOF") throw error;
console.error(" No input available on stdin, so policy restore cannot prompt.");
console.error(
` Usage: ${CLI_NAME} <sandbox> policy restore <key> [--yes|-y] [--force] [--dry-run]`,
);
process.exit(1);
}
if (!confirm.trim().toLowerCase().startsWith("y")) return;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

if (!policies.restoreBaselineEntry(sandboxName, key)) {
refreshSandboxPolicyContextFile(sandboxName);
process.exit(1);
Expand Down
6 changes: 4 additions & 2 deletions src/lib/cli/public-display-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,18 @@ const PUBLIC_DISPLAY_LAYOUT: Record<string, readonly PublicDisplayLayout[]> = {
{
group: "Policy Presets",
order: 21,
usage: "nemoclaw <name> policy exclude <key>",
description: "Exclude a baseline policy entry (persisted, replayed on rebuild)",
flags: "(--force, -f, --yes, -y, --dry-run)",
flags: "(--force, --yes, -y, --dry-run)",
},
],
"sandbox:policy:restore": [
{
group: "Policy Presets",
order: 22,
usage: "nemoclaw <name> policy restore <key>",
description: "Restore a previously excluded baseline entry",
flags: "(--dry-run)",
flags: "(--force, --yes, -y, --dry-run)",
},
],
"sandbox:rebuild": [
Expand Down
2 changes: 0 additions & 2 deletions src/lib/sandbox/policy-command-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,3 @@ export const policyMutationFlags = {
force: forceFlag(),
"dry-run": dryRunFlag(),
};

export const policyBaselineRestoreFlags = { "dry-run": dryRunFlag() };
15 changes: 15 additions & 0 deletions test/root-help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ describe("root help", () => {
}
});

it("shows the supported policy acknowledgement flags", () => {
const log = vi.spyOn(console, "log").mockImplementation(() => {});

renderRootHelp();

const output = log.mock.calls.map(([line]) => String(line)).join("\n");
expect(output).toMatch(
/nemoclaw <name> policy exclude <key>[^\n]*\(--force, --yes, -y, --dry-run\)/,
);
expect(output).toMatch(
/nemoclaw <name> policy restore <key>[^\n]*\(--force, --yes, -y, --dry-run\)/,
);
expect(output).not.toContain("(--force, -f, --yes, -y, --dry-run)");
});

it("lists --destroy-user-data under uninstall flags without unsupported --keep flags", () => {
const log = vi.spyOn(console, "log").mockImplementation(() => {});

Expand Down
Loading