-
Notifications
You must be signed in to change notification settings - Fork 3.1k
refactor(cli): extract credentials and list runtime bits #2840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
116111c
refactor(cli): harden oclif bridge
cv 5e997cb
test(cli): relax uninstall helper timeouts
cv 88cd958
refactor(cli): migrate status and tunnel commands to oclif
cv 3f748d6
refactor(cli): migrate debug uninstall and gateway-token to oclif
cv 0bc877a
refactor(cli): migrate credentials commands to oclif
cv 3fd15fc
refactor(cli): migrate sandbox inspection commands to oclif
cv 81c62bb
refactor(cli): migrate maintenance commands to oclif
cv 7d6a6fb
refactor(cli): migrate sandbox logs command to oclif
cv 3f17a4f
refactor(cli): migrate skill install command to oclif
cv 0fb3c41
refactor(cli): migrate snapshot list and create to oclif
cv d11eeee
refactor(cli): migrate shields commands to oclif
cv 74806ce
refactor(cli): migrate channels mutation commands to oclif
cv e637e84
refactor(cli): migrate policy mutation commands to oclif
cv ee20dfb
refactor(cli): migrate snapshot restore command to oclif
cv 8d3a568
refactor(cli): migrate destroy command to oclif
cv b447f36
refactor(cli): migrate rebuild command to oclif
cv 02431db
refactor(cli): migrate connect command to oclif
cv 37ce2ff
refactor(cli): migrate deploy command to oclif
cv d3e218e
refactor(cli): migrate onboard aliases to oclif
cv df05a3e
refactor(cli): migrate help and version commands to oclif
cv 3edcf2e
refactor(cli): centralize legacy oclif dispatch
cv 47df3b5
refactor(cli): drop trivial oclif wrapper helpers
cv 460173c
refactor(cli): centralize sandbox runtime bridge
cv 31c0195
test(cli): keep dispatch table out of coverage ratchet
cv bad424d
refactor(cli): centralize policy and channels runtime bridge
cv 5214142
refactor(cli): centralize global runtime bridge
cv 5fca48f
refactor(cli): collapse runtime bridge exports
cv 9616295
refactor(cli): introduce sandbox runtime action facade
cv c3a4906
refactor(cli): introduce policy and channels action facade
cv 35288d8
refactor(cli): introduce global command action facade
cv 58e71de
refactor(cli): extract root help action
cv 66a1673
refactor(cli): extract deploy action
cv e60ba8e
refactor(cli): extract onboard actions
cv 7d29288
refactor(cli): extract openshell runtime helpers
cv 81780c5
refactor(cli): extract sandbox logs action
cv 278ecc5
test(cli): keep extracted action facades out of coverage
cv 99f5cff
refactor(cli): extract maintenance actions
cv 56fa588
test(cli): keep maintenance actions out of coverage ratchet
cv 6e30cfc
refactor(cli): extract snapshot actions
cv f5feac4
refactor(cli): extract policy and channels actions
cv ee9c7d2
refactor(cli): extract credentials and list runtime bits
cv 4f677d4
merge(main): resolve credentials list runtime conflicts
cv 1e69962
test(cli): preserve credentials runtime bridge injection
cv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| const { startGatewayForRecovery } = require("./onboard") as { | ||
| startGatewayForRecovery: () => Promise<void>; | ||
| }; | ||
| import { OPENSHELL_OPERATION_TIMEOUT_MS, OPENSHELL_PROBE_TIMEOUT_MS } from "./openshell-timeouts"; | ||
| import { stripAnsi } from "./openshell"; | ||
| import { captureOpenshell, runOpenshell } from "./openshell-runtime"; | ||
|
|
||
| function hasNamedGateway(output = ""): boolean { | ||
| return stripAnsi(output).includes("Gateway: nemoclaw"); | ||
| } | ||
|
|
||
| function getActiveGatewayName(output = ""): string | null { | ||
| const match = stripAnsi(output).match(/^\s*Gateway:\s+(.+?)\s*$/m); | ||
| return match ? match[1].trim() : null; | ||
| } | ||
|
|
||
| export function getNamedGatewayLifecycleState() { | ||
| const status = captureOpenshell(["status"], { timeout: OPENSHELL_PROBE_TIMEOUT_MS }); | ||
| const gatewayInfo = captureOpenshell(["gateway", "info", "-g", "nemoclaw"], { | ||
| timeout: OPENSHELL_PROBE_TIMEOUT_MS, | ||
| }); | ||
| const cleanStatus = stripAnsi(status.output); | ||
| const activeGateway = getActiveGatewayName(status.output); | ||
| const connected = /^\s*Status:\s*Connected\b/im.test(cleanStatus); | ||
| const named = hasNamedGateway(gatewayInfo.output); | ||
| const refusing = /Connection refused|client error \(Connect\)|tcp connect error/i.test( | ||
| cleanStatus, | ||
| ); | ||
| if (connected && activeGateway === "nemoclaw" && named) { | ||
| return { | ||
| state: "healthy_named", | ||
| status: status.output, | ||
| gatewayInfo: gatewayInfo.output, | ||
| activeGateway, | ||
| }; | ||
| } | ||
| if (activeGateway === "nemoclaw" && named && refusing) { | ||
| return { | ||
| state: "named_unreachable", | ||
| status: status.output, | ||
| gatewayInfo: gatewayInfo.output, | ||
| activeGateway, | ||
| }; | ||
| } | ||
| if (activeGateway === "nemoclaw" && named) { | ||
| return { | ||
| state: "named_unhealthy", | ||
| status: status.output, | ||
| gatewayInfo: gatewayInfo.output, | ||
| activeGateway, | ||
| }; | ||
| } | ||
| if (connected) { | ||
| return { | ||
| state: "connected_other", | ||
| status: status.output, | ||
| gatewayInfo: gatewayInfo.output, | ||
| activeGateway, | ||
| }; | ||
| } | ||
| return { | ||
| state: "missing_named", | ||
| status: status.output, | ||
| gatewayInfo: gatewayInfo.output, | ||
| activeGateway, | ||
| }; | ||
| } | ||
|
|
||
| /** Attempt to recover the named NemoClaw gateway after a restart or connectivity loss. */ | ||
| export async function recoverNamedGatewayRuntime() { | ||
| const before = getNamedGatewayLifecycleState(); | ||
| if (before.state === "healthy_named") { | ||
| return { recovered: true, before, after: before, attempted: false }; | ||
| } | ||
|
|
||
| runOpenshell(["gateway", "select", "nemoclaw"], { | ||
| ignoreError: true, | ||
| timeout: OPENSHELL_OPERATION_TIMEOUT_MS, | ||
| }); | ||
| let after = getNamedGatewayLifecycleState(); | ||
| if (after.state === "healthy_named") { | ||
| process.env.OPENSHELL_GATEWAY = "nemoclaw"; | ||
| return { recovered: true, before, after, attempted: true, via: "select" }; | ||
| } | ||
|
|
||
| const shouldStartGateway = [before.state, after.state].some((state) => | ||
| ["missing_named", "named_unhealthy", "named_unreachable", "connected_other"].includes(state), | ||
| ); | ||
|
|
||
| if (shouldStartGateway) { | ||
| try { | ||
| await startGatewayForRecovery(); | ||
| } catch { | ||
| // Fall through to the lifecycle re-check below so we preserve the | ||
| // existing recovery result shape and emit the correct classification. | ||
| } | ||
| runOpenshell(["gateway", "select", "nemoclaw"], { | ||
| ignoreError: true, | ||
| timeout: OPENSHELL_OPERATION_TIMEOUT_MS, | ||
| }); | ||
| after = getNamedGatewayLifecycleState(); | ||
| if (after.state === "healthy_named") { | ||
| process.env.OPENSHELL_GATEWAY = "nemoclaw"; | ||
| return { recovered: true, before, after, attempted: true, via: "start" }; | ||
| } | ||
| } | ||
|
|
||
| return { recovered: false, before, after, attempted: true }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the lifecycle probes non-fatal.
getNamedGatewayLifecycleState()is supposed to classify missing/unhealthy gateway states, but both probes currently use the defaultcaptureOpenshell()behavior. If either command exits non-zero, the CLI can terminate before this function ever returnsmissing_named/named_unreachable, which means the recovery path never gets a chance to run.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents