refactor(cli): extract onboard command handler#1710
Conversation
📝 WalkthroughWalkthroughCentralizes onboarding CLI parsing/execution into Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/onboard-command.test.ts`:
- Around line 6-10: The test currently imports the compiled artifact from the
dist build; change the import so it loads the source implementation instead
(i.e., import the module that directly exports parseOnboardArgs,
runDeprecatedOnboardAliasCommand, and runOnboardCommand) so tests run against
source code rather than stale/absent build output; update the import statement
to point at the source module that defines those functions and remove the
dependency on the dist artifact.
🪄 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: Pro
Run ID: 5c7640e9-336f-47a0-907c-ca55eeaba667
📒 Files selected for processing (5)
src/lib/onboard-command.test.tssrc/lib/onboard-command.tssrc/nemoclaw.tstest/cli.test.tstest/runner.test.ts
|
I merged the latest Focused validation run:
Both passed. CI is rerunning now. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/onboard-command.ts (1)
82-85: Print onboard usage after unknown--agenterrors for consistency.This branch exits immediately, while other parse failures also print usage; matching behavior would make CLI errors more consistent.
Suggested patch
if (knownAgents.length > 0 && !knownAgents.includes(agentValue)) { error(` Unknown agent '${agentValue}'. Available: ${knownAgents.join(", ")}`); + printOnboardUsage(error, noticeAcceptFlag); exit(1); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/onboard-command.ts` around lines 82 - 85, When the agent argument is unknown (the branch checking knownAgents and agentValue), print the CLI usage/help before exiting to match other parse-failure behavior; modify the branch so it calls the same usage-printing function used elsewhere in this module (e.g., printUsage/showUsage/printOnboardUsage) immediately before invoking exit(1) so the error message plus usage are both shown.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/lib/onboard-command.ts`:
- Around line 82-85: When the agent argument is unknown (the branch checking
knownAgents and agentValue), print the CLI usage/help before exiting to match
other parse-failure behavior; modify the branch so it calls the same
usage-printing function used elsewhere in this module (e.g.,
printUsage/showUsage/printOnboardUsage) immediately before invoking exit(1) so
the error message plus usage are both shown.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2cc78336-f0bc-4d69-822e-77847ff6953e
📒 Files selected for processing (4)
src/lib/onboard-command.test.tssrc/lib/onboard-command.tssrc/nemoclaw.tstest/runner.test.ts
✅ Files skipped from review due to trivial changes (1)
- src/lib/onboard-command.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- test/runner.test.ts
|
I merged the latest Focused validation run:
Both passed. CI is rerunning now. |
🦞 NemoClaw Functional Review — PR #1710Verdict: ✅ APPROVE SummaryClean refactoring — extracts onboard/setup/setup-spark command handling from Functional Testing
Security
ArchitectureChanges are well-scoped to the CLI layer:
The existing NotesNo blocking issues. Straightforward extraction with good test coverage for the new seam. 🦞 Auto-reviewed by Nemo. |
…and-ts-redo # Conflicts: # src/nemoclaw.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/runner.test.ts (1)
479-480: Tighten this regression guard tosetupSpark()specifically.These file-wide
toContain()checks can still pass ifsetupSpark()stops delegating correctly and the same strings remain elsewhere insrc/nemoclaw.ts. Matching thesetupSparkfunction body would keep this guard anchored to the behavior it is supposed to protect.🔍 Suggested tightening
- expect(src).toContain("runDeprecatedOnboardAliasCommand"); - expect(src).toContain('kind: "setup-spark"'); + const setupSparkBlock = src.match( + /async function setupSpark\(args = \[\]\) \{[\s\S]*?runDeprecatedOnboardAliasCommand\([\s\S]*?kind: "setup-spark"[\s\S]*?\n\}/, + ); + expect(setupSparkBlock).toBeTruthy();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/runner.test.ts` around lines 479 - 480, Tighten the regression guard by asserting the actual setupSpark function body is present rather than searching the whole file: locate the setupSpark function definition in src/nemoclaw.ts and change the two loose expect(src).toContain(...) checks to assert that the substring or regex matching the entire setupSpark(...) function (including occurrences of runDeprecatedOnboardAliasCommand and the literal kind: "setup-spark") exists in src; e.g., match the function declaration and its closing brace so the test fails if setupSpark stops delegating or its body changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/runner.test.ts`:
- Around line 479-480: Tighten the regression guard by asserting the actual
setupSpark function body is present rather than searching the whole file: locate
the setupSpark function definition in src/nemoclaw.ts and change the two loose
expect(src).toContain(...) checks to assert that the substring or regex matching
the entire setupSpark(...) function (including occurrences of
runDeprecatedOnboardAliasCommand and the literal kind: "setup-spark") exists in
src; e.g., match the function declaration and its closing brace so the test
fails if setupSpark stops delegating or its body changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4317859b-b941-4d9e-9489-36442e2999bd
📒 Files selected for processing (2)
src/nemoclaw.tstest/runner.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/onboard-command.ts (1)
62-67: Consider extracting repeated fail-fast handling into a small helper.
error(...) + printOnboardUsage(...) + exit(1)is repeated in multiple branches; a local helper would reduce duplication and simplify future edits.♻️ Optional refactor sketch
+ const fail = (message: string): never => { + error(message); + printOnboardUsage(error, noticeAcceptFlag); + exit(1); + }; + if (fromIdx !== -1) { fromDockerfile = parsedArgs[fromIdx + 1] || null; if (!fromDockerfile || fromDockerfile.startsWith("--")) { - error(" --from requires a path to a Dockerfile"); - printOnboardUsage(error, noticeAcceptFlag); - exit(1); + fail(" --from requires a path to a Dockerfile"); }Also applies to: 76-79, 83-85, 94-96
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/onboard-command.ts` around lines 62 - 67, Several branches in onboard-command.ts repeat the pattern error(...); printOnboardUsage(error, noticeAcceptFlag); exit(1); — extract a small helper (e.g., failWithUsage or handleBadArg) that accepts the error message (and captures noticeAcceptFlag via closure or as a parameter), calls error(msg), printOnboardUsage(error, noticeAcceptFlag), then exit(1); replace repeated blocks around fromDockerfile, parsedArgs checks and the other similar branches (the ones that currently call error + printOnboardUsage + exit) to call this helper instead, keeping existing symbols like fromDockerfile, parsedArgs, error, printOnboardUsage, noticeAcceptFlag and exit unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/lib/onboard-command.ts`:
- Around line 62-67: Several branches in onboard-command.ts repeat the pattern
error(...); printOnboardUsage(error, noticeAcceptFlag); exit(1); — extract a
small helper (e.g., failWithUsage or handleBadArg) that accepts the error
message (and captures noticeAcceptFlag via closure or as a parameter), calls
error(msg), printOnboardUsage(error, noticeAcceptFlag), then exit(1); replace
repeated blocks around fromDockerfile, parsedArgs checks and the other similar
branches (the ones that currently call error + printOnboardUsage + exit) to call
this helper instead, keeping existing symbols like fromDockerfile, parsedArgs,
error, printOnboardUsage, noticeAcceptFlag and exit unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7e1ff890-7ca8-41f9-a0d2-ede57c4f8156
📒 Files selected for processing (2)
src/lib/onboard-command.test.tssrc/lib/onboard-command.ts
✅ Files skipped from review due to trivial changes (1)
- src/lib/onboard-command.test.ts
Main underwent a large-scale refactoring while this PR was open: - JS→TS migration: bin/lib/onboard.js → src/lib/onboard.ts, bin/nemoclaw.js → src/nemoclaw.ts (NVIDIA#1673) - Legacy shim removal: 18 bin/lib/*.js files deleted (NVIDIA#1713) - Command handler extraction: src/lib/onboard-command.ts (NVIDIA#1710) - Test renames: .js → .ts across all test files Conflict resolution: - bin/nemoclaw.js: accept main's 6-line launcher (logic in src/nemoclaw.ts) - src/lib/onboard.ts: take main's build context staging (fromDockerfile + agent + stageOptimized), keep Jetson gateway patch functions - docs/get-started/quickstart.md: use main's table format, add Jetson row - test/onboard.test.js: accept deletion (migrated to .ts) Re-ported Jetson features onto new TS structure: - Add setup-jetson to GLOBAL_COMMANDS, help text, and switch dispatch in src/nemoclaw.ts (not a deprecated alias — runs setup-jetson.sh) - Add Jetson to ci/platform-matrix.json (source of truth for docs table) - Add getGatewayImageTag and patchGatewayImageForJetson to exports in src/lib/onboard.ts - Port 4 Jetson tests to test/onboard.test.ts (dist/lib/onboard paths) Verified on Jetson Orin Nano Super (8GB, JetPack 6.x, Node 22.22.0): - Build: tsc passes - 4 Jetson tests: all pass - GPU: jetson=true, 7619 MB unified memory - Gateway: iptables v1.8.10 (legacy), io.nemoclaw.jetson-patched=true - Sandbox: Phase Ready - Inference: openclaw agent → "2 + 2 = 4." - Path: sandbox → host.openshell.internal:11434 → Ollama → nemotron-3-nano:4b Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Main underwent a large-scale refactoring while this PR was open: - JS→TS migration: bin/lib/onboard.js → src/lib/onboard.ts, bin/nemoclaw.js → src/nemoclaw.ts (NVIDIA#1673) - Legacy shim removal: 18 bin/lib/*.js files deleted (NVIDIA#1713) - Command handler extraction: src/lib/onboard-command.ts (NVIDIA#1710) - Test renames: .js → .ts across all test files Conflict resolution: - bin/nemoclaw.js: accept main's 6-line launcher (logic in src/nemoclaw.ts) - src/lib/onboard.ts: take main's build context staging (fromDockerfile + agent + stageOptimized), keep Jetson gateway patch functions - docs/get-started/quickstart.md: use main's table format, add Jetson row - test/onboard.test.js: accept deletion (migrated to .ts) Re-ported Jetson features onto new TS structure: - Add setup-jetson to GLOBAL_COMMANDS, help text, and switch dispatch in src/nemoclaw.ts (not a deprecated alias — runs setup-jetson.sh) - Add Jetson to ci/platform-matrix.json (source of truth for docs table) - Add getGatewayImageTag and patchGatewayImageForJetson to exports in src/lib/onboard.ts - Port 4 Jetson tests to test/onboard.test.ts (dist/lib/onboard paths) Verified on Jetson Orin Nano Super (8GB, JetPack 6.x, Node 22.22.0): - Build: tsc passes - 4 Jetson tests: all pass - GPU: jetson=true, 7619 MB unified memory - Gateway: iptables v1.8.10 (legacy), io.nemoclaw.jetson-patched=true - Sandbox: Phase Ready - Inference: openclaw agent → "2 + 2 = 4." - Path: sandbox → host.openshell.internal:11434 → Ollama → nemotron-3-nano:4b Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary Redo the old NVIDIA#1550 slice on top of the post-migration TypeScript CLI by extracting the onboard/setup/setup-spark command handling from `src/nemoclaw.ts` into a dedicated typed helper module. ## Why After the JS→TS migration, the original NVIDIA#1550 branch no longer mapped cleanly onto the codebase. The same refactor still makes sense, but the right source of truth is now `src/nemoclaw.ts`, not `bin/nemoclaw.js`. This PR keeps the scope narrow: - extract the command parsing/deprecation flow - keep the existing `../bin/lib/onboard` implementation untouched - update only the focused CLI/regression tests needed for the new seam ## Changes - add `src/lib/onboard-command.ts` with: - `parseOnboardArgs()` - `runOnboardCommand()` - `runDeprecatedOnboardAliasCommand()` - add `src/lib/onboard-command.test.ts` - reduce `src/nemoclaw.ts` onboard/setup/setup-spark handlers to thin wrappers - add CLI coverage for: - `onboard --help` - `setup --help` - `setup-spark --help` - update the source-level regression guard in `test/runner.test.ts` ## Notes This supersedes the old migration-era attempt in NVIDIA#1550 with a smaller post-migration redo. ## Testing - [x] `npm run build:cli` - [x] `npx vitest run src/lib/onboard-command.test.ts test/cli.test.ts test/runner.test.ts` Signed-off-by: Carlos Villela <cvillela@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Help flag shows usage for onboarding and deprecated aliases; aliases emit deprecation notice and delegate to onboarding. * **Bug Fixes** * Clear error messages and exit code 1 for unknown options, missing paths, and unknown agents; third‑party acknowledgement honored via flag or env, defaults to false. * **Refactor** * Centralized onboarding argument handling for consistent behavior across entry points. * **Tests** * Added comprehensive tests for parsing, help/deprecation output, acknowledgement, errors, and delegation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Redo the old #1550 slice on top of the post-migration TypeScript CLI by extracting the onboard/setup/setup-spark command handling from
src/nemoclaw.tsinto a dedicated typed helper module.Why
After the JS→TS migration, the original #1550 branch no longer mapped cleanly onto the codebase. The same refactor still makes sense, but the right source of truth is now
src/nemoclaw.ts, notbin/nemoclaw.js.This PR keeps the scope narrow:
../bin/lib/onboardimplementation untouchedChanges
src/lib/onboard-command.tswith:parseOnboardArgs()runOnboardCommand()runDeprecatedOnboardAliasCommand()src/lib/onboard-command.test.tssrc/nemoclaw.tsonboard/setup/setup-spark handlers to thin wrappersonboard --helpsetup --helpsetup-spark --helptest/runner.test.tsNotes
This supersedes the old migration-era attempt in #1550 with a smaller post-migration redo.
Testing
npm run build:clinpx vitest run src/lib/onboard-command.test.ts test/cli.test.ts test/runner.test.tsSigned-off-by: Carlos Villela cvillela@nvidia.com
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests