Skip to content

RFD 189: Console Access - Add console command to CLI#349

Draft
nwilkens wants to merge 4 commits intomasterfrom
rfd-0189-console-access
Draft

RFD 189: Console Access - Add console command to CLI#349
nwilkens wants to merge 4 commits intomasterfrom
rfd-0189-console-access

Conversation

@nwilkens
Copy link
Member

@nwilkens nwilkens commented Oct 8, 2025

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 triton inst console

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

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>
@nwilkens nwilkens requested a review from Copilot October 8, 2025 17:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

// Put stdin in raw mode if it's a TTY
if (tty.isatty(process.stdin.fd)) {
stdinWasRaw = process.stdin.isRaw;
stdinOldMode = process.stdin.setRawMode;
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
stdinOldMode = process.stdin.setRawMode;

Copilot uses AI. Check for mistakes.

function cleanup() {
// Restore stdin mode
if (stdinWasRaw !== undefined && process.stdin.setRawMode) {
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 98 to 108
process.on('SIGINT', function () {
console.log('\n[Interrupted]');
cleanup();
callback();
});

process.on('SIGTERM', function () {
console.log('\n[Terminated]');
cleanup();
callback();
});
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@danmcd danmcd requested a review from a team October 8, 2025 18:08
@danmcd
Copy link

danmcd commented Oct 8, 2025

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.

*/

/*
* Copyright 2025 Joyent, Inc.
Copy link

Choose a reason for hiding this comment

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

I think the copyright should be updated.

callback(new errors.UsageError('missing INST arg'));
return;
}

Copy link

@cneira cneira Oct 8, 2025

Choose a reason for hiding this comment

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

Maybe we could add log.trace messages as done here when the function/callbacks are executed to help debug issues if needed.

nwilkens and others added 3 commits October 8, 2025 15:07
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants