Skip to content

feat(cli): add --json output for list, status, and policy-list commands#1475

Open
ac12644 wants to merge 2 commits intoNVIDIA:mainfrom
ac12644:feat/json-output
Open

feat(cli): add --json output for list, status, and policy-list commands#1475
ac12644 wants to merge 2 commits intoNVIDIA:mainfrom
ac12644:feat/json-output

Conversation

@ac12644
Copy link
Copy Markdown

@ac12644 ac12644 commented Apr 4, 2026

Summary

Add a --json flag to three CLI commands for machine-readable output, enabling scripting and CI integration.

Command Output
nemoclaw list --json All sandboxes with default flag, model, provider, policies
nemoclaw <name> status --json Sandbox details with NIM health
nemoclaw <name> policy-list --json All presets with applied/unapplied status

JSON mode reads directly from the local registry without requiring a live OpenShell gateway, making it safe for offline scripting.

Example

$ nemoclaw list --json
{
  "sandboxes": [
    {
      "name": "my-assistant",
      "default": true,
      "model": "nvidia/nemotron-3-super-120b-a12b",
      "provider": "nvidia-nim",
      "gpuEnabled": false,
      "policies": ["pypi", "npm"]
    }
  ],
  "defaultSandbox": "my-assistant"
}

$ nemoclaw my-assistant status --json | jq .nim.running
false

Test plan

  • 5 new tests in test/json-output.test.js covering all three commands
  • Full test suite passes (941 tests, 0 failures)
  • Manually verified JSON output with multi-sandbox registry
  • Verified piping works for scripting (nemoclaw list --json | jq ...)
  • Existing human-readable output unchanged when --json is omitted

Fixes #753

Summary by CodeRabbit

  • New Features

    • Added --json flag to list, status, and policy-list commands for machine-readable JSON output, enabling integration with scripts and external tools.
  • Tests

    • Added comprehensive test coverage validating JSON output formatting and structure across all modified commands.

Add a --json flag to three CLI commands for machine-readable output:
- nemoclaw list --json
- nemoclaw <name> status --json
- nemoclaw <name> policy-list --json

JSON mode reads directly from the local registry without requiring a
live OpenShell gateway, making it safe for scripting and CI pipelines.

Fixes NVIDIA#753

Signed-off-by: Abhishek Chauhan <ac12644@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

This PR adds --json output support to three CLI commands (list, status, policy-list) to enable machine-readable structured output for automation and scripting. The human-readable output remains the default. A comprehensive test suite validates JSON output structure and correctness across all three commands.

Changes

Cohort / File(s) Summary
CLI JSON Output Support
bin/nemoclaw.js
Added --json flag handling to listSandboxes, sandboxStatus, and sandboxPolicyList. Each command now checks for the flag and outputs structured JSON (with fields like sandboxes, defaultSandbox, nim, presets, etc.) instead of human-readable text. Updated CLI dispatch and help text to pass args to these functions and document the new flag.
JSON Output Validation Tests
test/json-output.test.js
New test suite validating --json output for list, status, and policy-list commands. Tests verify JSON structure, field presence (e.g., sandboxes array, nim.running boolean, presets array), and that help output documents the flag. Uses isolated temporary directories to avoid filesystem state pollution.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Flags fly with --json so merry and bright,
Machines now can parse what once was just sight,
Structured and stable, a feast for the bots,
One rabbit applauds all these logical thoughts! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% 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 'feat(cli): add --json output for list, status, and policy-list commands' directly and clearly describes the main change: adding JSON output format support to three CLI commands.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #753: adds --json support to nemoclaw list, nemoclaw status, nemoclaw status, and nemoclaw policy-list; includes comprehensive tests validating JSON structure and exit behavior.
Out of Scope Changes check ✅ Passed All changes in bin/nemoclaw.js and test/json-output.test.js are directly scoped to implementing the --json flag feature. No unrelated modifications or scope creep detected in the changeset.

✏️ 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bin/nemoclaw.js (1)

1486-1517: ⚠️ Potential issue | 🟠 Major

Add missing nemoclaw status --json support to match the stated acceptance scope.

The global status command path still ignores flags (showStatus() is called without args), so nemoclaw status --json is not implemented even though it is in the linked objective scope.

Suggested patch
-function showStatus() {
+function showStatus(args = []) {
+  const jsonMode = args.includes("--json");
+
   // Show sandbox registry
   const { sandboxes, defaultSandbox } = registry.listSandboxes();
+  if (jsonMode) {
+    // Keep this schema stable for automation.
+    console.log(
+      JSON.stringify(
+        {
+          sandboxes: sandboxes.map((sb) => ({
+            name: sb.name,
+            default: sb.name === defaultSandbox,
+            model: sb.model || null,
+            provider: sb.provider || null,
+            gpuEnabled: sb.gpuEnabled || false,
+            policies: sb.policies || [],
+            createdAt: sb.createdAt || null,
+          })),
+          defaultSandbox,
+        },
+        null,
+        2,
+      ),
+    );
+    return;
+  }
+
   if (sandboxes.length > 0) {
     const live = parseGatewayInference(
       captureOpenshell(["inference", "get"], { ignoreError: true }).output,
@@
       case "status":
-        showStatus();
+        showStatus(args);
         break;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/nemoclaw.js` around lines 1486 - 1517, The global "status" branch ignores
CLI flags because it calls showStatus() with no arguments; update the switch
case to pass the parsed args (call showStatus(args)) and ensure the showStatus
function signature/handler accepts and respects flags like --json so `nemoclaw
status --json` works; locate the GLOBAL_COMMANDS switch, the cmd variable
handling, and the showStatus function to make the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@bin/nemoclaw.js`:
- Around line 1486-1517: The global "status" branch ignores CLI flags because it
calls showStatus() with no arguments; update the switch case to pass the parsed
args (call showStatus(args)) and ensure the showStatus function
signature/handler accepts and respects flags like --json so `nemoclaw status
--json` works; locate the GLOBAL_COMMANDS switch, the cmd variable handling, and
the showStatus function to make the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ac1b1681-baf8-4170-a683-eb8d18c0ae86

📥 Commits

Reviewing files that changed from the base of the PR and between eaef339 and 7d8f116.

📒 Files selected for processing (2)
  • bin/nemoclaw.js
  • test/json-output.test.js

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.

feat(cli): add --json output for list and status commands

1 participant