Skip to content

refactor(cli): add oclif examples for utility commands - #2902

Merged
cv merged 13 commits into
mainfrom
refactor/oclif-ux-global-utility-commands
May 4, 2026
Merged

refactor(cli): add oclif examples for utility commands#2902
cv merged 13 commits into
mainfrom
refactor/oclif-ux-global-utility-commands

Conversation

@cv

@cv cv commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add oclif examples to low-risk global and utility commands so generated help has concrete usage snippets. This starts the oclif UX pass without changing command behavior.

Stack Navigation

Changes

  • Added examples for list, global status, gateway-token, credentials, credentials list, and credentials reset.
  • Added examples for backup-all, upgrade-sandboxes, and gc.
  • Added examples for uninstall, tunnel start, tunnel stop, and deprecated start/stop aliases.
  • Added a help flag declaration to the uninstall oclif adapter to align its metadata with other utility commands.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Verification

  • npx prek run --all-files passes
  • npm test passes
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes
  • make docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Carlos Villela cvillela@nvidia.com

Summary by CodeRabbit

Release Notes

  • New Features

    • Added sandbox doctor command for comprehensive health diagnostics across sandbox infrastructure, gateway, and services
    • Introduced automated sandbox process recovery and health probing capabilities
    • Enhanced sandbox lifecycle management with improved destroy, rebuild, and skill installation workflows
  • Documentation

    • Expanded CLI usage examples across multiple commands for improved discoverability and guidance

@cv cv self-assigned this May 3, 2026
@copy-pr-bot

copy-pr-bot Bot commented May 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR refactors sandbox operation logic from a centralized nemoclaw-runtime-bridge module into dedicated per-action modules, eliminates legacy dispatch routing, and adds CLI command examples. New standalone action files implement sandbox connect, destroy, doctor, gateway state, process recovery, rebuild, skill install, and status workflows. CLI dispatch is simplified by removing the LegacyDispatch type and converting legacy cases to oclif commands. A runtime hook system is introduced to support test injection. Terminal styling utilities are extracted into a new module.

Changes

Sandbox Runtime Actions Extraction

Layer / File(s) Summary
Utility Modules
src/lib/terminal-style.ts
New ANSI terminal color constants (G, B, D, R, RD, YW) with TTY/NO_COLOR detection and conditional output control.
Data & State Management
src/lib/sandbox-gateway-state-action.ts
Defines SandboxGatewayState type and reconciliation logic for querying/validating sandbox presence in live gateway, handling ambiguous gateway states, and enforcing sandbox readiness with guidance output.
Core Sandbox Operations
src/lib/sandbox-connect-action.ts, src/lib/sandbox-destroy-action.ts, src/lib/sandbox-rebuild-action.ts, src/lib/sandbox-skill-install-action.ts, src/lib/sandbox-status-action.ts, src/lib/sandbox-doctor-action.ts, src/lib/upgrade-sandboxes-action.ts
Extracted sandbox action implementations: connect (with probing/readiness wait), destroy (with cleanup/registry removal), rebuild (with backup/restore flow), skill install (with file validation), status (with health check/reconciliation), doctor (with health check suite), and upgrade-sandboxes (with version checking/batch rebuild).
Process Health & Recovery
src/lib/sandbox-process-recovery-action.ts
Implements sandbox process probing and automated recovery via SSH/exec, gateway health detection, and polling utilities for recovery verification.
Legacy Bridge Removal & Delegation
src/lib/nemoclaw-runtime-bridge.ts, src/lib/sandbox-runtime-actions.ts, src/lib/global-cli-actions.ts
Deletes nemoclaw-runtime-bridge.ts; updates sandbox-runtime-actions.ts to dynamically require dedicated action modules instead of bridge; adds runtime hook injection in global-cli-actions.ts for test support.
Test Integration
test/credentials-cli-command.test.ts, test/image-cleanup.test.ts
Updates test harness to use setGlobalCliActionRuntimeHooksForTest() for runtime injection; refactors image cleanup tests to directly import and test sandbox-destroy-action helpers instead of regex-parsing source.

CLI Routing & Command Updates

