feat: embedded interactive terminal (PTY) for kubectl & shell - #12
Merged
Conversation
Adds a floating, draggable, resizable terminal window (TopBar "⌨ Terminal") that runs a real interactive shell via a cross-platform PTY, rendered with xterm.js. Supports full interactivity (kubectl exec -it, watch, vim, etc.). Backend (src-tauri/terminal.rs): - portable-pty spawns the user's login shell ($SHELL / COMSPEC) under a PTY; a reader thread streams output bytes to the frontend over a Tauri Channel and reaps the child for an exit code on EOF. - terminal_open / _write / _resize / _close commands; sessions live in Backend and tear down (kill + temp-file cleanup) on close. - kubectl scoping: for Direct connections a temporary kubeconfig with current-context pinned to the app's selected context is written and exported as KUBECONFIG, so the shell targets exactly the active cluster (never the file's stale default). Remote connections leave kubectl unconfigured and the banner says so. No kube-client logic added here — OS plumbing only. Frontend: - TerminalWindow (xterm.js + fit addon) manages its own PTY lifetime; Resize observer keeps the PTY size in sync. api.ts/types.ts mirror the new commands. Deps: portable-pty, serde_yaml (Rust); @xterm/xterm, @xterm/addon-fit (JS). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Adds an embedded interactive terminal to the app — a floating, draggable, resizable window opened from the TopBar (⌨ Terminal) that runs a real shell under a cross-platform PTY and is rendered with xterm.js. Because it's a true PTY, interactive commands work:
kubectl exec -it,kubectl get -w,vim,top, etc.Per the chosen design: arbitrary shell (runs your login shell, so kubectl/helm/pipelines all work) + full interactive PTY.
kubectl scoping (the important part)
For Direct (local kubeconfig) connections, the terminal writes a temporary kubeconfig with
current-contextpinned to the context the app currently has selected, and pointsKUBECONFIGat it. This is deliberate: the app's in-memory context can differ from the kubeconfig file's default, and a terminal silently targeting the wrong cluster (e.g. prod) would be dangerous. The temp file is0600and deleted when the terminal closes.For Remote connections there is no local kubeconfig (traffic goes through the backend proxy), so kubectl is left unconfigured and the banner says so.
Backend (
src-tauri/src/terminal.rs)portable-ptyspawns$SHELL(unix,-i) /%COMSPEC%(windows) under a PTY.Channeland reaps the child for its exit code on EOF.terminal_open/terminal_write/terminal_resize/terminal_close. Sessions live inBackend;Dropkills the shell and removes the temp kubeconfig.kube-coreboundary is intact.Frontend
TerminalWindow.tsx(xterm.js + fit addon) owns its PTY lifetime; aResizeObserverkeeps the PTY size in sync with the viewport.api.ts/types.tsmirror the new commands.Notes
portable-pty,serde_yaml(Rust);@xterm/xterm,@xterm/addon-fit(JS). JS bundle grows ~330 kB (xterm) — flagged by Vite's size warning, not an error.Test
npm run build✓cargo fmt --all -- --check✓cargo clippy --workspace --all-targets -- -D warnings✓cargo test -p kubefront-core✓ (6 passed)kubectl get nsruns against the active context; resize/drag work;exitcloses the shell.🤖 Generated with Claude Code