Singleton that manages all terminal sessions.
Create a new terminal session.
const session = TerminalManager.spawn({
shell: '/bin/zsh', // Shell to use (default: $SHELL or /bin/bash)
cwd: '/path/to/dir', // Working directory
cols: 120, // Terminal width (default: 80)
rows: 40, // Terminal height (default: 24)
env: { FOO: 'bar' }, // Additional environment variables
visible: true, // Open terminal window (requires tmux)
});Get session by ID. Returns undefined if not found.
Get session by ID. Throws if not found.
List all sessions. Returns SessionInfo[].
Destroy a session by ID. Returns boolean.
Destroy all sessions.
Send raw input to terminal.
session.write('ls -la\n');
session.write('\x03'); // Ctrl+CRead output buffer.
const output = session.read();
const lastLines = session.read({ lines: 10 });
const cleared = session.read({ clear: true });Execute command and wait for completion.
const result = await session.runCommand('npm install', {
timeout: 60000,
waitFor: /\$\s*$/, // Custom prompt pattern
});
// result: { output: string, completed: boolean }Wait for pattern in output.
await session.waitFor(/Password:/);
session.write('secret\n');Resize terminal.
Kill the session.
Open terminal window (visible sessions only).
interface SessionInfo {
id: string;
pid: number;
createdAt: Date;
cwd: string;
alive: boolean;
visible?: boolean;
tmuxSession?: string;
attachCommand?: string;
}