Skip to content

refactor(cli): split share into oclif subcommands - #2911

Merged
cv merged 24 commits into
mainfrom
refactor/oclif-ux-share-subcommands
May 5, 2026
Merged

refactor(cli): split share into oclif subcommands#2911
cv merged 24 commits into
mainfrom
refactor/oclif-ux-share-subcommands

Conversation

@cv

@cv cv commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Split the sandbox share command into explicit oclif subcommands for mount, unmount, and status. This keeps the public nemoclaw <name> share ... syntax stable while moving subcommand routing and unknown-subcommand handling into oclif.

Stack Navigation

Changes

  • Added sandbox:share, sandbox:share:mount, sandbox:share:unmount, and sandbox:share:status command adapters.
  • Moved share mount/unmount/status behavior into exported action helpers reused by the adapters and tests.
  • Updated sandbox dispatch to route share subcommands to explicit oclif command IDs.
  • Added CLI coverage for unknown share subcommands failing before action dispatch.

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

  • New Features

    • Added sandbox-scoped share subcommands: share mount/unmount/status and improved share help/usage.
    • Added -y short flag for --yes across destroy, rebuild, upgrade, and garbage-collection; rebuild docs also show -v/--verbose.
    • Added sandbox:doctor command and added CLI usage examples for several commands.
  • Bug Fixes

    • Improved help/usage and argument validation to surface unexpected arguments earlier.
  • Tests

    • Expanded tests for share help, destroy short-flag usage, and maintenance command help.

@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4a9858eb-e783-4c6b-9424-0792bb70ccfa

📥 Commits

Reviewing files that changed from the base of the PR and between 3cb1dd8 and b492934.

📒 Files selected for processing (2)
  • src/lib/legacy-oclif-dispatch.ts
  • test/cli.test.ts
✅ Files skipped from review due to trivial changes (1)
  • src/lib/legacy-oclif-dispatch.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/cli.test.ts

📝 Walkthrough

Walkthrough

This PR adds short-form flag aliases (-y, -v) and example metadata across multiple CLI commands, refactors the top-level share command into distinct Oclif subcommands (sandbox:share:mount, sandbox:share:unmount, sandbox:share:status) with exported runner functions, and narrows the dispatch type union by removing legacy dispatch mode.

Changes

Flag aliases and CLI metadata

Layer / File(s) Summary
Dispatch Routing & Type System
src/lib/legacy-oclif-dispatch.ts
DispatchResult narrowed: legacy dispatch variant removed; exports limited to Oclif-native dispatch types.
Core Flag Definitions
src/lib/destroy-cli-command.ts, src/lib/rebuild-cli-command.ts, src/lib/maintenance-cli-commands.ts
--yes now documents/accepts -y (char: "y"); rebuild documents `--verbose
Help Text & Registry
src/lib/command-registry.ts, src/lib/legacy-oclif-dispatch.ts
Help/usage strings updated to advertise -y/-v aliases and --force where applicable.
Examples & Metadata
src/lib/rebuild-cli-command.ts, src/lib/maintenance-cli-commands.ts
Added static examples for relevant commands and updated static usage strings.
Tests / Assertions
test/cli.test.ts, src/lib/share-command.test.ts
Updated help assertions to expect short-form flags; adjusted an integration invocation to use -y; tests adapted to import new runner functions for share mount/status.

Share command refactor (independent DAG)

Layer / File(s) Summary
Data Shape / Types
src/lib/share-command.ts
Introduced exported option types: ShareMountOptions, ShareUnmountOptions, ShareStatusOptions.
Core Implementation Extraction
src/lib/share-command.ts
Extracted mount, unmount, status logic into exported runner functions: runShareMount, runShareUnmount, runShareStatus; added printShareUsageAndExit.
Oclif Command Surface
src/lib/share-command.ts
Converted ShareCommand to strict sandbox:share that prints usage and added ShareMountCommand, ShareUnmountCommand, ShareStatusCommand which call the runners.
Command Registration
src/lib/oclif-commands.ts
Registered sandbox:doctor, sandbox:share, sandbox:share:mount, sandbox:share:status, sandbox:share:unmount; removed top-level share entry.
Dispatch Routing
src/lib/legacy-oclif-dispatch.ts
share action now routes `mount
Tests / Test Adapters
src/lib/share-command.test.ts, test/cli.test.ts
Tests updated to call runShareMount / runShareStatus directly; added CLI tests ensuring alpha share bogus fails early and alpha share --help shows public sandbox-scoped usage.

Sequence Diagram

