Skip to content

refactor(cli): remove legacy dispatch fallbacks - #2899

Merged
cv merged 12 commits into
mainfrom
refactor/oclif-remove-legacy-dispatch-fallbacks
May 4, 2026
Merged

refactor(cli): remove legacy dispatch fallbacks#2899
cv merged 12 commits into
mainfrom
refactor/oclif-remove-legacy-dispatch-fallbacks

Conversation

@cv

@cv cv commented May 3, 2026

Copy link
Copy Markdown
Collaborator

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

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

  • 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

  • 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.

@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: 9dd0fd03-7755-4cb4-86fe-e94beb6f119c

📥 Commits

Reviewing files that changed from the base of the PR and between 3a3a65d and d3e97f4.

📒 Files selected for processing (3)
  • src/lib/policy-mutate-cli-commands.ts
  • src/lib/skill-install-cli-command.ts
  • src/lib/snapshot-cli-commands.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/snapshot-cli-commands.ts

📝 Walkthrough

Walkthrough

Removed legacy dispatch type/branching and migrated sandbox actions (policy-add, skill, snapshot) to new non-strict oclif command entrypoints; resolver now returns oclif targets and runtime executor no longer handles legacy dispatches. Tests added to assert arg-preserving oclif routing.

Changes

Legacy Dispatch Migration to Oclif Commands

Layer / File(s) Summary
Type & Export Removals
src/lib/legacy-oclif-dispatch.ts
Removed exported LegacyDispatch type and removed it from the DispatchResult union.
Dispatch Resolution
src/lib/legacy-oclif-dispatch.ts
resolveSandboxOclifDispatch now maps policy-add, skill, and unknown snapshot cases to oclif targets (sandbox:policy-add:raw, sandbox:skill, sandbox:snapshot) instead of returning legacy dispatch values.
New Oclif Command Implementations
src/lib/policy-mutate-cli-commands.ts, src/lib/skill-install-cli-command.ts, src/lib/snapshot-cli-commands.ts
Added non-strict, argv-forwarding oclif commands: PolicyAddRawCommand (sandbox:policy-add:raw), SkillCliCommand (sandbox:skill), and SnapshotCommand (sandbox:snapshot). Each validates a non-empty sandbox name and forwards remaining argv to the runtime bridge handlers.
Command Registry Updates
src/lib/oclif-commands.ts
Imported and registered PolicyAddRawCommand and SkillCliCommand in the default oclif command map (retaining sandbox:skill:install).
Runtime Dispatch Handler
src/nemoclaw.ts
Removed the "legacy" branch from runDispatchResult; runtime no longer directly routes legacy action targets.
Tests
src/lib/legacy-oclif-dispatch.test.ts
Added tests asserting: policy-add routes to sandbox:policy-add:raw with preserved args; skill routes help/unknown subcommands to sandbox:skill preserving args; unknown snapshot routes to sandbox:snapshot preserving args.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI
  participant Resolver
  participant OclifCmd as OclifCommand
  participant Runtime as RuntimeBridge

  CLI->>Resolver: parse action (policy-add | skill | snapshot) + argv
  Resolver->>CLI: return oclif dispatch (e.g., sandbox:policy-add:raw)
  CLI->>OclifCmd: invoke command id with raw argv (first = sandboxName, rest = actionArgs)
  OclifCmd->>Runtime: sandboxPolicyAdd / sandboxSkillInstall / sandboxSnapshot(sandboxName, actionArgs)
  Runtime-->>CLI: action result
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped through code, clean and spry,
Old paths trimmed, new routes fly by,
Three little commands now take the lead,
Args preserved, no tangled weed,
A sandbox hummed beneath the sky.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 pull request title 'refactor(cli): remove legacy dispatch fallbacks' accurately summarizes the main change: eliminating legacy dispatch fallback targets and replacing them with hidden oclif adapters.
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-remove-legacy-dispatch-fallbacks

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 now-empty transitional NemoClaw runtime bridge from the oclif
CLI layer. Credentials tests now inject gateway/OpenShell hooks directly
through `global-cli-actions` instead of stubbing `../nemoclaw`.

## Stack Navigation
- Position: 9 of 60
- Previous PR: [#2897 — refactor(cli): extract upgrade sandboxes
action](#2897)
- Next PR: [#2899 — refactor(cli): remove legacy dispatch
fallbacks](#2899)

## Changes
- Deleted `src/lib/nemoclaw-runtime-bridge.ts`.
- Added explicit test/runtime hook injection to
`src/lib/global-cli-actions.ts` for credential command gateway recovery
and provider operations.
- Updated credentials CLI tests to use the explicit global action hooks
instead of stubbing `dist/nemoclaw.js`.
- Verified no `src/lib` code imports or requires `../nemoclaw`.

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

* **Refactor**
* Refactored internal runtime architecture to streamline dependencies
and enhance code modularity.

* **Tests**
* Enhanced test infrastructure with improved runtime mocking mechanism
for better test isolation and control.
<!-- 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-runtime-bridge to main May 4, 2026 21:28
@cv
cv marked this pull request as ready for review May 4, 2026 21:28
Signed-off-by: Carlos Villela <cvillela@nvidia.com>

@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: 3

🤖 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/policy-mutate-cli-commands.ts`:
- Around line 84-87: The run() method currently reads const [sandboxName,
...actionArgs] = this.argv and calls getRuntimeBridge().sandboxPolicyAdd without
validating sandboxName; add a guard at the start of run() that verifies
sandboxName is a non-empty string and, if missing, fails fast with a CLI usage
error (e.g., throw an informative Error or print a usage message and exit)
before calling getRuntimeBridge().sandboxPolicyAdd(sandboxName, actionArgs) so
invalid/empty sandbox names are never dispatched downstream.

In `@src/lib/skill-install-cli-command.ts`:
- Around line 29-32: The run() method extracts sandboxName from this.argv but
doesn't validate it before calling getRuntimeBridge().sandboxSkillInstall, which
can lead to missing-argument errors; update run() (in class/method where run is
declared) to check that sandboxName is present and non-empty, and if not throw
or return a deterministic error (or call this.error/reporting helper) rather
than invoking getRuntimeBridge().sandboxSkillInstall with undefined; ensure the
validation message clearly states the missing sandboxName and include the
original actionArgs only when sandboxName is valid.

In `@src/lib/snapshot-cli-commands.ts`:
- Around line 35-38: The run() method should validate that a sandbox name was
provided before dispatching; check this.argv for a present sandboxName (the
destructured const [sandboxName, ...actionArgs] = this.argv) and if sandboxName
is falsy, emit a usage/error message and stop (throw or return non-zero exit)
instead of calling getRuntimeBridge().sandboxSnapshot(sandboxName, actionArgs);
add this guard at the top of run() so sandboxSnapshot is only invoked with a
valid sandboxName.
🪄 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: 23106aa5-0538-4d0b-ab7a-821078403d76

📥 Commits

Reviewing files that changed from the base of the PR and between f46b99b and 3a3a65d.

📒 Files selected for processing (7)
  • src/lib/legacy-oclif-dispatch.test.ts
  • src/lib/legacy-oclif-dispatch.ts
  • 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/nemoclaw.ts
💤 Files with no reviewable changes (1)
  • src/nemoclaw.ts

Comment thread src/lib/policy-mutate-cli-commands.ts
Comment thread src/lib/skill-install-cli-command.ts
Comment thread src/lib/snapshot-cli-commands.ts
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. Clean removal of the LegacyDispatch fallback path.

  • Three legacy targets (policy-add, skill, snapshot) now route through new oclif command classes (PolicyAddRawCommand hidden, SkillCliCommand, SnapshotCommand). Each wraps getRuntimeBridge().sandbox*() which defaults to the same handler the old legacy path called (verified policy-mutate-cli-commands.ts:13-22 etc.) — same end-target, same args ordering.
  • LegacyDispatch type, the five kind: "legacy" returns, and the case "legacy": branch in runDispatchResult (-38 lines in src/nemoclaw.ts) all removed cleanly.
  • +33 lines of new dispatch tests cover the three new routes.
  • PolicyAddRawCommand is correctly hidden: true (internal fallback). The user-visible SkillCliCommand/SnapshotCommand add proper summary/description/usage — small help-text improvement.
  • CI: pr.yaml fully green; pr-self-hosted build-sandbox-images/arm64 PASS; three e2es (test-e2e-sandbox, test-e2e-gateway-isolation, test-e2e-port-overrides) still pending after the rebase — worth confirming green before merging.

Cumulative ~16 orphan-import debt in src/nemoclaw.ts is unchanged here, still pending the dedicated cleanup PR.

@cv
cv merged commit ce184db into main May 4, 2026
17 checks passed
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>
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-remove-legacy-dispatch-fallbacks 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