Skip to content

refactor(cli): extract public argv normalizer - #2916

Merged
cv merged 26 commits into
mainfrom
refactor/oclif-arch-normalize-argv
May 5, 2026
Merged

refactor(cli): extract public argv normalizer#2916
cv merged 26 commits into
mainfrom
refactor/oclif-arch-normalize-argv

Conversation

@cv

@cv cv commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Start the post-UX architecture cleanup by extracting public argv normalization out of src/nemoclaw.ts. The top-level entrypoint still owns registry recovery and user-facing routing errors, but command classification now lives in a focused helper with unit coverage.

Stack Navigation

Changes

  • Added src/lib/cli-argv-normalizer.ts for root/global/sandbox argv normalization and typo suggestions.
  • Replaced duplicated command-shape parsing in src/nemoclaw.ts with the normalizer.
  • Added unit coverage for root help, global commands, explicit sandbox actions, implicit connect, and suggestions.

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

  • Tests

    • Added comprehensive test suite for CLI argument normalization and command suggestions
  • Refactor

    • Reorganized CLI argument parsing and command routing
    • Enhanced command suggestions with improved typo detection using similarity matching
    • Improved handling of help requests across root, global commands, and sandbox contexts
    • Streamlined sandbox action dispatching with explicit connect action support

@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

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a44ac2c8-9a0d-48b4-8df9-24adc8a25248

📥 Commits

Reviewing files that changed from the base of the PR and between 3224350 and 4efce12.

📒 Files selected for processing (1)
  • src/nemoclaw.ts

📝 Walkthrough

Walkthrough

A new CLI argv normalizer module is introduced that formalizes the parsing of command-line arguments into a discriminated union type (NormalizedArgv), covering root help, dump commands, global commands, and sandbox actions. The main entry point is refactored to dispatch through this centralizer, and a helper function for command suggestion via edit distance is provided and used in both modules.

Changes

CLI Argument Normalization

Layer / File(s) Summary
Data Shape
src/lib/cli-argv-normalizer.ts (lines 1–25)
Exported discriminated union NormalizedArgv with variants rootHelp, dumpCommands, global, and sandbox. NormalizeArgvOptions provides configuration for global commands and sandbox connect flag detection.
Core Implementation
src/lib/cli-argv-normalizer.ts (lines 26–88)
normalizeArgv parses argv into one of the four normalized kinds; editDistance computes Levenshtein distance; suggestCommand finds the closest non-flag command match.
Tests
src/lib/cli-argv-normalizer.test.ts
Vitest suite verifying normalization of help, dump, global, sandbox, and connect scenarios, plus command suggestion with typo correction and flag-like filtering.
Integration
src/nemoclaw.ts (lines 83–254)
main refactored to call normalizeArgv and dispatch on the result kind; suggestGlobalCommand simplified to delegate to the shared suggestCommand helper.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI Input
    participant NormAr as Argv Normalizer
    participant Main as Main Dispatcher
    participant GCmd as Global Command<br/>Handler
    participant SBx as Sandbox Action<br/>Handler

    CLI->>NormAr: argv: string[]
    activate NormAr
    alt Empty or --help
        NormAr-->>NormAr: { kind: "rootHelp" }
    else --dump-commands
        NormAr-->>NormAr: { kind: "dumpCommands" }
    else Known global command
        NormAr-->>NormAr: { kind: "global", command, args }
    else Sandbox invocation
        NormAr-->>NormAr: { kind: "sandbox",<br/>sandboxName, action,<br/>actionArgs, connectHelpRequested }
    end
    NormAr-->>Main: NormalizedArgv
    deactivate NormAr

    activate Main
    alt kind = "rootHelp" | "dumpCommands"
        Main->>Main: Handle early
    else kind = "global"
        Main->>GCmd: Dispatch command
        activate GCmd
        GCmd-->>Main: Result
        deactivate GCmd
    else kind = "sandbox"
        alt connectHelpRequested
            Main->>Main: Show connect help
        else
            Main->>SBx: Execute action
            activate SBx
            SBx-->>Main: Result
            deactivate SBx
        end
    end
    deactivate Main
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A normalizer hops along the argv trail,
Bundling chaos into kinds both great and small—
Global commands leap, sandbox actions stir,
Help and dumps parse clean, no more a whir,
Edit distances whisper typos' gentle call! ✨

✨ 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-arch-normalize-argv

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 mentioned this pull request May 4, 2026
12 tasks
@cv cv mentioned this pull request May 4, 2026
12 tasks

@cjagwani cjagwani 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.

Approved as part of stack from #2886 (auto-approve: CI green, no scope/behavior flags).

@cv cv added v0.0.35 refactor PR restructures code without intended behavior change and removed v0.0.34 labels May 5, 2026
cv added a commit that referenced this pull request May 5, 2026
## Summary
Sync the CLI command reference with the oclif UX changes in the stacked
parser/help PRs. This updates documented usage for new aliases,
parser-owned flags, and recent command examples.

## Stack Navigation
- Position: 22 of 60
- Previous PR: [#2913 — refactor(cli): model onboard flags with
oclif](#2913)
- Next PR: [#2916 — refactor(cli): extract public argv
normalizer](#2916)

## Changes
- Documented `--resume | --fresh` in onboard usage.
- Added logs `--tail`/`-n` and `--since` usage.
- Updated lifecycle confirmation aliases and debug short flags.
- Updated `gc` and `upgrade-sandboxes` confirmation alias references.

## Type of Change
- [ ] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [x] 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
- [x] Docs updated for user-facing behavior changes
- [ ] `make docs` builds without warnings (doc changes only)
- [x] 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 doctor` command for sandbox and gateway health
diagnostics
* Enhanced `sandbox logs` with `--tail/-n <lines>` and `--since
<duration>` options
  * Added new `sandbox share` subcommands (`mount`, `unmount`, `status`)
* Added short flag aliases: `-y` for `--yes`, `-v` for `--verbose`, `-q`
for `--quick`, `-o` for `--output`
  * Added `--fresh` option to `onboard` command

* **Improvements**
* Made required arguments mandatory (skill path, channel name) with
early validation
  * Enhanced debug command with `-q` and `-o` short aliases
* Added CLI usage examples to multiple commands for better
discoverability

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

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv
cv marked this pull request as ready for review May 5, 2026 17:13
@cv
cv changed the base branch from docs/oclif-ux-command-reference-sync to main May 5, 2026 17:13
@cv
cv enabled auto-merge (squash) May 5, 2026 17:14
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv
cv merged commit ec87e32 into main May 5, 2026
10 of 11 checks passed
cv added a commit that referenced this pull request May 5, 2026
## Summary
Remove the stale legacy naming from the oclif dispatch helper now that
sandbox and global commands route through explicit oclif adapters. This
is a small naming cleanup in the architecture follow-up stack.

## Stack Navigation
- Position: 24 of 60
- Previous PR: [#2916 — refactor(cli): extract public argv
normalizer](#2916)
- Next PR: [#2918 — refactor(cli): normalize policy command
ids](#2918)

## Changes
- Renamed `legacy-oclif-dispatch` to `oclif-dispatch`.
- Updated the CLI entrypoint and dispatch tests to import the renamed
module.
- Kept dispatch behavior unchanged.

## 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 `doctor` command for health diagnostics across Host,
Gateway, Sandbox, Inference, Messaging, and Local services.
* Enhanced logs command with `--tail/-n`, `--since` filtering, and
`--follow` output controls.
  * Onboard now supports `--non-interactive` and `--fresh` flags.
  * Debug command adds `--quick/-q` option.

* **Improvements**
* Channel mutation, destroy, rebuild, and maintenance commands now
support `-y` shorthand flag.
* Share command refactored with dedicated `mount`, `unmount`, `status`
subcommands.
  * Stricter argument validation across CLI commands.
  * Added command usage examples throughout CLI.

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

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv
cv deleted the refactor/oclif-arch-normalize-argv branch May 27, 2026 21:17
@wscurran wscurran added area: cli Command line interface, flags, terminal UX, or output and removed NemoClaw CLI labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli Command line interface, flags, terminal UX, or output refactor PR restructures code without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants