Skip to content

feat(policy): allow selecting policy presets by number#1195

Merged
cv merged 7 commits intoNVIDIA:mainfrom
cr7258:preset-select
Apr 3, 2026
Merged

feat(policy): allow selecting policy presets by number#1195
cv merged 7 commits intoNVIDIA:mainfrom
cr7258:preset-select

Conversation

@cr7258
Copy link
Copy Markdown
Contributor

@cr7258 cr7258 commented Mar 31, 2026

Summary

Allow nemoclaw <sandbox> policy-add to be selected by number instead of typing preset names.

root@se7en:/tmp/NemoClaw# node bin/nemoclaw.js seven-demo policy-add

  Available presets:
    1) ○ discord — Discord API, gateway, and CDN access
    2) ○ docker — Docker Hub and NVIDIA container registry access
    3) ○ huggingface — Hugging Face Hub, LFS, and Inference API access
    4) ○ jira — Jira and Atlassian Cloud access
    5) ● npm — npm and Yarn registry access
    6) ○ outlook — Microsoft Outlook and Graph API access
    7) ○ pypi — Python Package Index (PyPI) access
    8) ○ slack — Slack API, Socket Mode, and webhooks access
    9) ○ telegram — Telegram Bot API access

  ● applied, ○ not applied

  Choose preset [1]: 7
  Apply 'pypi' to sandbox 'seven-demo'? [Y/n]: y
✓ Policy version 3 submitted (hash: 462a3f55b4da)
✓ Policy version 3 loaded (active version: 3)
  Applied preset: pypi

Related Issue

Fixes #1164

Changes

Type of Change

  • Code change for a new feature, bug fix, or refactor.
  • Code change with doc updates.
  • Doc only. Prose changes without code sample modifications.
  • Doc only. Includes code sample changes.

Testing

  • npx prek run --all-files passes (or equivalently make check).
  • npm test passes.
  • make docs builds without warnings. (for doc-only changes)

Checklist

General

Code Changes

  • Formatters applied — npx prek run --all-files auto-fixes formatting (or make format for targeted runs).
  • Tests added or updated for new or changed behavior.
  • No secrets, API keys, or credentials committed.
  • Doc pages updated for any user-facing behavior changes (new commands, changed defaults, new features, bug fixes that contradict existing docs).

Doc Changes

  • Follows the style guide. Try running the update-docs agent skill to draft changes while complying with the style guide. For example, prompt your agent with "/update-docs catch up the docs for the new changes I made in this PR."
  • New pages include SPDX license header and frontmatter, if creating a new page.
  • Cross-references and links verified.

Signed-off-by: Seven Cheng sevenc@nvidia.com

Summary by CodeRabbit

  • New Features

    • Interactive preset selection menu with visual status (● applied, ○ not applied)
    • Empty input selects the default (first non-applied) when available
    • Policy-add CLI now invokes the interactive selector and asks for confirmation before applying
  • Validation

    • Rejects invalid, non-numeric, out-of-range, or already-applied selections and prints feedback
  • Tests

    • Expanded tests covering selection behavior, defaulting, rejection cases, list rendering, and CLI confirmation flow

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added an exported interactive CLI chooser selectFromList(items, { applied = [] }) in bin/lib/policies.js, integrated it into sandboxPolicyAdd in bin/nemoclaw.js, and expanded tests in test/policies.test.js to exercise selection, defaulting, validation, and confirmation-driven apply behavior.

Changes

Cohort / File(s) Summary
Interactive Selection Feature
bin/lib/policies.js
New selectFromList(items, { applied = [] } = {}) using readline to print a numbered list to stderr with applied () / not-applied () markers, compute a default (first unapplied), read trimmed input, validate numeric index, reject already-applied or out-of-range selections, and resolve with the selected item name or null.
CLI Integration
bin/nemoclaw.js
Replaced the prior free-text prompt/list logic in sandboxPolicyAdd() with policies.selectFromList(allPresets, { applied }); subsequent confirmation and applyPreset invocation remain unchanged.
Tests
test/policies.test.js
Added subprocess helpers and Vitest cases invoking selectFromList and policy-add to validate numeric selection, empty-input defaulting, handling of already-applied/out-of-range/non-numeric input, list rendering (markers/legend/default), and confirmation-gated application.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant User
participant CLI as NemoClaw CLI
participant Policies as policies.selectFromList
participant Readline as Readline (tty)
User->>CLI: run "nemoclaw policy-add"
CLI->>Policies: call selectFromList(allPresets, {applied})
Policies->>Readline: render numbered list + legend to stderr
Readline->>User: display prompt, wait for input
User-->>Readline: enters index or empty input
Readline-->>Policies: return raw input
Policies->>Policies: compute effective selection (defaulting, validate, check applied)
alt valid & not applied
Policies-->>CLI: resolve selected preset name
CLI->>User: ask confirmation
User-->>CLI: confirm
CLI->>Policies: applyPreset(sandboxName, preset)
else invalid / already applied / blank-without-default
Policies-->>CLI: resolve null
CLI->>User: abort or skip apply
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰
I tap the keys with whiskered cheer,
Circles, bullets, choices near.
A quiet default, numbered bright,
Hop and pick by candlelight.
Hooray — selection now takes flight! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature: allowing numeric selection of policy presets instead of typing names, which directly addresses the PR's primary objective.
Linked Issues check ✅ Passed The PR implements numeric preset selection addressing issue #1164's request for improved preset selection usability, though it uses numeric input rather than arrow keys.
Out of Scope Changes check ✅ Passed All changes (new selectFromList function, integration into policy-add command, and comprehensive test coverage) are directly scoped to implementing numeric preset selection per issue #1164.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/policies.test.js`:
- Around line 22-62: The helper runPolicyAdd creates a temporary directory
(tmpDir) and writes scriptPath but never removes it; wrap the spawnSync call in
a try/finally (or ensure cleanup after execution) and remove tmpDir in the
finally block using a recursive forced removal (e.g., fs.rmSync(tmpDir, {
recursive: true, force: true })) so the temp directory (and the script file
inside) is always deleted after runPolicyAdd completes, even on errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7d421a00-4df3-41ba-a6d8-5b9939b63535

📥 Commits

Reviewing files that changed from the base of the PR and between 6b9820a and 1b42ca3.

📒 Files selected for processing (3)
  • bin/lib/policies.js
  • bin/nemoclaw.js
  • test/policies.test.js

@cv cv self-assigned this Apr 1, 2026
@wscurran wscurran added status: triage For new items that haven't been reviewed yet. NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI). enhancement: feature Use this label to identify requests for new capabilities in NemoClaw. and removed status: triage For new items that haven't been reviewed yet. labels Apr 1, 2026
@cv cv merged commit 494ecde into NVIDIA:main Apr 3, 2026
8 checks passed
cjagwani pushed a commit to fdzdev/NemoClaw that referenced this pull request Apr 3, 2026
<!-- markdownlint-disable MD041 -->
<!-- 1-3 sentences: what this PR does and why. -->

Allow `nemoclaw <sandbox> policy-add` to be selected by number instead
of typing preset names.

```bash
root@se7en:/tmp/NemoClaw# node bin/nemoclaw.js seven-demo policy-add

  Available presets:
    1) ○ discord — Discord API, gateway, and CDN access
    2) ○ docker — Docker Hub and NVIDIA container registry access
    3) ○ huggingface — Hugging Face Hub, LFS, and Inference API access
    4) ○ jira — Jira and Atlassian Cloud access
    5) ● npm — npm and Yarn registry access
    6) ○ outlook — Microsoft Outlook and Graph API access
    7) ○ pypi — Python Package Index (PyPI) access
    8) ○ slack — Slack API, Socket Mode, and webhooks access
    9) ○ telegram — Telegram Bot API access

  ● applied, ○ not applied

  Choose preset [1]: 7
  Apply 'pypi' to sandbox 'seven-demo'? [Y/n]: y
✓ Policy version 3 submitted (hash: 462a3f55b4da)
✓ Policy version 3 loaded (active version: 3)
  Applied preset: pypi
```

<!-- Link to the issue: Fixes #NNN or Closes #NNN. Remove this section
if none. -->
Fixes NVIDIA#1164

<!-- Bullet list of key changes. -->

<!-- Check the one that applies. -->
- [x] Code change for a new feature, bug fix, or refactor.
- [ ] Code change with doc updates.
- [ ] Doc only. Prose changes without code sample modifications.
- [ ] Doc only. Includes code sample changes.

<!-- What testing was done? -->
- [x] `npx prek run --all-files` passes (or equivalently `make check`).
- [x] `npm test` passes.
- [ ] `make docs` builds without warnings. (for doc-only changes)

- [x] I have read and followed the [contributing
guide](https://github.com/NVIDIA/NemoClaw/blob/main/CONTRIBUTING.md).
- [x] I have read and followed the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md).
(for doc-only changes)

<!-- Skip if this is a doc-only PR. -->
- [x] Formatters applied — `npx prek run --all-files` auto-fixes
formatting (or `make format` for targeted runs).
- [x] Tests added or updated for new or changed behavior.
- [x] No secrets, API keys, or credentials committed.
- [ ] Doc pages updated for any user-facing behavior changes (new
commands, changed defaults, new features, bug fixes that contradict
existing docs).

<!-- Skip if this PR has no doc changes. -->
- [ ] Follows the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md).
Try running the `update-docs` agent skill to draft changes while
complying with the style guide. For example, prompt your agent with
"`/update-docs` catch up the docs for the new changes I made in this
PR."
- [ ] New pages include SPDX license header and frontmatter, if creating
a new page.
- [ ] Cross-references and links verified.

