Skip to content

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

Open
cr7258 wants to merge 3 commits intoNVIDIA:mainfrom
cr7258:preset-select
Open

feat(policy): allow selecting policy presets by number#1195
cr7258 wants to merge 3 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
    • CLI policy-add flow now uses the interactive selector
  • Validation

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

    • Comprehensive tests for selection behavior and CLI confirmation flow

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb6c8244-a69c-4a85-bd2d-13d380639d67

📥 Commits

Reviewing files that changed from the base of the PR and between d8e8089 and b93e521.

📒 Files selected for processing (1)
  • bin/nemoclaw.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • bin/nemoclaw.js

📝 Walkthrough

Walkthrough

Replaced the CLI's printed preset menu with a new interactive chooser selectFromList (in bin/lib/policies.js) and added tests covering selection, defaults, validation, and CLI integration for policy-add.

Changes

Cohort / File(s) Summary
Interactive Selection Feature
bin/lib/policies.js
Added selectFromList(items, { applied = [] } = {}) using readline to render a numbered list with applied () / not-applied () markers, compute a default (first unapplied), accept trimmed user input, validate numeric index, reject already-applied or out-of-range selections, and return the selected item name or null.
CLI Integration
bin/nemoclaw.js
Updated sandboxPolicyAdd() to call policies.selectFromList(allPresets, { applied }) instead of printing the full presets menu and using askPrompt, preserving the existing confirmation and apply flow.
Tests
test/policies.test.js
Added process-spawned integration tests and helpers exercising selectFromList (numeric selection, empty-input defaulting, rejection cases, list formatting) and CLI-level policy-add flows to verify confirmation-driven application behavior.

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: returns raw input
Policies->>Policies: determine effective selection (defaulting, validate, check applied)
alt valid & not applied
Policies-->>CLI: resolve selected preset name
CLI->>User: ask confirmation, then apply 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 and bullets now appear.
A default hop, a numbered dance,
Choices made with nimble prance.
Hooray—no more static list, just chance! 🥕

🚥 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 accurately describes the main change: adding numeric selection for policy presets, which directly addresses the usability concern in issue #1164.
Linked Issues check ✅ Passed The PR implements numeric index-based preset selection as an alternative to typing preset names, directly addressing issue #1164's request for improved preset selection usability.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing numeric preset selection: the selectFromList helper, CLI integration, and corresponding tests with no extraneous modifications.

✏️ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

2 participants