Skip to content

refactor(cli): split oclif commands by command tree#2970

Merged
cv merged 77 commits intomainfrom
refactor/layer-command-tree
May 6, 2026
Merged

refactor(cli): split oclif commands by command tree#2970
cv merged 77 commits intomainfrom
refactor/layer-command-tree

Conversation

@cv
Copy link
Copy Markdown
Contributor

@cv cv commented May 4, 2026

Summary

Split the oclif command adapter layer out of the flat src/lib/ directory and mirror the command tree under src/lib/commands/**.

Stack Navigation

Changes

  • Moved the explicit oclif registry to src/lib/commands/index.ts and updated the oclif target in package.json.
  • Split registered oclif command classes to one command per production file, grouped by command family and sandbox scope.
  • Moved command adapter tests beside the new command tree and updated imports/mocks.
  • Kept behavior unchanged; command IDs, public syntax, parser flags, and action calls are preserved.

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 --stage pre-push passes
  • npm run clean:cli && npm run build:cli && npm run dist:sourcemaps:check
  • npm run typecheck:cli
  • Command adapter and metadata tests pass
  • 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

  • Refactor
    • Reorganized CLI command modules into a more modular structure with commands grouped by feature and functionality.

cv added 30 commits May 2, 2026 13:36
@cv cv self-assigned this May 4, 2026
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 4, 2026

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
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

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: 629e9ef7-1492-469e-9585-5e855ba54785

📥 Commits

Reviewing files that changed from the base of the PR and between 5b89381 and 231f912.

📒 Files selected for processing (86)
  • package.json
  • src/lib/channels-mutate-cli-commands.ts
  • src/lib/cli/oclif-metadata.ts
  • src/lib/command-display-metadata.test.ts
  • src/lib/commands/credentials.test.ts
  • src/lib/commands/credentials.ts
  • src/lib/commands/credentials/common.ts
  • src/lib/commands/credentials/list.ts
  • src/lib/commands/credentials/reset.ts
  • src/lib/commands/debug.ts
  • src/lib/commands/deploy.ts
  • src/lib/commands/deprecated/start.ts
  • src/lib/commands/deprecated/stop.ts
  • src/lib/commands/gateway-token.ts
  • src/lib/commands/global-oclif-command-adapters.test.ts
  • src/lib/commands/index.ts
  • src/lib/commands/list.ts
  • src/lib/commands/maintenance/backup-all.ts
  • src/lib/commands/maintenance/gc.ts
  • src/lib/commands/maintenance/upgrade-sandboxes.ts
  • src/lib/commands/onboard.test.ts
  • src/lib/commands/onboard.ts
  • src/lib/commands/onboard/common.ts
  • src/lib/commands/root/help.ts
  • src/lib/commands/root/version.ts
  • src/lib/commands/sandbox/channels/add.ts
  • src/lib/commands/sandbox/channels/common.ts
  • src/lib/commands/sandbox/channels/list.ts
  • src/lib/commands/sandbox/channels/mutate.test.ts
  • src/lib/commands/sandbox/channels/remove.ts
  • src/lib/commands/sandbox/channels/start.ts
  • src/lib/commands/sandbox/channels/stop.ts
  • src/lib/commands/sandbox/common.ts
  • src/lib/commands/sandbox/config/get.ts
  • src/lib/commands/sandbox/connect.ts
  • src/lib/commands/sandbox/destroy.ts
  • src/lib/commands/sandbox/doctor.ts
  • src/lib/commands/sandbox/logs.test.ts
  • src/lib/commands/sandbox/logs.ts
  • src/lib/commands/sandbox/oclif-command-adapters.test.ts
  • src/lib/commands/sandbox/policy/add.ts
  • src/lib/commands/sandbox/policy/common.ts
  • src/lib/commands/sandbox/policy/list.ts
  • src/lib/commands/sandbox/policy/mutate.test.ts
  • src/lib/commands/sandbox/policy/remove.ts
  • src/lib/commands/sandbox/rebuild.ts
  • src/lib/commands/sandbox/share.test.ts
  • src/lib/commands/sandbox/share.ts
  • src/lib/commands/sandbox/share/mount.ts
  • src/lib/commands/sandbox/share/status.ts
  • src/lib/commands/sandbox/share/unmount.ts
  • src/lib/commands/sandbox/shields/down.ts
  • src/lib/commands/sandbox/shields/status.ts
  • src/lib/commands/sandbox/shields/up.ts
  • src/lib/commands/sandbox/skill.test.ts
  • src/lib/commands/sandbox/skill.ts
  • src/lib/commands/sandbox/skill/common.ts
  • src/lib/commands/sandbox/skill/install.ts
  • src/lib/commands/sandbox/snapshot.test.ts
  • src/lib/commands/sandbox/snapshot.ts
  • src/lib/commands/sandbox/snapshot/common.ts
  • src/lib/commands/sandbox/snapshot/create.ts
  • src/lib/commands/sandbox/snapshot/list.ts
  • src/lib/commands/sandbox/snapshot/restore.ts
  • src/lib/commands/sandbox/status.ts
  • src/lib/commands/setup-spark.ts
  • src/lib/commands/setup.ts
  • src/lib/commands/simple-global-oclif-adapters.test.ts
  • src/lib/commands/status.ts
  • src/lib/commands/tunnel/common.ts
  • src/lib/commands/tunnel/start.ts
  • src/lib/commands/tunnel/stop.ts
  • src/lib/commands/uninstall.ts
  • src/lib/credentials-cli-command.ts
  • src/lib/maintenance-cli-commands.ts
  • src/lib/oclif-command-metadata.test.ts
  • src/lib/oclif-commands.ts
  • src/lib/policy-mutate-cli-commands.ts
  • src/lib/sandbox-inspection-cli-command.ts
  • src/lib/share-cli-commands.ts
  • src/lib/shields-cli-commands.ts
  • src/lib/skill-install-cli-command.ts
  • src/lib/snapshot-cli-commands.ts
  • src/lib/tunnel-commands.ts
  • test/cli.test.ts
  • test/credentials-cli-command.test.ts

📝 Walkthrough

Walkthrough

This PR restructures the CLI command architecture from consolidated barrel exports to a modular, per-file layout. Commands are migrated from monolithic *-cli-commands.ts modules into individual files under src/lib/commands/, with a new central registry at src/lib/commands/index.ts mapping command identifiers to implementations. The oclif target in package.json is updated to reference the new registry location.

Changes

CLI Command Modularization

Layer / File(s) Summary
Registry Update
package.json, src/lib/cli/oclif-metadata.ts
oclif target path changed from ./dist/lib/oclif-commands.js to ./dist/lib/commands/index.js; module resolution paths updated to load from new ../commands paths.
Core Command Modules Deleted
src/lib/channels-mutate-cli-commands.ts, src/lib/credentials-cli-command.ts, src/lib/maintenance-cli-commands.ts, src/lib/policy-mutate-cli-commands.ts, src/lib/sandbox-inspection-cli-command.ts, src/lib/share-cli-commands.ts, src/lib/shields-cli-commands.ts, src/lib/skill-install-cli-command.ts, src/lib/snapshot-cli-commands.ts, src/lib/tunnel-commands.ts, src/lib/oclif-commands.ts
Consolidated barrel modules removed; commands migrated to per-file structure.
New Credentials Commands
src/lib/commands/credentials.ts, src/lib/commands/credentials/list.ts, src/lib/commands/credentials/reset.ts, src/lib/commands/credentials/common.ts
Credentials management split into separate command files with shared utilities (bridge provider detection, gateway recovery, usage printing).
New Sandbox Channel Commands
src/lib/commands/sandbox/channels/add.ts, src/lib/commands/sandbox/channels/remove.ts, src/lib/commands/sandbox/channels/start.ts, src/lib/commands/sandbox/channels/stop.ts, src/lib/commands/sandbox/channels/list.ts, src/lib/commands/sandbox/channels/common.ts
Channel mutation commands split from consolidated module; runtime bridge and argument builders centralized in common.ts.
New Sandbox Policy Commands
src/lib/commands/sandbox/policy/add.ts, src/lib/commands/sandbox/policy/remove.ts, src/lib/commands/sandbox/policy/list.ts, src/lib/commands/sandbox/policy/common.ts
Policy commands extracted with shared runtime bridge and flag utilities in common.ts.
New Sandbox Share Commands
src/lib/commands/sandbox/share.ts, src/lib/commands/sandbox/share/mount.ts, src/lib/commands/sandbox/share/status.ts, src/lib/commands/sandbox/share/unmount.ts
Share operations split into modular command files.
New Sandbox Shields Commands
src/lib/commands/sandbox/shields/down.ts, src/lib/commands/sandbox/shields/status.ts, src/lib/commands/sandbox/shields/up.ts
Shields management split into per-action command files.
New Sandbox Config & Inspection
src/lib/commands/sandbox/config/get.ts, src/lib/commands/sandbox/status.ts, src/lib/commands/sandbox/snapshot.ts, src/lib/commands/sandbox/snapshot/create.ts, src/lib/commands/sandbox/snapshot/list.ts, src/lib/commands/sandbox/snapshot/restore.ts, src/lib/commands/sandbox/snapshot/common.ts
Config, status, and snapshot commands split into individual files with test helper factories.
New Sandbox Skill Commands
src/lib/commands/sandbox/skill.ts, src/lib/commands/sandbox/skill/install.ts, src/lib/commands/sandbox/skill/common.ts
Skill installation split with runtime bridge abstraction.
New Maintenance Commands
src/lib/commands/maintenance/backup-all.ts, src/lib/commands/maintenance/gc.ts, src/lib/commands/maintenance/upgrade-sandboxes.ts
Backup, garbage collection, and upgrade commands separated.
New Tunnel Commands
src/lib/commands/tunnel/start.ts, src/lib/commands/tunnel/stop.ts, src/lib/commands/tunnel/common.ts
Tunnel operations split with service dependency injection via serviceDeps().
New Root Commands
src/lib/commands/root/help.ts, src/lib/commands/root/version.ts
Help and version commands split.
New Deprecated Aliases
src/lib/commands/deprecated/start.ts, src/lib/commands/deprecated/stop.ts
Deprecated command aliases for start/stop in separate directory.
New Standalone Commands
src/lib/commands/onboard.ts, src/lib/commands/onboard/common.ts, src/lib/commands/setup.ts, src/lib/commands/setup-spark.ts, src/lib/commands/gateway-token.ts, src/lib/commands/deploy.ts, src/lib/commands/debug.ts, src/lib/commands/list.ts, src/lib/commands/status.ts, src/lib/commands/uninstall.ts, src/lib/commands/sandbox/connect.ts, src/lib/commands/sandbox/destroy.ts, src/lib/commands/sandbox/rebuild.ts, src/lib/commands/sandbox/doctor.ts, src/lib/commands/sandbox/logs.ts, src/lib/commands/sandbox/common.ts
Individual command files and helper modules created; imports updated to reference parent directories (../) where applicable.
Central Registry
src/lib/commands/index.ts
New consolidated default export mapping command identifiers (e.g., "credentials", "sandbox:channels:add", "tunnel:start") to their command implementations; replaces the deleted oclif-commands.ts.
Test Updates
src/lib/commands/credentials.test.ts, src/lib/commands/sandbox/channels/mutate.test.ts, src/lib/commands/sandbox/policy/mutate.test.ts, src/lib/commands/sandbox/snapshot.test.ts, src/lib/commands/sandbox/skill.test.ts, src/lib/commands/sandbox/logs.test.ts, src/lib/commands/sandbox/oclif-command-adapters.test.ts, src/lib/commands/global-oclif-command-adapters.test.ts, src/lib/commands/simple-global-oclif-adapters.test.ts, src/lib/command-display-metadata.test.ts, src/lib/oclif-command-metadata.test.ts, test/credentials-cli-command.test.ts, test/cli.test.ts
Test imports updated to reference new per-file modules as default exports; mock paths adjusted to new directory structure; test harness for credentials refactored to load per-module instead of aggregated.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 Whiskers twitching with glee,
Commands now bloom in trees—
Each file its own sweet home,
No barrel buckets to roam!
Modular magic, so fine,
The registry shines! ✨

✨ 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/layer-command-tree

@cv cv added the v0.0.34 Release target label May 4, 2026
@wscurran wscurran added NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI). refactor This is a refactor of the code and/or architecture. v0.0.34 Release target and removed v0.0.34 Release target labels May 4, 2026
@cv cv marked this pull request as ready for review May 4, 2026 19:04
@cv cv changed the base branch from refactor/layer-cli-core-modules to main May 4, 2026 19:04
@cv cv changed the base branch from main to refactor/layer-cli-core-modules May 4, 2026 19:08
@cv cv requested a review from prekshivyas May 5, 2026 00:27
@cv cv added v0.0.35 Release target and removed v0.0.34 Release target labels May 5, 2026
@prekshivyas prekshivyas self-assigned this May 5, 2026
cv added a commit that referenced this pull request May 5, 2026
## Summary
Start the CLI layer directory structure by grouping oclif core/runtime
modules under `src/lib/cli/`. This makes argv normalization, dispatch,
oclif runtime helpers, metadata lookup, public help rendering, and the
shared command base visibly part of the CLI boundary.

## Stack Navigation
- Position: 52 of 60
- Previous PR: [#2966 — refactor(cli): extract policy channel
helpers](#2966)
- Next PR: [#2970 — refactor(cli): split oclif commands by command
tree](#2970)

## Changes
- Moved oclif core modules and their tests into `src/lib/cli/`.
- Updated imports from `src/nemoclaw.ts`, root help, and existing
command adapters.
- Kept command behavior unchanged; this PR is a file-structure/import
move only.

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

* **Refactor**
* Reorganized internal CLI module structure by moving related components
into a dedicated subdirectory for improved code organization and
maintainability. Updated import paths across multiple files to reflect
the new hierarchy. Enhanced command metadata resolution to support
additional packaging layouts. No changes to user-facing functionality or
CLI behavior.

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

---------

Signed-off-by: Carlos Villela <[email protected]>
Co-authored-by: Prekshi Vyas <[email protected]>
@cv cv changed the base branch from refactor/layer-cli-core-modules to main May 5, 2026 23:58
@cv cv enabled auto-merge (squash) May 5, 2026 23:58
Copy link
Copy Markdown
Contributor

@prekshivyas prekshivyas left a comment

Choose a reason for hiding this comment

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

LGTM. Large but mechanical — 86 files / +1687 / -1442.

Eight aggregator files (oclif-commands.ts + 10 *-cli-commands.ts/-cli-command.ts files) deleted; their classes split one-per-file under src/lib/commands/<topic>/<command>.ts mirroring the oclif command tree. New commands/index.ts replaces the aggregator registry. package.json oclif target updated to point at it.

Verified the colon-separated command IDs (e.g. sandbox:policy:add, sandbox:gateway:token) match what the OLD registry already used — not a behavior change. User-facing <name> policy-add hyphenated usage strings preserved.

oclif-metadata.ts tiny path tweak (3+/3-) to find the new registry. Test files moved alongside their sources.

CI: pr.yaml fully green (lint/dco/check-hash/legacy-path-guard/macos-e2e/changes/checks/test-e2e-ollama-proxy PASS); pr-self-hosted builds + wsl-e2e still in flight at review time. Critical signals (typecheck, integration test, adapter+metadata Vitest) all green.

@cv cv merged commit 5ba48f4 into main May 6, 2026
15 of 16 checks passed
cv added a commit that referenced this pull request May 6, 2026
## Summary
Move pure CLI/domain helper modules out of the flat `src/lib/` directory
into `src/lib/domain/**` so parser, action, and domain boundaries are
visible in paths.

## Stack Navigation
- Position: 54 of 60
- Previous PR: [#2970 — refactor(cli): split oclif commands by command
tree](#2970)
- Next PR: [#2985 — refactor(cli): group openshell
adapters](#2985)

## Changes
- Moved lifecycle option normalizers to
`src/lib/domain/lifecycle/options.ts`.
- Moved duration parsing, maintenance image/upgrade helpers, sandbox
destroy/log helpers, sandbox log options, and policy/channel arg helpers
under `src/lib/domain/**`.
- Moved helper tests with their modules and updated imports from
actions, command adapters, and tests.
- Kept behavior unchanged; this PR is a structural move plus import
updates.

## 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 --stage pre-push` passes
- [x] `npm run build:cli`
- [x] `npm run typecheck:cli`
- [x] Domain/helper targeted tests pass
- [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 (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

* **Refactor**
* Internal module structure reorganized to improve code organization and
maintainability.

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

---------

Signed-off-by: Carlos Villela <[email protected]>
Co-authored-by: Prekshi Vyas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI). refactor This is a refactor of the code and/or architecture. v0.0.35 Release target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants