Skip to content

refactor(cli): return typed debug parse results - #2920

Merged
cv merged 31 commits into
mainfrom
refactor/oclif-arch-debug-typed-parse
May 5, 2026
Merged

cv merged 31 commits into
mainfrom
refactor/oclif-arch-debug-typed-parse

Conversation

@cv

@cv cv commented May 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Start moving process-exit behavior toward CLI boundaries by adding a typed parse result path for debug arguments. Existing command helpers keep their compatibility wrapper, but callers can now inspect debug parse failures without triggering process.exit().

Stack Navigation

Changes

  • Added DebugParseResult and parseDebugArgsResult.
  • Reworked parseDebugArgs to map typed parse outcomes to output and exit behavior.
  • Added unit coverage for typed debug parse errors.

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 [email protected]

Summary by CodeRabbit

  • Bug Fixes

    • Improved CLI flag validation to catch missing values (e.g., --output without a path now returns proper error message).
    • Enhanced debug command error handling for invalid argument combinations.
  • Tests

    • Expanded test coverage for debug command argument parsing and edge cases.

cv added 29 commits May 2, 2026 13:36
@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: 43d40e49-a632-45cd-abaa-e6d1847f4234

📥 Commits

Reviewing files that changed from the base of the PR and between 38d484e and 96840b1.

📒 Files selected for processing (1)
  • test/cli.test.ts

📝 Walkthrough

Walkthrough

The debug command argument parsing workflow was refactored into distinct layers. A new structured result type separates success/help/error cases, help text generation was centralized, and option handling was decoupled into dedicated functions. Existing entry points now delegate to these new components.

Changes

Debug Command Parsing Refactor

Layer / File(s) Summary
Data Shape
src/lib/debug-command.ts
DebugParseResult type introduced to distinguish { ok: true }, help, and error outcomes with exitCode, kind, and messages.
Help Text Generation
src/lib/debug-command.ts
debugHelpLines() centralizes CLI help strings; printDebugHelp iterates over lines instead of logging fixed blocks.
Core Parsing Logic
src/lib/debug-command.ts
parseDebugArgsResult parses args into structured result, applies default sandboxName from getDefaultSandbox(), and distinguishes help/error cases.
Refactored Entry Points
src/lib/debug-command.ts
parseDebugArgs refactored to call parseDebugArgsResult, print messages to appropriate stream, and exit; runDebugCommandWithOptions clones options, fills defaults, and delegates to deps.runDebug.
Main Wiring
src/lib/debug-command.ts
runDebugCommand updated to use refactored parsing and option-running flow.
Tests & Validation
src/lib/debug-command.test.ts, test/cli.test.ts
New tests verify parseDebugArgsResult returns typed results without side effects, runDebugCommandWithOptions populates defaults, missing arguments are rejected, and oclif validates flag values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A parser's dance, now structured bright,
With results typed—left, help, right!
Options bloom where defaults lay,
Debug commands find their way.
Rabbit grins at clarity gained! 🎩✨

✨ 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-debug-typed-parse

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

@cv

cv commented May 3, 2026

Copy link
Copy Markdown
Collaborator Author

Automated PR review summary

Reviewed PR #2920: refactor(cli): return typed debug parse results

Recommendation

  • Recommendation: PASS
  • Highest observed severity: low
  • Block merge: no
  • Why: The highest-severity downside if merged as-is is low: CLI adapter behavior is now handled by oclif and can differ from the helper wrapper in exit code/message text, so adapter-level regression coverage should be added, but observed behavior is still safe and functional.
  • Reviewer summary: PASS: The typed debug parse result path behaves as claimed in direct runtime probes, compatibility exit semantics remain intact, and nemoclaw debug --quick --sandbox nvf-nemoclaw --output /tmp/pr2920-debug.tgz successfully collected diagnostics from the real ready OpenShell sandbox. No merge-blocking issue was found.

