### Install from Repository Head Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Install the latest version directly from the GitHub repository. ```bash cargo install --locked --git https://github.com/anomalyco/terminal-control terminal-control ``` -------------------------------- ### Install Semantic UI Adapter Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Install the required adapter package for OpenTUI applications. ```bash bun add @kitlangton/terminal-control-opentui ``` -------------------------------- ### Install Terminal Control Source: https://github.com/anomalyco/terminal-control/blob/main/docs/typescript-client.md Install the package and Vitest as development dependencies. ```bash bun add -d @kitlangton/terminal-control vitest ``` -------------------------------- ### Agent Task Examples Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Example natural language prompts for agent-driven terminal tasks. ```text Use terminal-control to open my TUI, press through the setup flow, and save a screenshot of the final screen. ``` ```text Record yourself using the terminal app, mark the important moments, and export a short MP4 demo. ``` -------------------------------- ### Launch and inspect the application Source: https://github.com/anomalyco/terminal-control/blob/main/packages/opentui/README.md Commands to start the application with the OpenTUI host profile and display the semantic tree. ```bash termctrl start app --host opentui -- my-tui termctrl show app --format semantic ``` -------------------------------- ### Install Terminal Control via Cargo Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Install the CLI tool using cargo and verify the installation. ```bash cargo install --locked terminal-control termctrl --help ``` -------------------------------- ### Start MCP Server Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Expose terminal sessions as structured MCP tools. ```bash termctrl mcp ``` -------------------------------- ### Start and Show Semantic UI Snapshots Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands to launch an application with semantic UI support and display its snapshot output. ```bash termctrl start demo --host opentui -- my-tui termctrl show demo --format semantic ``` -------------------------------- ### Driver Request Examples Source: https://github.com/anomalyco/terminal-control/blob/main/docs/driver-protocol.md Common request formats for session lifecycle management, input, and state capture. ```json {"type":"hello","protocolVersion":1,"terminalControlVersion":""} {"id":1,"method":"launch","sessionId":"app","params":{"command":["my-terminal-app"],"cols":100,"rows":30,"inheritEnv":false,"env":{"TERM":"xterm-256color"}}} {"id":2,"method":"waitForText","sessionId":"app","params":{"text":"Ready","timeoutMs":5000}} {"id":3,"method":"send","sessionId":"app","params":{"input":[{"type":"text","value":"help"},{"type":"key","value":"enter"}]}} {"id":4,"method":"capture","sessionId":"app","params":{"settleMs":250,"deadlineMs":5000}} ``` -------------------------------- ### Initialize Driver Source: https://github.com/anomalyco/terminal-control/blob/main/docs/driver-protocol.md Command to start the terminal control driver process. ```bash termctrl driver ``` -------------------------------- ### Protocol Response and Error Examples Source: https://github.com/anomalyco/terminal-control/blob/main/docs/driver-protocol.md Examples of JSON Lines responses and error messages returned by the driver. ```json {"type":"response","id":1,"result":{"sessionId":"app"}} {"type":"error","id":2,"error":{"code":"REQUEST_FAILED","message":"session app has exited"}} ``` -------------------------------- ### Install OpenTUI Terminal Control dependencies Source: https://github.com/anomalyco/terminal-control/blob/main/packages/opentui/README.md Use this command to add the necessary packages to your project. ```bash bun add @kitlangton/terminal-control-opentui @opentui/core ``` -------------------------------- ### Manage live terminal sessions Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands for starting, interacting with, and stopping named terminal sessions. ```bash termctrl start demo --host opentui --cols 112 --rows 34 -- my-terminal-app termctrl wait demo "Ready" termctrl send demo text:help enter termctrl show demo termctrl show demo --format semantic termctrl save demo --format png --out captures/help.png termctrl stop demo ``` -------------------------------- ### Record and Export Terminal Sessions Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands to start a recording, mark specific moments, and export the session to an MP4 file. ```bash termctrl start demo --record captures/demo.termctrl --host opentui -- opencode termctrl wait demo "Ask anything" termctrl mark demo before-prompt termctrl send demo --pace-ms 35 'text:Write a terminal haiku. End with DONE.' enter termctrl wait demo "DONE" --timeout 60000 termctrl mark demo after-answer termctrl stop demo termctrl markers captures/demo.termctrl termctrl show --recording captures/demo.termctrl --at-marker after-answer termctrl video captures/demo.termctrl --edit captures/demo.json --footer --out captures/demo.mp4 ``` -------------------------------- ### Manage Embedded Sessions in Rust Source: https://github.com/anomalyco/terminal-control/blob/main/docs/rust-library.md Starts a PTY-backed application session, interacts with it, and captures output. ```rust use std::time::Duration; let mut session = terminal_control::session::Session::start( &["my-terminal-app".to_owned()], None, None, &terminal_control::shot::Options::default(), )?; session.wait_for_text("Ready", Duration::from_secs(5))?; let status = session.status()?; session.send(b"help\r")?; session.wait_for_idle(Duration::from_millis(250), Duration::from_secs(5))?; let capture = session.capture(Duration::from_millis(250), Duration::from_secs(5))?; let shot = capture.shot; let exit = session.wait_for_exit(Duration::from_secs(5))?; session.stop()?; ``` -------------------------------- ### Manage Persistent Terminal Sessions Source: https://github.com/anomalyco/terminal-control/blob/main/skills/terminal-control/SKILL.md Starts a named session, interacts with it, and stops it. Always stop named sessions after use to prevent resource leakage. ```bash termctrl start app -- my-terminal-app termctrl wait app "Ready" termctrl show app termctrl send app text:help enter termctrl wait app "Commands" termctrl show app termctrl stop app ``` -------------------------------- ### Manage OpenTUI Applications Source: https://github.com/anomalyco/terminal-control/blob/main/skills/terminal-control/SKILL.md Initialize applications with specific dimensions using the OpenTUI host handshake. Use resize and restart commands to manage application state. ```bash termctrl start app --host opentui --cols 112 --rows 34 -- opencode termctrl wait app "/connect" termctrl show app ``` -------------------------------- ### Record and Export Terminal Demos Source: https://github.com/anomalyco/terminal-control/blob/main/skills/terminal-control/SKILL.md Capture sessions with markers and export them as videos using an edit plan. Use footer options for branding and timecodes. ```bash termctrl start app --record artifacts/run.termctrl -- my-terminal-app termctrl wait app "Ready" termctrl mark app ready termctrl send app text:demo enter termctrl wait app "Done" --timeout 60000 termctrl mark app done termctrl stop app termctrl markers artifacts/run.termctrl termctrl show --recording artifacts/run.termctrl --at-marker done termctrl video artifacts/run.termctrl --edit artifacts/run-edit.json --footer --out artifacts/run.mp4 ``` -------------------------------- ### Create GitHub Release Source: https://github.com/anomalyco/terminal-control/blob/main/docs/releasing.md Create a tag and GitHub release for the new version. ```bash gh release create vX.Y.Z --target main --generate-notes --title "Terminal Control vX.Y.Z" ``` -------------------------------- ### Launch session and capture snapshots Source: https://github.com/anomalyco/terminal-control/blob/main/packages/test/README.md Launch a TUI application and perform assertions on the screen text. ```ts await using session = await terminal.launch({ command: ["my-tui"] }) await session.screen.waitForText("Ready") expect(await session.screen.text()).toMatchSnapshot() ``` -------------------------------- ### Launch and Interact with Terminal Session Source: https://github.com/anomalyco/terminal-control/blob/main/docs/typescript-client.md Initialize a terminal session with specific artifacts and environment settings, then perform interactions and assertions. ```ts import { TerminalControl } from "@kitlangton/terminal-control" await using terminal = await TerminalControl.make({ artifacts: { directory: ".termctrl-artifacts", onFailure: true, includeTranscript: false, includeRecording: true, }, }) await using session = await terminal.launch({ command: ["/absolute/path/to/my-terminal-app"], viewport: { cols: 100, rows: 30 }, inheritEnv: false, env: { TERM: "xterm-256color", HOME: "/tmp/test-home" }, record: "on-failure", }) await session.screen.waitForText(/Ready/) await session.keyboard.type("help") await session.keyboard.press("Enter") const text = await session.screen.text() const frame = await session.screen.frame() const logs = await session.logs.text() const transcript = await session.transcript.ansi() expect(text).toMatchSnapshot() expect(frame).toMatchSnapshot() const exit = await session.waitForExit({ timeoutMs: 5_000 }) expect(exit).toMatchObject({ reason: "exited", exit: { code: 0 } }) ``` -------------------------------- ### OpenTUI application handshake Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Specific startup command for OpenTUI applications requiring a host handshake. ```bash termctrl start demo --host opentui --cols 112 --rows 34 -- opencode termctrl wait demo "/connect" ``` -------------------------------- ### Run Workspace Attachment Benchmark Source: https://github.com/anomalyco/terminal-control/blob/main/perf/workspace-attachment.md Executes the workspace attachment benchmark using the release build of the terminal control binary. ```bash cargo build --release --bin termctrl TERMCTRL_BIN=./target/release/termctrl bun scripts/bench-workspace-attach.ts ``` -------------------------------- ### Verify Public Artifacts Source: https://github.com/anomalyco/terminal-control/blob/main/docs/releasing.md Check the version information on registries to confirm successful publication. ```bash cargo info terminal-control npm view @kitlangton/terminal-control version ``` -------------------------------- ### Request OpenTUI Semantic Snapshots Source: https://github.com/anomalyco/terminal-control/blob/main/docs/rust-library.md Configures a session with the OpenTUI host profile to retrieve semantic snapshots from the application. ```rust use std::time::Duration; let mut options = terminal_control::shot::Options::default(); options.opentui_host = true; let mut session = terminal_control::session::Session::start( &["my-opentui-app".to_owned()], None, None, &options, )?; let semantics = session.semantic_snapshot(Duration::from_secs(1))?; ``` -------------------------------- ### Manage Shared Workspaces Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands for creating, attaching to, and configuring persistent terminal workspaces. ```bash termctrl run termctrl run -- nvim termctrl run workspace --tab-position top termctrl run editor --cwd ~/src/project -- nvim termctrl run editor termctrl attach editor ``` -------------------------------- ### Run Workspace Idle Benchmark Source: https://github.com/anomalyco/terminal-control/blob/main/perf/workspace-idle.md Executes the workspace idle benchmark using the compiled binary and a TypeScript script. ```bash cargo build --release --bin termctrl TERMCTRL_BIN=./target/release/termctrl bun scripts/bench-workspace-idle.ts ``` -------------------------------- ### Initialize a terminal test session Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Launch a command in a terminal session and perform assertions using the screen and keyboard APIs. ```ts import { TerminalControl } from "@kitlangton/terminal-control" await using terminal = await TerminalControl.make() await using session = await terminal.launch({ command: ["my-tui"] }) await session.screen.waitForText("Ready") await session.keyboard.press("Enter") expect(await session.screen.text()).toMatchSnapshot() ``` -------------------------------- ### Define Video Edit Plan Source: https://github.com/anomalyco/terminal-control/blob/main/README.md JSON configuration for selecting marker ranges, adjusting playback speed, and adding captions to exported video. ```json { "clips": [ { "from": "before-prompt", "to": "after-answer", "speed": 4, "caption": "The agent answers inside the live terminal UI" } ] } ``` -------------------------------- ### Run CI Validation Checks Source: https://github.com/anomalyco/terminal-control/blob/main/AGENTS.md Execute the full suite of build, test, and linting commands to validate changes before submission. ```bash bun install --frozen-lockfile cargo fmt --all -- --check cargo test --all-targets cargo clippy --all-targets --all-features -- -D warnings cargo build --release bun run test:npm bun run build:npm bun run validate:npm cargo package --list cargo package ``` -------------------------------- ### Publish Release Artifacts Source: https://github.com/anomalyco/terminal-control/blob/main/docs/releasing.md Execute the final publication of the validated crate and npm packages. ```bash cargo publish --locked gh workflow run npm-release.yml --ref main -f publish=true ``` -------------------------------- ### Send Terminal Input Source: https://github.com/anomalyco/terminal-control/blob/main/skills/terminal-control/SKILL.md Use text prefixes or stdin to send commands and keys to an application. Prefer wait commands over sleep to ensure interface updates. ```bash termctrl send app text:/connect enter termctrl send app down enter termctrl send app ctrl-c printf '%s' 'multiline prompt' | termctrl send app --stdin ``` -------------------------------- ### Control Visible Workspaces Source: https://github.com/anomalyco/terminal-control/blob/main/skills/terminal-control/SKILL.md Commands for managing windows, panes, and layouts within a persistent workspace environment. ```bash termctrl run termctrl run -- /usr/bin/nvim termctrl run editor -- nvim termctrl run workspace --tab-position top termctrl run editor termctrl attach editor termctrl windows workspace --json termctrl current --json termctrl tab-position workspace top termctrl move-window workspace editor --index 0 termctrl new-window workspace editor -- nvim termctrl show workspace --window editor termctrl panes workspace --json termctrl layout workspace --grid 2x2 termctrl layout workspace --grid 2x2 -- nvim termctrl send workspace --pane 1 text:opencode2 enter termctrl focus workspace --pane 1 termctrl close-pane workspace --pane 1 termctrl resize-pane workspace --pane 1 --direction left --cells 5 termctrl zoom-pane workspace --pane 1 ``` -------------------------------- ### Automate Workspace and Pane Operations Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands for agents to discover, layout, and drive terminal panes and windows programmatically. ```bash termctrl windows workspace --json termctrl current --json termctrl tab-position workspace top termctrl move-window workspace editor --index 0 termctrl new-window workspace editor --cwd ~/src/project -- nvim termctrl show workspace --window editor termctrl send workspace --window editor text::help enter termctrl panes workspace --window editor --json termctrl layout workspace --window editor --grid 2x2 termctrl layout workspace --window editor --grid 2x2 -- nvim termctrl select-window workspace editor termctrl rename-window workspace editor code termctrl close-window workspace code termctrl move-pane workspace --pane 3 --window editor termctrl resize-pane workspace --pane 3 --direction left --cells 5 termctrl zoom-pane workspace --pane 3 termctrl panes workspace --json termctrl layout workspace --grid 2x2 termctrl show workspace termctrl show workspace --pane 1 termctrl send workspace --pane 1 text:opencode2 enter termctrl focus workspace --pane 1 termctrl close-pane workspace --pane 1 ``` -------------------------------- ### Save Application Artifacts Source: https://github.com/anomalyco/terminal-control/blob/main/skills/terminal-control/SKILL.md Export terminal state in specific formats to a designated output directory. ```bash termctrl save app --format txt --format png --out artifacts/current ``` -------------------------------- ### Initialize TerminalControl Source: https://github.com/anomalyco/terminal-control/blob/main/packages/test/README.md Initialize the terminal control instance using the provided driver. ```ts import { TerminalControl } from "@kitlangton/terminal-control" await using terminal = await TerminalControl.make() ``` -------------------------------- ### Resize Session and Save Recording Source: https://github.com/anomalyco/terminal-control/blob/main/docs/typescript-client.md Adjust the terminal viewport dimensions and manually persist a recording file. ```ts await session.resize({ cols: 120, rows: 40 }) await session.saveRecording("artifacts/navigation.termctrl") ``` -------------------------------- ### Capture and Render ANSI Streams Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands to save piped command output as images or render ANSI streams directly from standard input. ```bash termctrl save --pipe --format png --cols 100 --rows 16 --out captures/log -- my-command printf '\033[44;97m terminal output \033[0m\n' | termctrl show --input - ``` -------------------------------- ### Provide Terminal Control to the application Source: https://github.com/anomalyco/terminal-control/blob/main/packages/opentui/README.md Initialize the terminal control provider with the application's renderer and ensure it closes on destruction. ```ts import { provideTerminalControl } from "@kitlangton/terminal-control-opentui" const terminalControl = provideTerminalControl(renderer, { application: { name: "my-tui", version: "1.0.0" }, }) renderer.once("destroy", () => terminalControl.close()) ``` -------------------------------- ### Read session logs Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands to retrieve scrollback logs from a session. ```bash termctrl logs demo termctrl logs demo --ansi > captures/demo-output.ansi ``` -------------------------------- ### Snapshot Request Source: https://github.com/anomalyco/terminal-control/blob/main/docs/semantic-protocol.md Terminal Control sends this request to the provider to initiate a snapshot. ```json {"type":"semantic.snapshot","id":1} ``` -------------------------------- ### Add Terminal Control Skill Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Add the skill to your coding agent environment. ```bash npx skills add anomalyco/terminal-control --skill terminal-control ``` -------------------------------- ### Driver Protocol Operations Source: https://github.com/anomalyco/terminal-control/blob/main/docs/driver-protocol.md The driver protocol supports various methods for session management and interaction. Each request requires a numeric 'id', a 'method', and a 'sessionId' (except for 'launch' and 'shutdown'). ```APIDOC ## Driver Protocol Operations ### Description The driver accepts typed operations over stdin/stdout. Each request must include a unique numeric `id`, the `method` name, and a `sessionId` (except for `launch` and `shutdown`). Responses are returned as JSON objects with the matching `id`. ### Supported Methods - **launch**: Starts a new terminal session. - **status**: Retrieves current session status. - **send**: Sends text or key input to the session. - **waitForText**: Blocks until specific text appears or timeout occurs. - **waitForIdle**: Blocks until the session is idle. - **waitForExit**: Blocks until the session exits. - **capture**: Captures the current visible frame and text. - **logs**: Retrieves session logs. - **recording**: Manages session recording. - **resize**: Resizes the terminal dimensions. - **stop**: Stops the session. - **shutdown**: Shuts down the driver. ### Request Format {"id": number, "method": string, "sessionId": string, "params": object} ### Response Format {"type": "response", "id": number, "result": object} ### Error Format {"type": "error", "id": number, "error": {"code": string, "message": string}} ``` -------------------------------- ### Snapshot Error Source: https://github.com/anomalyco/terminal-control/blob/main/docs/semantic-protocol.md The application returns this structure if it cannot fulfill the snapshot request. ```json {"type":"error","id":1,"error":{"code":"NOT_READY","message":"the UI is still mounting"}} ``` -------------------------------- ### Validate npm Artifacts Source: https://github.com/anomalyco/terminal-control/blob/main/docs/releasing.md Assemble and validate npm artifacts using the release workflow without publishing. ```bash gh workflow run npm-release.yml --ref main -f publish=false ``` -------------------------------- ### Read terminal screen output Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands to capture the visible screen of a terminal application. ```bash termctrl show --cols 100 --rows 32 -- my-terminal-app ``` ```bash termctrl show --cols 100 --rows 32 --wait-for "Commands" \ -s ctrl-p text:model enter -- my-terminal-app ``` ```bash termctrl show --format json -- my-terminal-app termctrl show --format svg -- my-terminal-app ``` -------------------------------- ### Save terminal artifacts Source: https://github.com/anomalyco/terminal-control/blob/main/README.md Commands to save terminal output as specific file formats. ```bash termctrl save --format png --out captures/home.png -- my-terminal-app termctrl save --format png --format txt --out captures/model -- my-terminal-app ``` -------------------------------- ### Render an ANSI Stream in Rust Source: https://github.com/anomalyco/terminal-control/blob/main/docs/rust-library.md Converts raw ANSI byte sequences into a shot frame and renders it as an SVG. ```rust let shot = terminal_control::shot::from_ansi(b"\x1b[32mready\x1b[0m".to_vec(), 1, 20, 1024)?; assert_eq!(shot.frame.text(), "ready"); let svg = terminal_control::render::svg(&shot.frame, &terminal_control::render::Options::default()); ``` -------------------------------- ### Validate Crate Release Source: https://github.com/anomalyco/terminal-control/blob/main/docs/releasing.md Perform local validation of the Rust crate before publication. ```bash cargo package cargo publish --dry-run --locked ``` -------------------------------- ### Snapshot Result Source: https://github.com/anomalyco/terminal-control/blob/main/docs/semantic-protocol.md The application returns the requested snapshot data using the original request ID. ```json {"type":"result","id":1,"value":{"format":"termctrl-semantic-snapshot-v1","nodes":[]}} ``` -------------------------------- ### Handshake Request Source: https://github.com/anomalyco/terminal-control/blob/main/docs/semantic-protocol.md The application must send this handshake message within five seconds of the socket being accepted. ```json {"type":"hello","protocolVersion":1,"application":{"name":"my-tui","version":"1.0.0"},"capabilities":["semantic.snapshot"]} ``` -------------------------------- ### Extend Vitest Matchers Source: https://github.com/anomalyco/terminal-control/blob/main/docs/typescript-client.md Register custom terminal control matchers with Vitest to enable screen-aware assertions. ```ts import { expect } from "vitest" import { extendTerminalControlMatchers } from "@kitlangton/terminal-control/vitest" extendTerminalControlMatchers(expect) await expect(session).toHaveScreenText("Ready\n\nChoose an option") await expect(session.screen.text()).resolves.toMatchInlineSnapshot() ``` -------------------------------- ### Capture Intermediate Screen State Source: https://github.com/anomalyco/terminal-control/blob/main/docs/typescript-client.md Explicitly request an incomplete screen capture when intermediate frames are required. ```ts const capture = await session.screen.capture({ allowIncomplete: true }) console.log(capture.reason, capture.text, capture.frame) ``` -------------------------------- ### Wrap Assertions for Failure Artifacts Source: https://github.com/anomalyco/terminal-control/blob/main/docs/typescript-client.md Ensure artifacts are saved if an assertion within the block fails. ```ts await session.withArtifactsOnFailure("settings-snapshot", async () => { await expect(session.screen.text()).resolves.toMatchSnapshot() }) ``` -------------------------------- ### Read Disposable Terminal Screen Source: https://github.com/anomalyco/terminal-control/blob/main/skills/terminal-control/SKILL.md Reads the visible screen of a terminal application once without maintaining a persistent session. ```bash termctrl show -- my-terminal-app ``` -------------------------------- ### Handshake Response Source: https://github.com/anomalyco/terminal-control/blob/main/docs/semantic-protocol.md Terminal Control responds with this message upon receiving a valid handshake. ```json {"type":"ready","protocolVersion":1} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.