{"id":51610273,"url":"https://github.com/alexpasmantier/phantom","last_synced_at":"2026-07-12T07:02:37.181Z","repository":{"id":350348923,"uuid":"1195510685","full_name":"alexpasmantier/phantom","owner":"alexpasmantier","description":"Phantom lets you programmatically drive any terminal application — spawn it, send input, read the screen, wait for conditions","archived":false,"fork":false,"pushed_at":"2026-07-01T19:44:59.000Z","size":1319,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-01T21:25:23.793Z","etag":null,"topics":["agents","ai","cli","ghostty","tests","tui"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexpasmantier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-29T18:51:28.000Z","updated_at":"2026-07-01T19:45:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/alexpasmantier/phantom","commit_stats":null,"previous_names":["alexpasmantier/phantom"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alexpasmantier/phantom","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpasmantier%2Fphantom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpasmantier%2Fphantom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpasmantier%2Fphantom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpasmantier%2Fphantom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexpasmantier","download_url":"https://codeload.github.com/alexpasmantier/phantom/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpasmantier%2Fphantom/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35384622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-12T02:00:06.386Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agents","ai","cli","ghostty","tests","tui"],"created_at":"2026-07-12T07:02:36.471Z","updated_at":"2026-07-12T07:02:37.169Z","avatar_url":"https://github.com/alexpasmantier.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phantom (`pt`)\n\n[![CI](https://github.com/alexpasmantier/phantom/actions/workflows/ci.yml/badge.svg)](https://github.com/alexpasmantier/phantom/actions/workflows/ci.yml)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![crates.io](https://img.shields.io/crates/v/phantom-test.svg)](https://crates.io/crates/phantom-test)\n\nPhantom lets you programmatically drive any terminal application — spawn it, send input, read the screen, wait for conditions. Built on [libghostty-vt](https://github.com/ghostty-org/ghostty) (Ghostty's terminal emulation core).\n\n**Use cases:** AI agent tool use, TUI integration testing, terminal automation.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/demo.gif\" alt=\"phantom test runner with live TUI monitor\" width=\"800\"\u003e\n\u003c/p\u003e\n\n## Quick Start\n\n```bash\n# Spawn vim in a headless session\npt run -s editor -- vim\n\n# Wait for it, type something, read the screen\npt wait -s editor --text \"~\" --timeout 5000\npt send -s editor --type \"iHello, world!\"\npt send -s editor --key escape\npt screenshot -s editor\n\n# Clean up\npt send -s editor --type \":q!\\n\"\npt wait -s editor --process-exit\n```\n\nThe daemon starts automatically on the first command.\n\n## Installation\n\nRequires [Rust](https://rustup.rs/) nightly and [Zig](https://ziglang.org/download/) 0.15.x.\n\n```bash\ncargo build --release --workspace\n```\n\nPre-built binaries are available on the [Releases](https://github.com/alexpasmantier/phantom/releases) page.\n\n## CLI\n\n```bash\n# Sessions\npt run -s NAME -- COMMAND [ARGS...]     # Spawn a TUI\npt run -s app --cols 120 --rows 40 -- ./my-tui\npt list                                 # List sessions\npt status -s NAME                       # Running/exited?\npt kill -s NAME                         # Terminate\npt monitor -s NAME                      # Watch a session live\n\n# Input\npt send -s NAME --type \"hello\"          # Type text\npt send -s NAME --key ctrl-c            # Keys (enter, escape, f1, alt-x, ...)\npt send -s NAME --paste \"text\"          # Bracketed paste\npt send -s NAME --mouse click:10,5      # Mouse events\n\n# Screen\npt screenshot -s NAME                   # Plain text\npt screenshot -s NAME --format json     # Full cell data (grapheme, colors, attrs)\npt screenshot -s NAME --region 0,0,5,40 # Capture a region\npt cursor -s NAME                       # Cursor position and style\npt cell -s NAME --x 0 --y 0            # Single cell\npt scrollback -s NAME --lines 100       # Scrollback buffer\n\n# Wait (conditions are AND-ed, default timeout 10s)\npt wait -s NAME --text \"Ready\"          # Text on screen\npt wait -s NAME --regex \"v\\d+\\.\\d+\"     # Regex match\npt wait -s NAME --stable                # Screen stopped changing\npt wait -s NAME --process-exit          # Process exited\npt wait -s NAME --text \"Done\" --stable --timeout 5000\n\n# Snapshots\npt snapshot save -s NAME -f ref.txt     # Save screen\npt snapshot diff -s NAME -f ref.txt     # Compare (exit 1 on diff)\n\n# Batch\npt batch commands.txt                   # One command per line, # for comments\n```\n\nGlobal flags: `--json`, `--human`, `--socket PATH`, `--version`.\n\n## Rust Library (`phantom-test`)\n\nWrite TUI integration tests in Rust — no daemon needed, the engine runs in-process.\n\n```toml\n[dev-dependencies]\nphantom-test = { version = \"0.1\", features = [\"monitor\"] }\n```\n\n```rust\nuse phantom_test::Phantom;\n\nlet pt = Phantom::new()?;\nlet s = pt.run(\"vim\").args(\u0026[\"--clean\", \"-u\", \"NONE\"]).start()?;\n\ns.wait().text(\"~\").timeout_ms(5000).until()?;\ns.send().type_text(\"iHello\")?;\ns.send().key(\"escape\")?;\n\nlet screen = s.screenshot()?;\nassert!(screen.contains(\"Hello\"));\n\ns.send().type_text(\":q!\\n\")?;\ns.wait().process_exit().until()?;\n```\n\n### Test Runner with Live Monitor\n\n`TestRunner` runs structured test suites with an optional TUI monitor that shows test progress alongside a live view of the terminal session being tested:\n\n```rust\nuse phantom_test::TestRunner;\n\nTestRunner::new()\n    .test(\"vim insert mode\", |pt| {\n        let s = pt.run(\"vim\").args(\u0026[\"--clean\", \"-u\", \"NONE\"]).start()?;\n        s.wait().text(\"~\").timeout_ms(5000).until()?;\n        s.send().type_text(\"iHello from phantom\")?;\n        s.wait().text(\"Hello from phantom\").until()?;\n        s.send().key(\"escape\")?;\n        s.send().type_text(\":q!\\n\")?;\n        s.wait().process_exit().until()?;\n        Ok(())\n    })\n    .test(\"bash echo\", |pt| {\n        let s = pt.run(\"bash\").args(\u0026[\"--norc\", \"--noprofile\"]).start()?;\n        s.wait().stable(300).until()?;\n        s.send().type_text(\"echo 'phantom works!'\\n\")?;\n        s.wait().text(\"phantom works!\").until()?;\n        Ok(())\n    })\n    .run(); // pass --monitor for live TUI, or set PHANTOM_MONITOR=1\n```\n\nRun headless or with the live monitor:\n\n```bash\n# Headless — prints results to stdout\ncargo test --example my_tests\n\n# With live TUI monitor — shows a real-time view of each test's terminal\ncargo test --example my_tests -- --monitor\n```\n\nHeadless output:\n\n```\nphantom integration tests\n────────────────────────────\n\n  ✓ vim insert mode         1.2s\n  ✓ bash echo               0.4s\n\n────────────────────────────\n2/2 passed\n```\n\nThe `--monitor` flag opens a split-screen TUI: test list on the left with pass/fail status, and a live mirror of the terminal session on the right — so you can see exactly what your tests see as they run.\n\n## MCP Server (`phantom-mcp`)\n\nPhantom also ships as an [MCP](https://modelcontextprotocol.io) server, so AI agents (Claude Code, Claude Desktop, Cursor, Zed, …) can drive headless TUI programs over stdio. It embeds the engine in-process — no daemon to manage.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"crates/phantom-mcp/docs/demo.gif\" alt=\"phantom-mcp live in-tmux viewer demo\" width=\"800\"\u003e\n\u003c/p\u003e\n\nWhen the user is running their MCP client inside **tmux**, the `phantom_show` tool splits the surrounding pane to show a live `phantom monitor` view of the agent's TUI session — the human watches what the agent is doing in real time, in the same terminal, without opening anything.\n\n```bash\ncargo build -p phantom-mcp --release\n```\n\nThen point your MCP client at the binary:\n\n```json\n{ \"mcpServers\": { \"phantom\": { \"command\": \"/abs/path/to/target/release/phantom-mcp\" } } }\n```\n\nTools exposed: `phantom_run`, `phantom_send`, `phantom_wait`, `phantom_screenshot` (text or PNG image, with optional region), `phantom_show`, `phantom_cursor`, `phantom_cell`, `phantom_scrollback`, `phantom_output`, `phantom_status`, `phantom_list`, `phantom_resize`, `phantom_kill`. See [`crates/phantom-mcp/README.md`](crates/phantom-mcp/README.md) for the full reference.\n\n## Exit Codes\n\n| Code | Meaning |\n|------|---------|\n| 0 | Success |\n| 1 | Error |\n| 2 | Session not found |\n| 3 | Wait timed out |\n| 4 | Process exited |\n| 5 | Session name collision |\n\n## Architecture\n\n```\npt CLI  ──unix socket──▶  phantom-daemon  ──pty──▶  child process\n                               │\n                          libghostty-vt\n                       (terminal emulation)\n```\n\nThe daemon owns all terminal state on a dedicated engine thread (libghostty-vt types are `!Send`). The CLI is stateless — connect, send JSON, get JSON back.\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for the full architecture guide.\n\n## Contributing\n\nContributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexpasmantier%2Fphantom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexpasmantier%2Fphantom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexpasmantier%2Fphantom/lists"}