Skip to content

refactor(cli): expose explicit main entrypoint - #2901

Merged
cv merged 12 commits into
mainfrom
refactor/oclif-explicit-main-entrypoint
May 4, 2026
Merged

refactor(cli): expose explicit main entrypoint#2901
cv merged 12 commits into
mainfrom
refactor/oclif-explicit-main-entrypoint

Conversation

@cv

@cv cv commented May 3, 2026

Copy link
Copy Markdown
Collaborator

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

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

  • 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

  • Refactor
    • Reorganized internal CLI initialization structure while preserving existing functionality.

@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: 6c480da8-a2b8-4741-9e09-c921944206a1

📥 Commits

Reviewing files that changed from the base of the PR and between ce184db and ff5458a.

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

📝 Walkthrough

Walkthrough

The CLI entry point is refactored by extracting the top-level async IIFE into a named, exported main function that accepts an optional argv parameter. The dispatch logic and exit behavior remain unchanged; backward compatibility is maintained by immediately invoking main() and assigning the result to mainPromise.

Changes

CLI Entry Point Restructuring

Layer / File(s) Summary
Function Extraction
src/nemoclaw.ts (lines 258–260)
async function main(argv: string[] = process.argv.slice(2)) is defined, replacing the top-level IIFE and accepting optional command-line arguments.
Logic Migration
src/nemoclaw.ts (lines 261–366)
Existing dispatch control flow (help handling, global vs. sandbox dispatch, registry recovery, and unknown-command suggestions) moves into main function body; behavior and exit conditions are preserved.
Export Updates
src/nemoclaw.ts (lines 369–372)
exports.main now references the extracted function; exports.mainPromise is set to main() to maintain backward compatibility for test harnesses.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop through the code, so clean and so bright,
The main takes the stage—no more IIFE in sight!
Argv flows in, dispatch flows through,
Same trusty behavior, but refactored anew!
Scripts and tests still dance to the tune, 🎭

🚥 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 and specifically describes the main change: exposing an explicit main entrypoint for the CLI module, which aligns with the PR's primary objective of refactoring the CLI structure.
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-explicit-main-entrypoint

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
Remove the remaining legacy dispatch fallback targets for policy-add,
skill, and snapshot edge paths. These paths now route through hidden/raw
oclif adapters that preserve the existing command-action behavior
without using the legacy dispatch variant.

## Stack Navigation
- Position: 10 of 60
- Previous PR: [#2898 — refactor(cli): remove runtime
bridge](#2898)
- Next PR: [#2901 — refactor(cli): expose explicit main
entrypoint](#2901)

## Changes
- Added raw oclif adapters for policy-add missing-value handling, skill
usage/unknown subcommands, and snapshot usage/unknown subcommands.
- Registered the raw adapters in the oclif command map.
- Removed `LegacyDispatch` and the `legacy` handling branch from
`src/nemoclaw.ts`.
- Added dispatch tests covering the newly routed policy, skill, and
snapshot fallback paths.

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

* **Refactoring**
* Streamlined sandbox command routing so help and unknown subcommands
are forwarded consistently and original arguments are preserved.
* Unified behavior for policy, skill, and snapshot commands to improve
predictability.

* **New Features**
* Sandbox commands now accept raw argument forms and validate missing
sandbox names with clearer exit behavior.

* **Tests**
  * Added coverage for the updated dispatch and routing behaviors.
<!-- 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-remove-legacy-dispatch-fallbacks to main May 4, 2026 21:56
@cv
cv marked this pull request as ready for review May 4, 2026 21:56
Signed-off-by: Carlos Villela <cvillela@nvidia.com>

@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 after rebase. Tiny clean refactor — 1 file / +8 / -5.

  • Top-level argv destructure moves into the new main(argv = process.argv.slice(2)).
  • Anonymous IIFE replaced with the named async function main.
  • exports.mainPromise = main() preserves the load-time side-effect invocation byte-equivalent to the old (async () => {...})().
  • New exports.main enables in-process harnesses to call with explicit argv. Comment correctly directs new callers to main(argv) over the legacy mainPromise.

No argv parsing, exit, or rejection-handling deltas. bin/nemoclaw.js untouched, package.json bin mapping untouched — public CLI surface identical.

CI: pr.yaml fully green; pr-self-hosted build-sandbox-images/arm64 still in flight at review time but no failures. Cumulative ~16-orphan debt in src/nemoclaw.ts unchanged here, still pending the dedicated cleanup PR.

@cv
cv merged commit b8e6fdb into main May 4, 2026
11 of 12 checks passed
cv added a commit that referenced this pull request May 4, 2026
## 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
- Position: 12 of 60
- Previous PR: [#2901 — refactor(cli): expose explicit main
entrypoint](#2901)
- Next PR: [#2905 — refactor(cli): validate logs flags with
oclif](#2905)

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

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
latenighthackathon added a commit to latenighthackathon/NemoClaw that referenced this pull request May 5, 2026
…aging (NVIDIA#1691)

When a sandbox is created without enabling Telegram (or Discord, or
Slack) during `nemoclaw onboard`, applying the matching policy preset
via `nemoclaw <name> policy-add` only opens network egress to the
channel API. The bot token, channel configuration, and in-sandbox
bridge are wired up at onboard time, so users who apply the preset
after onboarding without having enabled the channel can reasonably
believe they have enabled messaging when only the firewall has been
widened.

Add `getMessagingPresetWarning()` in `src/lib/policies.ts` and surface
it in `addSandboxPolicy()` (now in `src/lib/policy-channel-actions.ts`
after the recent CLI dispatch refactor) before the apply confirmation
so users see, for example, that the `telegram` preset alone does not
enable Telegram bots and that re-running `nemoclaw onboard` with
Telegram selected is the path to actually enabling the channel.

This is a rebase of an earlier branch onto current main:

- Hook moved from the legacy `src/nemoclaw.ts` dispatcher to the new
  `src/lib/policy-channel-actions.ts:addSandboxPolicy` after NVIDIA#2899 /
  NVIDIA#2901 / NVIDIA#2907 extracted dispatch.
- `getMessagingPresetWarning` got an explicit TS signature
  (`presetName: string): string | null`) to match the rest of
  `src/lib/policies.ts`.
- Replaced the em dash in the warning message with a period for
  consistency with project style.

Originally three commits (warning logic + ordering assertion + tmpDir
cleanup) on the prior branch; consolidated here because the rebase
needed the dispatcher hook ported to a new file.

Closes NVIDIA#1691

Re-ran `npx vitest run test/policies.test.ts` after rebase: 120/120 pass.

Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
@cv
cv deleted the refactor/oclif-explicit-main-entrypoint 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.

3 participants