Layer / File(s) Summary
Dispatch Type Cleanup
src/lib/legacy-oclif-dispatch.ts, src/lib/legacy-oclif-dispatch.test.ts
Removes LegacyDispatch type; converts sandbox doctor, policy-add (raw mode), skill, and snapshot routing from legacy dispatch to oclif command dispatch; adds test coverage for new routes.
Command Registry & Wiring
src/lib/oclif-commands.ts, src/lib/policy-mutate-cli-commands.ts, src/lib/skill-install-cli-command.ts, src/lib/snapshot-cli-commands.ts, src/lib/sandbox-doctor-cli-command.ts
Registers new CLI commands: sandbox:doctor, sandbox:policy-add:raw (hidden, non-strict), sandbox:skill (base), and sandbox:snapshot; updates import/export wiring to include new command classes.
Dependency Refactoring
src/lib/share-command-deps.ts
Removes internal runtime bridge abstraction; directly requires captureOpenshell and ensureLiveSandboxOrExit modules with local type casts; preserves public ShareCommandDeps interface.

CLI Examples & Metadata

Layer / File(s) Summary
Command Examples
src/lib/credentials-cli-command.ts, src/lib/gateway-token-cli-command.ts, src/lib/list-command.ts, src/lib/maintenance-cli-commands.ts, src/lib/status-command.ts, src/lib/tunnel-commands.ts, src/lib/uninstall-cli-command.ts
Adds static examples property to 13 CLI command classes with example invocation strings using <%= config.bin %> template.
Documentation Reference Update
src/lib/skill-install.ts
Updates JSDoc reference from nemoclaw.ts to sandbox-process-recovery-action.ts for command execution helper.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant CLI as CLI Handler
    participant State as Gateway State
    participant Recovery as Process Recovery
    participant OpenShell as OpenShell Runtime

    User->>CLI: sandbox destroy <name>
    CLI->>State: ensureLiveSandboxOrExit(name)
    State->>OpenShell: sandbox list
    OpenShell-->>State: live sandbox data
    State-->>CLI: { present: true }
    
    CLI->>Recovery: checkAndRecoverSandboxProcesses(name)
    Recovery->>OpenShell: health probe
    OpenShell-->>Recovery: RUNNING
    Recovery-->>CLI: { checked, wasRunning, recovered }
    
    CLI->>OpenShell: sandbox delete <name>
    OpenShell-->>CLI: delete result
    CLI->>CLI: getSandboxDeleteOutcome(result)
    CLI->>CLI: removeSandboxRegistryEntry(name)
    CLI-->>User: ✓ Sandbox destroyed
Loading
sequenceDiagram
    actor User
    participant CLI as Rebuild CLI
    participant Backup as Backup System
    participant OpenShell as OpenShell Runtime
    participant Onboard as Onboard Engine

    User->>CLI: sandbox rebuild <name>
    CLI->>CLI: Load registry entry
    CLI->>CLI: Confirm with user
    
    CLI->>Backup: backupSandboxState(name)
    Backup-->>CLI: backup manifest
    
    CLI->>OpenShell: sandbox delete <name>
    OpenShell-->>CLI: delete result
    
    CLI->>Onboard: onboard({ resume: true, recreateSandbox: true })
    Onboard->>OpenShell: create sandbox
    OpenShell-->>Onboard: sandbox ready
    Onboard-->>CLI: recreation complete
    
    CLI->>Backup: restoreSandboxState(name, manifest)
    Backup-->>CLI: restore complete
    CLI->>CLI: applyPreset(...) for each policy
    CLI-->>User: ✓ Rebuild complete
Loading
sequenceDiagram
    participant Test as Test Suite
    participant Cache as require.cache
    participant GlobalActions as global-cli-actions
    participant Runtime as Mock Runtime

    Test->>Test: Create mock runtime
    Test->>GlobalActions: require(GLOBAL_ACTIONS_PATH)
    Test->>GlobalActions: setGlobalCliActionRuntimeHooksForTest(mockRuntime)
    GlobalActions->>GlobalActions: Store runtime in module state
    
    Test->>GlobalActions: recoverNamedGatewayRuntime()
    GlobalActions->>GlobalActions: Check if hook present
    GlobalActions->>Runtime: Use injected hook
    Runtime-->>GlobalActions: result
    GlobalActions-->>Test: return result
    
    Test->>Cache: delete require.cache[GLOBAL_ACTIONS_PATH]
    Cache-->>Test: cache cleared
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 Hop, hop, the bridge comes down,
Actions stand alone in town!
Doctor probes, connects with care,
Rebuild dreams float in the air!
Sandbox flows refactored bright,
Legacy dispatch takes flight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% 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 summarizes the main change: adding oclif examples to utility commands. It is concise, specific, and accurately reflects the primary purpose of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/oclif-ux-global-utility-commands
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch refactor/oclif-ux-global-utility-commands

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

