feat(policy): allow selecting policy presets by number#1195
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdded an exported interactive CLI chooser Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
bin/lib/policies.jsbin/nemoclaw.jstest/policies.test.js
<!-- 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 -->
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.
<!-- 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 -->
Summary
Allow
nemoclaw <sandbox> policy-addto 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: pypiRelated Issue
Fixes #1164
Changes
Type of Change
Testing
npx prek run --all-filespasses (or equivalentlymake check).npm testpasses.make docsbuilds without warnings. (for doc-only changes)Checklist
General
Code Changes
npx prek run --all-filesauto-fixes formatting (ormake formatfor targeted runs).Doc Changes
update-docsagent skill to draft changes while complying with the style guide. For example, prompt your agent with "/update-docscatch up the docs for the new changes I made in this PR."Signed-off-by: Seven Cheng sevenc@nvidia.com
Summary by CodeRabbit
New Features
Validation
Tests