Skip to main content

Module TerminalProvider

Module TerminalProvider 

Source
Expand description

TerminalProvider: creates and manages integrated terminal instances.

§TerminalProvider (Environment)

Implements the TerminalProvider trait for the MountainEnvironment. Contains the core logic for managing integrated terminal instances, including creating native pseudo-terminals (PTYs) and handling their I/O.

§Terminal architecture

  1. PTY creation - portable-pty opens a native PTY pair.
  2. Process spawning - shell spawned as child of PTY slave.
  3. I/O streaming - dedicated tokio::spawn tasks for input, output, and process exit; each terminal gets its own tasks.
  4. IPC fan-out - PTY output is sent in two directions:
    • Cocoon extension host via $acceptTerminalProcessData (gRPC)
    • Sky webview via SkyEvent::TerminalData (Tauri emit)
  5. State management - ApplicationState.Feature.Terminals.ActiveTerminals keyed by u64 terminal ID.

§Terminal lifecycle

  1. CreateTerminal - create PTY, spawn shell, start I/O tasks, emit TerminalCreate (deferred 120 ms to avoid a race with _ptys.set).
  2. SendTextToTerminal - write user input to PTY via mpsc channel.
  3. ResizeTerminal - call MasterPty::resize via spawn_blocking.
  4. ShowTerminal / HideTerminal - emit UI events to Sky.
  5. GetTerminalProcessId - read OS PID from TerminalStateDTO.
  6. DisposeTerminal - drop Arc<TerminalStateDTO>; PTY close kills shell.

§Shell detection

  • Windows: powershell.exe
  • macOS / Linux: $SHELL, fallback to sh

Custom shell paths can be provided via terminal options.

§Output replay buffer

Each terminal keeps a ring buffer of up to 64 KB of recent PTY output (TERMINAL_OUTPUT_BUFFER). On sky:replay-events the buffered bytes are replayed to Sky, covering the ~1 500 ms gap between shell spawn and SkyBridge listener install during workbench boot.

§VS Code reference

Patterns from VS Code’s integrated terminal:

  • vs/workbench/contrib/terminal/node/terminalProcess.ts
  • vs/platform/terminal/node/ptyService.ts

Constants§

MAX_BUFFERED_BYTES 🔒

Statics§

TERMINAL_OUTPUT_BUFFER 🔒

Functions§

AppendTerminalOutput
DrainTerminalOutputBuffer
RemoveTerminalOutputBuffer
TerminalOutputBuffer 🔒