@cv cv added the v0.0.34 label May 4, 2026
cv added a commit that referenced this pull request May 4, 2026
## Summary
Introduce an explicit `main(argv)` entrypoint for the CLI module. The
existing `mainPromise` export remains as a thin compatibility shim for
in-process test harnesses that still require and await the CLI module.

## Stack Navigation
- Position: 11 of 60
- Previous PR: [#2899 — refactor(cli): remove legacy dispatch
fallbacks](#2899)
- Next PR: [#2902 — refactor(cli): add oclif examples for utility
commands](#2902)

## Changes
- Moved top-level argv parsing into `main(argv =
process.argv.slice(2))`.
- Exported `main` for new in-process harnesses and future launcher
cleanup.
- Kept `mainPromise = main()` compatibility with a comment directing new
callers to `main(argv)`.

## Type of Change
- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification
- [x] `npx prek run --all-files` passes
- [x] `npm test` passes
- [ ] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [ ] Docs updated for user-facing behavior changes
- [ ] `make docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
Signed-off-by: Carlos Villela <cvillela@nvidia.com>


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

## Summary by CodeRabbit

## Release Notes

* **New Features**
* Added `sandbox doctor` command for comprehensive health diagnostics
across CLI, Docker, gateway, inference, and messaging systems.
* Introduced enhanced sandbox management workflows including connection,
destruction, and rebuild operations.
* Added `sandbox upgrade` to automatically rebuild sandboxes with
outdated agent versions.
* Improved sandbox status reporting with live gateway state and
inference health visibility.
* Added sandbox skill install functionality for local skill deployment.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv
cv changed the base branch from refactor/oclif-explicit-main-entrypoint to main May 4, 2026 22:06
@cv
cv marked this pull request as ready for review May 4, 2026 22:06
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv
cv enabled auto-merge (squash) May 4, 2026 22:09

@prekshivyas prekshivyas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Pure additive metadata change — static examples arrays added to oclif Command classes for list, status, gateway-token, credentials*, backup-all, upgrade-sandboxes, gc, uninstall, tunnel start/stop, and the deprecated start/stop aliases. No run() body, flag, or arg changes anywhere.

The one slightly-non-cosmetic change — adding Flags.help({ char: "h" }) to UninstallCliCommand — brings its metadata into parity with peer utility commands. Strictly a UX improvement (explicit -h/--help), not a regression.

Public CLI surface unchanged (examples only render in --help output). src/nemoclaw.ts untouched, so the cumulative ~16-orphan debt is unaffected.

CI: pr.yaml mostly green (commit-lint, dco-check, check-hash, legacy-path-guard, changes PASS; macos-e2e and checks still in progress at review time). For an examples-only change with zero behavioral surface, lightweight gates are adequate signal.

@cv
cv merged commit 9513028 into main May 4, 2026
11 checks passed
cv added a commit that referenced this pull request May 4, 2026
## Summary
Move the sandbox logs command's `--tail`, `-n`, `--since`, and
`--follow` option shape into the oclif adapter so invalid flag values
fail before any OpenShell calls. This also carries the log filter
options through the logs action and updates help/registry metadata for
the new flags.

## Stack Navigation
- Position: 13 of 60
- Previous PR: [#2902 — refactor(cli): add oclif examples for utility
commands](#2902)
- Next PR: [#2906 — refactor(cli): improve sandbox diagnostic command
metadata](#2906)

## Changes
- Added `SandboxLogsOptions` and wired `sandbox:logs` to pass structured
log options instead of a bare follow boolean.
- Modeled `--tail`/`-n` with `Flags.integer({ min: 1 })` and kept custom
`--since` duration validation in the oclif command.
- Updated log source argument construction so tail counts flow to both
OpenClaw and OpenShell logs, while `--since` avoids an unfiltered
gateway tail.
- Expanded logs help metadata and root command registry flags.
- Added CLI and command-adapter coverage for tail, since, follow, help,
malformed values, and unknown flags.

## Type of Change
- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification
- [x] `npx prek run --all-files` passes
- [x] `npm test` passes
- [x] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [ ] Docs updated for user-facing behavior changes
- [ ] `make docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
Signed-off-by: Carlos Villela <cvillela@nvidia.com>


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

## Release Notes

* **New Features**
* The `sandbox:logs` command now supports `--tail/-n` flag to display a
specific number of log lines
* Added `--since` flag to filter logs from a specified duration with
validation and helpful error messages
  * Updated command documentation with usage examples
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor PR restructures code without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants