RFD 189: Console Access - Add console command to CLI#349
RFD 189: Console Access - Add console command to CLI#349
Conversation
Add `triton instance console` command for terminal-based console access. Changes: - Add lib/do_instance/do_console.js - CLI command implementation - Add getInstanceConsole() to tritonapi.js - Add getMachineConsole() to cloudapi2.js - Register console command in do_instance/index.js Usage: triton instance console <instance-id> triton inst console <instance-id> Features: - Direct terminal integration (raw mode) - Bidirectional byte stream - Ctrl-] to disconnect (same as vmadm console) - Works with all instance types (KVM, Bhyve, Joyent, LX) The command connects stdin/stdout directly to the WebSocket for a native terminal experience. Useful for boot debugging, network troubleshooting, and low-level instance access. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
Adds a new triton instance console command to provide terminal-based console access to instances via WebSocket connections. This enables direct low-level access to instances for debugging and troubleshooting purposes.
- Implements console command with raw terminal mode and bidirectional streaming
- Adds WebSocket-based console connection APIs to both TritonApi and CloudApi layers
- Provides native terminal experience with proper cleanup and signal handling
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/do_instance/do_console.js | New CLI command implementation with terminal handling and WebSocket integration |
| lib/tritonapi.js | Adds getInstanceConsole() method using existing pipeline pattern |
| lib/cloudapi2.js | Adds getMachineConsole() method for WebSocket endpoint connection |
| lib/do_instance/index.js | Registers the new console command in the instance CLI |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
lib/do_instance/do_console.js
Outdated
| // Put stdin in raw mode if it's a TTY | ||
| if (tty.isatty(process.stdin.fd)) { | ||
| stdinWasRaw = process.stdin.isRaw; | ||
| stdinOldMode = process.stdin.setRawMode; |
There was a problem hiding this comment.
This line stores the setRawMode function reference instead of the current raw mode state. This should store the current raw mode boolean value, not the function itself.
| stdinOldMode = process.stdin.setRawMode; |
lib/do_instance/do_console.js
Outdated
|
|
||
| function cleanup() { | ||
| // Restore stdin mode | ||
| if (stdinWasRaw !== undefined && process.stdin.setRawMode) { |
There was a problem hiding this comment.
The condition checks stdinWasRaw !== undefined but stdinWasRaw is initialized to false on line 28, so it will never be undefined. This should check if stdin was actually modified by checking if it's a TTY.
lib/do_instance/do_console.js
Outdated
| process.on('SIGINT', function () { | ||
| console.log('\n[Interrupted]'); | ||
| cleanup(); | ||
| callback(); | ||
| }); | ||
|
|
||
| process.on('SIGTERM', function () { | ||
| console.log('\n[Terminated]'); | ||
| cleanup(); | ||
| callback(); | ||
| }); |
There was a problem hiding this comment.
Signal handlers are added to the global process object but never removed. This could cause issues in applications that use this module multiple times or in testing scenarios. Consider storing handler references and removing them in the cleanup function.
|
1.) Thank you for the draft PR. 2.) Copilot does not count as an official reviewer for our purposes. It'll be interesting to see if its feedback is helpful or distracting. |
lib/do_instance/do_console.js
Outdated
| */ | ||
|
|
||
| /* | ||
| * Copyright 2025 Joyent, Inc. |
There was a problem hiding this comment.
I think the copyright should be updated.
| callback(new errors.UsageError('missing INST arg')); | ||
| return; | ||
| } | ||
|
|
There was a problem hiding this comment.
Maybe we could add log.trace messages as done here when the function/callbacks are executed to help debug issues if needed.
Remove unused stdinOldMode variable that was incorrectly storing the setRawMode function reference instead of the mode state. The cleanup function already correctly uses stdinWasRaw to restore the terminal state. Addresses PR feedback from #349
Change cleanup condition from checking stdinWasRaw !== undefined (which is always true since it's initialized to false) to checking if stdin is actually a TTY. This matches the same check used when setting raw mode and prevents attempting to restore mode on non-TTY stdin. Addresses PR feedback from #349
- Store signal handler references and remove them in cleanup() to prevent memory leaks in repeated usage or testing scenarios - Update copyright to 2026 Edgecast Cloud LLC. Addresses PR review feedback from #349 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add
triton instance consolecommand for terminal-based console access.Changes:
Usage:
triton instance console triton inst console
Features:
The command connects stdin/stdout directly to the WebSocket for a native terminal experience. Useful for boot debugging, network troubleshooting, and low-level instance access.
🤖 Generated with Claude Code