Installation and setup findings

  • NemoClaw installation and mandatory sandbox verification completed successfully. nemoclaw list showed nvf-nemoclaw as the default sandbox, openshell sandbox list showed it Ready, openshell sandbox ssh-config nvf-nemoclaw produced SSH config for openshell-nvf-nemoclaw, and SSH into the sandbox ran printf "2+2=4\n" with output 2+2=4. OpenClaw was present in the sandbox, but the optional model-provider probe timed out with managed inference reporting 503 "inference service unavailable" because no real NVIDIA build key was available; the build key was not exposed.

What was validated

  • The PR revision was checked out in an isolated review environment.
  • The local checkout was installed using the repository installer flow as closely as the environment allowed.
  • Adversarial, PR-specific probes were then run against the installed environment and relevant repository context.
  • Diff summary:
 Dockerfile                                         |   28 -
 Dockerfile.base                                    |   30 -
 docs/get-started/quickstart.md                     |   15 +-
 docs/reference/commands.md                         |   30 +-
 scripts/generate-openclaw-config.py                |   22 +-
 scripts/nemoclaw-start.sh                          |   16 +-
 src/lib/agent-onboard.test.ts                      |   14 +-
 src/lib/agent-onboard.ts                           |   19 +-
 src/lib/channels-mutate-cli-commands.test.ts       |   14 +
 src/lib/channels-mutate-cli-commands.ts            |    6 +-
 src/lib/cli-argv-normalizer.test.ts                |   93 +
 src/lib/cli-argv-normalizer.ts                     |   88 +
 src/lib/command-registry.ts                        |    9 +-
 src/lib/connect-cli-command.ts                     |    4 +
 src/lib/credentials-cli-command.ts                 |    9 +
 src/lib/debug-cli-command.ts                       |   36 +-
 src/lib/debug-command.test.ts                      |   33 +-
 src/lib/debug-command.ts                           |   88 +-
 src/lib/deploy-cli-command.ts                      |    1 +
 src/lib/destroy-cli-command.t
...[truncated]

Failing tests and unresolved impact

  • No failing adversarial tests were captured.

Passing tests and why they mattered

Passing test 1: Typed debug parser returns failures without exiting

  • What was tested: parseDebugArgsResult should make parse errors/help inspectable without invoking process.exit() or sandbox resolution side effects.
  • Why it mattered: If false, non-CLI callers still cannot safely compose debug argument parsing and the refactor fails its main purpose.
  • Observed result: exitCalled=false; missing --output and unknown flag returned {ok:false, exitCode:1, kind:"error"}; --help returned {ok:false, exitCode:0, kind:"help"}.
  • Command: node /tmp/pr2920-typed-parse.js
  • Recommended follow-up coverage: Keep and extend unit coverage to include unknown-option and help typed results plus asserting getDefaultSandbox is not called on parse failures.

Passing test 2: Compatibility wrapper preserves exit behavior and suppresses execution on parse failure

  • What was tested: Existing runDebugCommand/parseDebugArgs compatibility path should still print the typed error, call the injected exit function, and not run diagnostics when parsing fails.
  • Why it mattered: If false, existing callers relying on process-exit semantics could continue after invalid input or run diagnostics with malformed options.
  • Observed result: [["error","Error: --sandbox requires a name argument"],["exit",1],["caught","exit"]]; no runDebug or default-sandbox event was recorded.
  • Command: node /tmp/pr2920-wrapper.js
  • Recommended follow-up coverage: Add a regression unit test for --sandbox missing value asserting error stream, exit code 1, no default lookup, and no runDebug call.

Passing test 3: Installed CLI keeps process-exit boundary for debug parse failures/help

  • What was tested: The installed nemoclaw debug CLI should still terminate at the CLI boundary for malformed args while help exits successfully.
  • Why it mattered: If false, users could see hangs, accidental diagnostics collection, or wrong exit status from CLI-facing parse failures.
  • Observed result: --output exited 2 with stderr Flag --output expects a value; --help exited 0 and printed oclif help. This is CLI-boundary behavior, though text/status come from oclif rather than the helper wrapper.
  • Command: nemoclaw debug --output; nemoclaw debug --help
  • Recommended follow-up coverage: Add an oclif integration test for the installed command adapter so wrapper-level typed parse changes do not silently diverge from CLI behavior expectations.

Passing test 4: Valid debug invocation still collects diagnostics from real OpenShell sandbox

  • What was tested: Refactoring debug argument parsing should not break the real installed debug path against the ready nvf-nemoclaw sandbox.
  • Why it mattered: If false, bug-report diagnostics would regress even though parser unit tests pass.
  • Observed result: status=0; tarball /tmp/pr2920-debug.tgz created (6138 bytes); stdout ended with Tarball written and redaction reminder; stderr empty.
  • Command: timeout 60 nemoclaw debug --quick --sandbox nvf-nemoclaw --output /tmp/pr2920-debug.tgz
  • Recommended follow-up coverage: Add or keep a smoke integration test with mocked OpenShell capture for --quick --sandbox --output; full sandbox e2e can remain a release/manual check.

Bottom line

  • Based on the install evidence and adversarial probes, this PR looks reasonable to approve.

@cv cv added the v0.0.34 label May 4, 2026
@wscurran wscurran added CI/CD refactor PR restructures code without intended behavior change and removed v0.0.34 labels May 4, 2026

@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 and removed v0.0.34 labels May 5, 2026
cv added a commit that referenced this pull request May 5, 2026
## Summary
Make oclif command metadata the enforced source for public command help
basics. This adds a metadata guard and fills the remaining missing
example on the deprecated deploy adapter.

## Stack Navigation
- Position: 26 of 60
- Previous PR: [#2918 — refactor(cli): normalize policy command
ids](#2918)
- Next PR: [#2920 — refactor(cli): return typed debug parse
results](#2920)

## Changes
- Added a command metadata test for registered public oclif commands.
- Required each public command class to provide summary, description,
usage, and examples.
- Added a deploy command example to satisfy the metadata contract.

## 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 <[email protected]>


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

## Summary by CodeRabbit

* **New Features**
* Added sandbox diagnostic command for health checks and troubleshooting
* Enhanced log viewing with tail count, duration filtering, and follow
options
* Improved command structure with new dedicated commands for share,
skill, and snapshot operations

* **Documentation**
* Updated CLI reference with additional flag options across multiple
commands, including shorthand variants (`-y`, `-q`, `-v`) and new
parameters

* **Improvements**
  * Enhanced error handling and validation for CLI arguments
  * Expanded command examples throughout the interface

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

---------

Signed-off-by: Carlos Villela <[email protected]>
@cv
cv marked this pull request as ready for review May 5, 2026 17:58
@cv
cv changed the base branch from refactor/oclif-arch-command-metadata to main May 5, 2026 17:58
@cv
cv enabled auto-merge (squash) May 5, 2026 17:58
@cv
cv merged commit 021a72a into main May 5, 2026
12 checks passed
cv added a commit that referenced this pull request May 5, 2026
## Summary
Introduce explicit public-display-to-oclif command IDs in the command
registry. This prepares root help and docs tooling to combine NemoClaw's
public syntax with oclif command metadata without changing runtime
behavior.

## Stack Navigation
- Position: 28 of 60
- Previous PR: [#2920 — refactor(cli): return typed debug parse
results](#2920)
- Next PR: [#2922 — refactor(cli): use oclif summaries in root
help](#2922)

## Changes
- Added `commandId` to command display metadata entries.
- Mapped every public and hidden display entry to the oclif command that
handles it.
- Added metadata coverage to ensure display entries point at registered
oclif commands.

## 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 <[email protected]>


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

## Summary by CodeRabbit

# Release Notes

* **New Features**
* Added `sandbox doctor` command for sandbox health diagnostics and
troubleshooting
* Added short flags across CLI commands (`-y` for yes, `-q` for quick,
`-o` for output)
* Enhanced `logs` command with `--tail/-n` and `--since` filtering
options
* Restructured `share` functionality into dedicated subcommands
(`mount`, `unmount`, `status`)

* **Documentation**
* Updated command reference with expanded flag support and usage
examples across all subcommands

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

---------

Signed-off-by: Carlos Villela <[email protected]>
@cv
cv deleted the refactor/oclif-arch-debug-typed-parse 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