sequenceDiagram
    participant User as User / CLI
    participant Dispatch as Dispatch Layer
    participant Oclif as Oclif Command
    participant Runner as Runner Function
    participant Impl as Implementation

    User->>Dispatch: "alpha share mount <args>"
    Note over Dispatch: resolveSandboxOclifDispatch maps action -> sandbox:share:mount
    Dispatch-->>User: DispatchResult { kind: 'oclif', commandId: 'sandbox:share:mount' }

    User->>Oclif: ShareMountCommand.run()
    Oclif->>Oclif: parse args (name, remotePath, localMount)
    Oclif->>Runner: runShareMount({sandboxName,...})
    Runner->>Impl: ensureLive(sandbox) / get ssh config
    Impl-->>Runner: ssh config
    Runner->>Impl: check sshfs, create temp ssh config, spawn sshfs
    Impl-->>Runner: success / error
    Runner->>Runner: cleanup temp files
    Runner-->>Oclif: exit code / messages
    Oclif-->>User: exit(0) or exit(1)
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🐰
Short flags hop in -y and -v delight,
Share split into paths, each runner takes flight,
Old dispatch trimmed, types now neat,
Tests follow the new, tidy CLI beat.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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 change: refactoring the CLI to split the share command into oclif subcommands, which aligns with the core objective 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-share-subcommands

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
cv requested a review from prekshivyas May 4, 2026 22:42
cv added a commit that referenced this pull request May 5, 2026
## Summary
Add consistent `-y` confirmation aliases and examples across
lifecycle-oriented oclif commands. This keeps confirmation semantics
unchanged while documenting the parser-owned aliases in command help and
root help metadata.

## Stack Navigation
- Position: 18 of 60
- Previous PR: [#2909 — refactor(cli): require skill install path in
oclif](#2909)
- Next PR: [#2911 — refactor(cli): split share into oclif
subcommands](#2911)

## Changes
- Added `-y` aliases for `destroy`, `rebuild`, `upgrade-sandboxes`, and
`gc` confirmation flags.
- Added examples for `destroy` and `rebuild` command metadata.
- Updated public help/registry usage strings for lifecycle commands.
- Exercised `destroy -y` through an existing lifecycle CLI subprocess
test.

## 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>
@cv
cv changed the base branch from refactor/oclif-ux-lifecycle-flags to main May 5, 2026 00:26
@cv
cv marked this pull request as ready for review May 5, 2026 00:26
@cv
cv enabled auto-merge (squash) May 5, 2026 00:26
@cv
cv requested a review from cjagwani May 5, 2026 00:27
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv
cv removed the request for review from prekshivyas May 5, 2026 00:28

@ericksoa ericksoa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed current head 3cb1dd8. Requesting changes for the share help regression introduced by the oclif subcommand split.

alpha share --help is routed through sandbox:share without preserving the help flag (src/lib/legacy-oclif-dispatch.ts:152), so it exits 1 with bare usage instead of normal help. The subcommand help paths also expose internal command IDs; after npm run build:cli, alpha share mount --help exits 0 but prints USAGE $ nemoclaw sandbox:share:mount <name> share mount ..., unlike the adjacent sandbox-scoped commands whose tests assert no sandbox:* internals leak in help output.

Local validation run on this head:

  • npm run build:cli passed.
  • npx vitest run src/lib/share-command.test.ts test/cli.test.ts -t share passed, but it does not cover share --help or share subcommand help output.
  • Manual probes reproduced the regression: alpha share --help exit 1; alpha share mount --help exit 0 with sandbox:share:mount in usage.

I would fix this by keeping share help on the public legacy-dispatch path, the same way other sandbox-scoped help is handled, and adding CLI coverage for alpha share --help plus alpha share mount|unmount|status --help asserting public usage and no sandbox:share* leakage.

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

This comment was marked as outdated.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
src/lib/command-registry.ts (1)

176-192: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Keep the registry in sync with the other new -y aliases.

This file is the help/docs source of truth, but upgrade-sandboxes and gc still advertise the old flag syntax farther down in COMMANDS. After this change, runtime support and canonical usage drift apart again.

Suggested follow-up in this file
   {
     usage: "nemoclaw upgrade-sandboxes",
     description: "Detect and rebuild stale sandboxes",
-    flags: "(--check, --auto)",
+    flags: "(--check, --auto, --yes|-y)",
     group: "Upgrade",
     scope: "global",
   },
@@
   {
     usage: "nemoclaw gc",
     description: "Remove orphaned sandbox Docker images",
-    flags: "(--yes|--force, --dry-run)",
+    flags: "(--yes|-y|--force, --dry-run)",
     group: "Cleanup",
     scope: "global",
   },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/command-registry.ts` around lines 176 - 192, The COMMANDS registry
entries for the "upgrade-sandboxes" and "gc" commands are still using the old
flag syntax; locate the COMMANDS array entries whose usage strings are "nemoclaw
upgrade-sandboxes" and "nemoclaw gc" and update their flags fields to include
the new short alias -y (e.g. change flags to include "[--yes|-y|--force]" or
"[--yes|-y]" as appropriate) so the help/docs match the runtime flag aliases
used elsewhere.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/legacy-oclif-dispatch.ts`:
- Around line 149-154: The branch handling case "share" currently strips a
top-level "--help"/"-h" flag before dispatching to sandbox:share so
ShareCommand.run() never sees the flag; change the logic so when shareSub is
"--help" or "-h" you return a help dispatch instead of removing the flag—e.g.
return { kind: "oclif", commandId: "sandbox:share", args: [sandboxName,
"--help"] } (or "-h"), otherwise keep existing behavior for real subcommands;
update the case "share" block around the shareSub/shareArgs variables so
ShareCommand.run() receives the help flag.

---

Outside diff comments:
In `@src/lib/command-registry.ts`:
- Around line 176-192: The COMMANDS registry entries for the "upgrade-sandboxes"
and "gc" commands are still using the old flag syntax; locate the COMMANDS array
entries whose usage strings are "nemoclaw upgrade-sandboxes" and "nemoclaw gc"
and update their flags fields to include the new short alias -y (e.g. change
flags to include "[--yes|-y|--force]" or "[--yes|-y]" as appropriate) so the
help/docs match the runtime flag aliases used elsewhere.
🪄 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: Enterprise

Run ID: 12254678-1400-43b8-9723-21e875b0149c

📥 Commits

Reviewing files that changed from the base of the PR and between 9b47026 and 3cb1dd8.

📒 Files selected for processing (9)
  • src/lib/command-registry.ts
  • src/lib/destroy-cli-command.ts
  • src/lib/legacy-oclif-dispatch.ts
  • src/lib/maintenance-cli-commands.ts
  • src/lib/oclif-commands.ts
  • src/lib/rebuild-cli-command.ts
  • src/lib/share-command.test.ts
  • src/lib/share-command.ts
  • test/cli.test.ts

Comment thread src/lib/legacy-oclif-dispatch.ts
@cv

cv commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

Correcting my previous comment (shell ate the backticks). Addressed the requested share help regression in b4929340:

  • alpha share --help now stays on the public help path and exits 0 with Usage: nemoclaw <name> share <mount|unmount|status>.
  • alpha share mount|unmount|status --help now also stays on public sandbox-scoped usage and does not expose sandbox:share* command IDs.
  • Added CLI coverage for parent and subcommand share help output.

Validation run locally:

  • npm run build:cli
  • npx vitest run src/lib/share-command.test.ts test/cli.test.ts -t share
  • npm run typecheck:cli

@cv
cv requested a review from ericksoa May 5, 2026 00:40

@ericksoa ericksoa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed current head b492934. The share-help blocker from my prior review is fixed: share --help and share mount|unmount|status --help now route through public sandbox-scoped help instead of leaking sandbox:share* internals, with CLI coverage added.

Local validation on this head:

  • npm run build:cli passed.
  • npx vitest run src/lib/legacy-oclif-dispatch.test.ts src/lib/share-command.test.ts test/cli.test.ts -t "share|maintenance command help" passed.
  • Manual probes for alpha share --help, alpha share mount --help, alpha share unmount --help, and alpha share status --help all exit 0 and print public usage.

CodeRabbit's remaining registry-sync note about root help not advertising the new global -y aliases is valid but non-blocking for this share-command split: command-specific help and runtime parsing are correct.

@cv
cv merged commit 6b97cd0 into main May 5, 2026
15 checks passed
cv added a commit that referenced this pull request May 5, 2026
## Summary
Move `debug` flag parsing into its oclif adapter so unknown flags and
missing flag values fail through the parser before diagnostic
collection. The debug action helpers remain available for existing unit
tests and now also accept already-parsed options.

## Stack Navigation
- Position: 20 of 60
- Previous PR: [#2911 — refactor(cli): split share into oclif
subcommands](#2911)
- Next PR: [#2913 — refactor(cli): model onboard flags with
oclif](#2913)

## Changes
- Modeled `--quick`/`-q`, `--output`/`-o`, and `--sandbox` as oclif
flags.
- Added debug command examples.
- Added `runDebugCommandWithOptions` for adapters that already have
parsed options.
- Updated CLI and unit tests for oclif-owned parse errors and
parsed-option execution.

## 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

* **New Features**
* Added sandbox diagnostics (`doctor` command) to troubleshoot sandbox
and gateway health.
* Enhanced logs command with `--tail`, `--since`, and `--follow`
options.
  * Expanded skill installation workflow for sandbox customization.

* **Improvements**
* Added CLI usage examples and shorthand flags (e.g., `-y`, `-v`) across
commands.
* Improved command validation and error messaging for required
arguments.
  * Enhanced sandbox lifecycle management and recovery workflows.

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

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Co-authored-by: Prekshi Vyas <34834085+prekshivyas@users.noreply.github.com>
@cv
cv deleted the refactor/oclif-ux-share-subcommands branch May 27, 2026 21:18
@wscurran wscurran added the refactor PR restructures code without intended behavior change label Jun 8, 2026
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.

4 participants