Tool Name
@agent-tools/pty
Description
Spawn and manage pseudo-terminal (PTY) processes with typed I/O, lifecycle control, and session multiplexing — enabling agents to interact with CLI tools that require a terminal environment.
Why It's Useful for Agents
AI agents frequently need to interact with programs that behave differently (or refuse to run) without a TTY — interactive installers, REPLs, TUI applications, SSH sessions, and CLI tools that gate output behind isatty() checks. Currently agents shell out via child_process which provides no PTY, losing colored output, progress bars, and interactive prompts. node-pty (1.9k stars, MIT, v1.1.0 Dec 2025, ~1.9M weekly npm downloads, powers VS Code/Hyper/Theia) provides the low-level forkpty(3) bindings but lacks session management, output parsing, expect-style pattern matching, and graceful lifecycle control that agents need. This tool wraps node-pty with an agent-friendly API for spawning interactive sessions, waiting for specific output patterns, sending input sequences, and managing multiple concurrent terminal sessions with proper cleanup.
Proposed API
import { spawn, expect, SessionPool } from "@agent-tools/pty";
// Spawn a PTY process
const session = await spawn("bash", {
cols: 120,
rows: 40,
cwd: "/workspace",
env: { TERM: "xterm-256color" },
timeout: 30_000,
});
// Read output as async iterable
for await (const chunk of session) {
console.log(chunk); // typed string output
}
// Expect-style pattern matching (wait for prompt, send input)
await session.expect(/\$\s*$/); // wait for shell prompt
session.write("npm install\n");
const result = await session.expect(/added \d+ packages/);
// Send control sequences
session.sendControl("c"); // Ctrl+C
session.sendControl("d"); // Ctrl+D (EOF)
// Resize terminal
session.resize(200, 50);
// Session pool for concurrent terminal management
const pool = new SessionPool({ maxSessions: 5 });
const s1 = await pool.acquire("bash");
const s2 = await pool.acquire("python3");
await pool.releaseAll(); // graceful SIGHUP + cleanup
// Output capture with ANSI stripping
const raw = await session.capture("ls --color=always");
const clean = raw.stripAnsi(); // plain text without escape codes
// Graceful shutdown
await session.close(); // sends SIGHUP, waits for exit
const code = session.exitCode;
Scope
In scope:
- PTY process spawning with terminal dimensions, env, and cwd
- Async iterable output streaming
- Expect-style pattern matching (regex/string, with timeout)
- Input writing and control sequence helpers (Ctrl+C/D/Z, arrow keys)
- Terminal resize
- ANSI escape code stripping for clean text extraction
- Session pooling with lifecycle management
- Graceful and forced shutdown with exit code capture
- Cross-platform: Linux, macOS, Windows 10+
Out of scope:
Tool Name
@agent-tools/ptyDescription
Spawn and manage pseudo-terminal (PTY) processes with typed I/O, lifecycle control, and session multiplexing — enabling agents to interact with CLI tools that require a terminal environment.
Why It's Useful for Agents
AI agents frequently need to interact with programs that behave differently (or refuse to run) without a TTY — interactive installers, REPLs, TUI applications, SSH sessions, and CLI tools that gate output behind
isatty()checks. Currently agents shell out viachild_processwhich provides no PTY, losing colored output, progress bars, and interactive prompts. node-pty (1.9k stars, MIT, v1.1.0 Dec 2025, ~1.9M weekly npm downloads, powers VS Code/Hyper/Theia) provides the low-levelforkpty(3)bindings but lacks session management, output parsing, expect-style pattern matching, and graceful lifecycle control that agents need. This tool wraps node-pty with an agent-friendly API for spawning interactive sessions, waiting for specific output patterns, sending input sequences, and managing multiple concurrent terminal sessions with proper cleanup.Proposed API
Scope
In scope:
Out of scope:
@agent-tools/ssh[new tool] @agent-tools/ssh — Remote server command execution and file transfer over SSH #76)