feat: add CLI shell and exec commands for pod terminal access#124
Draft
feat: add CLI shell and exec commands for pod terminal access#124
Conversation
Add two new commands under `centml cluster`:
- `shell <id>` -- interactive terminal session (like docker exec -it)
- `exec <id> -- <command>` -- run a command and return output (like ssh host "cmd")
Both connect via WebSocket through the Platform API terminal proxy,
matching the same protocol used by the Web UI TerminalView.
06e9ae1 to
155fdbf
Compare
Replaces str.replace("https://", "wss://") with urllib.parse.urlparse
scheme replacement to avoid CodeQL py/incomplete-url-substring-sanitization.
Replace url.startswith() assertions with urllib.parse.urlparse() checks to satisfy CodeQL py/incomplete-url-substring-sanitization rule. Reformat both shell.py and test_shell.py with black.
0073b53 to
095bd1e
Compare
Add pyte as local terminal emulator (equivalent to xterm.js) to solve cursor positioning and line wrapping issues. Feed WebSocket output through pyte Screen/Stream and render only dirty lines with ANSI escape sequences.
shutil.get_terminal_size() returns (columns, lines), not (rows, cols). The swapped unpacking caused pyte Screen to be created with terminal line count as width, making the display extremely narrow.
…andling Replace regex-based _strip_ansi with pyte single-row screen for marker detection. pyte interprets all VT100/VT220 sequences including OSC and truecolor escapes that the regex could miss.
If two Code signals arrive within 3 seconds, the shell has exited and the reconnect just opened a new session. Exit cleanly instead of looping forever.
Logs to /tmp/centml_shell_debug.log (overridable via CENTML_SHELL_DEBUG_LOG env var). Traces every WS message, stdin event, task lifecycle, reconnect decision, and connection close.
The platform API proxy never forwards ArgoCD Code messages and does not close the WebSocket when the remote shell exits. Replace the Code/reconnect logic with exit echo detection: when the server echoes back "exit\r\n", arm a 2-second idle timeout on ws.recv(). If no more data arrives, the shell has exited -- break out cleanly. Also removes Code handling from _exec_session (markers already work).
…ompt When "exit\r\n" appears at the end of ws data (nothing after it), the shell has exited -- return immediately instead of waiting 2s. When "exit\r\n" is followed by a new prompt (e.g. from echo exit), ignore it and continue the session.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
centml cluster shell <id>for interactive terminal sessions (likedocker exec -it)centml cluster exec <id> -- <command>for running commands and returning output (likessh host "cmd")get_status_v3()to SDK client for pod discoverywebsockets>=13.0dependencyChanges
centml/cli/shell.pytests/test_shell.pycentml/sdk/api.pyget_status_v3()method (+3 lines)centml/cli/main.pyshellandexeccommands (+3 lines)requirements.txtwebsockets>=13.0(+1 line)Test plan
centml cluster exec <id> -- echo helloreturns clean outputcentml cluster exec <id> -- cat /etc/os-releasereturns full file contentcentml cluster exec <id> -- nvidia-smi --query-gpu=name --format=csv,noheaderreturns GPU namecentml cluster exec <id> --shell sh -- echo testrespects shell optioncentml cluster shell <id>rejects non-TTY with clear errorpytest tests/test_shell.py)centml cluster shell <id>interactive mode (manual TTY test)