Skip to content

feat: embedded interactive terminal (PTY) for kubectl & shell - #12

Merged
bartbeecoders merged 1 commit into
mainfrom
feat/terminal-window
Jun 16, 2026
Merged

feat: embedded interactive terminal (PTY) for kubectl & shell#12
bartbeecoders merged 1 commit into
mainfrom
feat/terminal-window

Conversation

@bartbeecoders

Copy link
Copy Markdown
Owner

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-context pinned to the context the app currently has selected, and points KUBECONFIG at 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 is 0600 and 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-pty spawns $SHELL (unix, -i) / %COMSPEC% (windows) under a PTY.
  • A reader thread streams output bytes to the frontend over a Tauri Channel and reaps the child for its exit code on EOF.
  • Commands: terminal_open / terminal_write / terminal_resize / terminal_close. Sessions live in Backend; Drop kills the shell and removes the temp kubeconfig.
  • OS plumbing only — no Kubernetes client logic, so the kube-core boundary is intact.

Frontend

  • TerminalWindow.tsx (xterm.js + fit addon) owns its PTY lifetime; a ResizeObserver keeps the PTY size in sync with the viewport. api.ts / types.ts mirror the new commands.

Notes

  • New deps: 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.
  • Security: this intentionally allows arbitrary shell execution from the UI (the requested behavior). It runs locally as the same user that launched the app.

Test

  • npm run build
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test -p kubefront-core ✓ (6 passed)
  • Manual: open Terminal → kubectl get ns runs against the active context; resize/drag work; exit closes the shell.

🤖 Generated with Claude Code

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>
@bartbeecoders
bartbeecoders merged commit 886d6c7 into main Jun 16, 2026
3 checks passed
@bartbeecoders
bartbeecoders deleted the feat/terminal-window branch June 16, 2026 04:33
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.

1 participant