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
- PTY creation -
portable-ptyopens a native PTY pair. - Process spawning - shell spawned as child of PTY slave.
- I/O streaming - dedicated
tokio::spawntasks for input, output, and process exit; each terminal gets its own tasks. - IPC fan-out - PTY output is sent in two directions:
- Cocoon extension host via
$acceptTerminalProcessData(gRPC) - Sky webview via
SkyEvent::TerminalData(Tauri emit)
- Cocoon extension host via
- State management -
ApplicationState.Feature.Terminals.ActiveTerminalskeyed byu64terminal ID.
§Terminal lifecycle
CreateTerminal- create PTY, spawn shell, start I/O tasks, emitTerminalCreate(deferred 120 ms to avoid a race with_ptys.set).SendTextToTerminal- write user input to PTY via mpsc channel.ResizeTerminal- callMasterPty::resizeviaspawn_blocking.ShowTerminal/HideTerminal- emit UI events to Sky.GetTerminalProcessId- read OS PID fromTerminalStateDTO.DisposeTerminal- dropArc<TerminalStateDTO>; PTY close kills shell.
§Shell detection
- Windows:
powershell.exe - macOS / Linux:
$SHELL, fallback tosh
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.tsvs/platform/terminal/node/ptyService.ts