---
<!-- DCO sign-off (required by CI). Replace with your real name and
email. -->
Signed-off-by: Seven Cheng <sevenc@nvidia.com>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

* **New Features**
* Interactive preset selection menu with visual status (● applied, ○ not
applied)
  * Empty input selects the default (first non-applied) when available
* Policy-add CLI now invokes the interactive selector and asks for
confirmation before applying

* **Validation**
* Rejects invalid, non-numeric, out-of-range, or already-applied
selections and prints feedback

* **Tests**
* Expanded tests covering selection behavior, defaulting, rejection
cases, list rendering, and CLI confirmation flow
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
quanticsoul4772 added a commit to quanticsoul4772/NemoClaw that referenced this pull request Apr 4, 2026
Add selectFromList() to policies.js — shows a numbered menu with applied/
not-applied markers, accepts numeric input, defaults to first unapplied
preset. Replace inline listing + open-ended text prompt in sandboxPolicyAdd
with a single selectFromList() call.

Also fix policies.test.js: update preset count 9→10 and add missing
'github' to expected preset names (pre-existing test failures from when
the github preset was added without updating the test).
Backport of upstream NVIDIA#1195.
lakamsani pushed a commit to lakamsani/NemoClaw that referenced this pull request Apr 4, 2026
<!-- markdownlint-disable MD041 -->
## Summary
<!-- 1-3 sentences: what this PR does and why. -->

Allow `nemoclaw <sandbox> policy-add` to be selected by number instead
of typing preset names.

```bash
root@se7en:/tmp/NemoClaw# node bin/nemoclaw.js seven-demo policy-add

  Available presets:
    1) ○ discord — Discord API, gateway, and CDN access
    2) ○ docker — Docker Hub and NVIDIA container registry access
    3) ○ huggingface — Hugging Face Hub, LFS, and Inference API access
    4) ○ jira — Jira and Atlassian Cloud access
    5) ● npm — npm and Yarn registry access
    6) ○ outlook — Microsoft Outlook and Graph API access
    7) ○ pypi — Python Package Index (PyPI) access
    8) ○ slack — Slack API, Socket Mode, and webhooks access
    9) ○ telegram — Telegram Bot API access

  ● applied, ○ not applied

  Choose preset [1]: 7
  Apply 'pypi' to sandbox 'seven-demo'? [Y/n]: y
✓ Policy version 3 submitted (hash: 462a3f55b4da)
✓ Policy version 3 loaded (active version: 3)
  Applied preset: pypi
```

## Related Issue
<!-- Link to the issue: Fixes #NNN or Closes #NNN. Remove this section
if none. -->
Fixes NVIDIA#1164

## Changes
<!-- Bullet list of key changes. -->

## Type of Change
<!-- Check the one that applies. -->
- [x] Code change for a new feature, bug fix, or refactor.
- [ ] Code change with doc updates.
- [ ] Doc only. Prose changes without code sample modifications.
- [ ] Doc only. Includes code sample changes.

## Testing
<!-- What testing was done? -->
- [x] `npx prek run --all-files` passes (or equivalently `make check`).
- [x] `npm test` passes.
- [ ] `make docs` builds without warnings. (for doc-only changes)

## Checklist

### General

- [x] I have read and followed the [contributing
guide](https://github.com/NVIDIA/NemoClaw/blob/main/CONTRIBUTING.md).
- [x] I have read and followed the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md).
(for doc-only changes)

### Code Changes
<!-- Skip if this is a doc-only PR. -->
- [x] Formatters applied — `npx prek run --all-files` auto-fixes
formatting (or `make format` for targeted runs).
- [x] Tests added or updated for new or changed behavior.
- [x] No secrets, API keys, or credentials committed.
- [ ] Doc pages updated for any user-facing behavior changes (new
commands, changed defaults, new features, bug fixes that contradict
existing docs).

### Doc Changes
<!-- Skip if this PR has no doc changes. -->
- [ ] Follows the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md).
Try running the `update-docs` agent skill to draft changes while
complying with the style guide. For example, prompt your agent with
"`/update-docs` catch up the docs for the new changes I made in this
PR."
- [ ] New pages include SPDX license header and frontmatter, if creating
a new page.
- [ ] Cross-references and links verified.

---
<!-- DCO sign-off (required by CI). Replace with your real name and
email. -->
Signed-off-by: Seven Cheng <sevenc@nvidia.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Interactive preset selection menu with visual status (● applied, ○ not
applied)
  * Empty input selects the default (first non-applied) when available
* Policy-add CLI now invokes the interactive selector and asks for
confirmation before applying

* **Validation**
* Rejects invalid, non-numeric, out-of-range, or already-applied
selections and prints feedback

* **Tests**
* Expanded tests covering selection behavior, defaulting, rejection
cases, list rendering, and CLI confirmation flow
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement: feature Use this label to identify requests for new capabilities in NemoClaw. NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NemoClaw] policy-add preset list is not selectable using the up/down arrow keys

3 participants