SmartCLI
The SmartCLI MCP server lets agents spawn, perceive, drive, and tear down real terminal/TUI programs through persistent PTY sessions.
Session management: Start detached, persistent sessions for commands (REPLs, vim, htop, lazygit) with configurable cwd/env/size; list, check alive status, resize, and close them.
Perceive the screen: Get semantic snapshots with rendered text, alt-screen status, content hash, visual hash, and optional structured cell/cursor JSON.
Send input: Type literal text without Enter, send full lines with Enter, or send named key tokens and combos (arrows, Ctrl/Meta, function keys) for navigation and control.
Wait/synchronize: Block until a regex matches, any of several patterns matches, screen content changes, visual state changes, or the screen becomes ready/stable — avoiding blind sleeps.
Confirm actions: Use returned hashes as change-detection baselines and snapshot after acting to verify that keystrokes actually landed.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SmartCLI Drive lazygit in a terminal and show me the latest commit diff"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Python · MIT · ★4
SmartCLI
Read this in: English · 简体中文 · 繁體中文 · 日本語 · 한국어
A local Python toolkit for driving, perceiving, and rendering the terminal — three agent skills over one pluggable PTY + pyte core.
Let an AI drive, perceive, and render real terminal programs. SmartCLI reads
the actual screen with a pyte cell model — not a byte pipe — so it knows which
menu row is highlighted, presses the right keys, and waits for the screen to
settle. Below: it drives the real lazygit TUI end-to-end (arrow-key
navigation, opening a commit diff, highlighting a branch) — no script, no mock.
pip install smartcli-toolkitRequires Python 3.10 or newer. The install includes the shared Python library, the persistent TUI driver, and the stdio MCP server.
Drive something in 30 seconds
Copy-paste this. It starts a real Python REPL under a PTY, waits for the prompt
(never a blind sleep), types into it, and reads the screen back:
pip install smartcli-toolkit
SID=$(smartcli-tui start --cmd "python3 -i -q" --cols 80 --rows 24 --json | python3 -c "import json,sys;print(json.load(sys.stdin)['sid'])")
smartcli-tui wait-regex --id $SID ">>> " --timeout-ms 15000
smartcli-tui send-line --id $SID "print(6*7)"
smartcli-tui wait-regex --id $SID "42" # prints the cell grid it sees
smartcli-tui close --id $SIDOn Windows use --cmd "py -i -q". Swap the command for vim, htop or
lazygit and the same five verbs drive those too — that is the whole point:
wait-regex and friends react to what the screen actually shows, so an agent
never guesses whether its keystroke landed.
Want the same thing against a real editor, end to end and verifiable?
examples/drive_vim.py drives the actual vim binary —
opens a file, appends a line, saves, and then checks the filesystem, not the
screen:
python examples/drive_vim.py
# [OK ] vim painted its screen
# [OK ] file contents visible on screen
# [OK ] alternate screen is active
# [OK ] vim entered insert mode (so G and o both landed)
# [OK ] typed text appears on screen
# [OK ] vim restored the main screen on exit
# [OK ] file on disk really changedNote the fourth step. It is there because the example itself once sent five
keystrokes back to back with nothing between them, and under load vim had not
processed G by the time o arrived, so nothing was inserted and the run failed
with no useful diagnosis. Confirming insert mode proves both keys landed — the
same discipline the tool exists to provide, applied to its own demo.
Run the same file against smartcli-toolkit==0.1.8 and two steps fail — and the
file is never saved, because a driver that cannot see the alternate screen
mistimes the :wq. That is why the emulation work below matters: a wrong screen
model does not error, it silently succeeds at nothing.
Already running an MCP client (Claude Code, Cursor, VS Code)? The same verbs are MCP tools, with the per-session token attached for you:
smartcli-mcp # stdio MCP server; or `uvx --from smartcli-toolkit smartcli-mcp`What & why
SmartCLI is a workspace for terminal work that agents and humans both do: driving
interactive terminal programs, perceiving what a screen actually shows, and
rendering visuals and layouts back out. It is built on one shared, pluggable PTY
backend plus a pyte screen model — chosen over screenshot/vision so a single
structured screen model feeds both perception (read the screen) and rendering
(draw the screen). The PTY layer is intentionally not tmux-bound: local dev runs
on Windows via ConPTY (pywinpty), while target programs can run under POSIX ptys
or tmux elsewhere. Three skills sit on that core, each a self-contained tool you run
in place from the checkout.
Related MCP server: can-see
Driving a real TUI
The demo above is SmartCLI driving lazygit — a real full-screen curses app —
through its perceive → act → confirm loop: it reads the pyte cell grid (which
row is selected, the alt-screen diff), moves with arrow keys, opens a commit's
diff, and highlights a branch. Captured by driving the actual program in a Linux
container, not scripted or mocked. A byte-stream matcher like pexpect can't
perceive "which row is highlighted"; a screen model can.
How we know the perception is right. A screen model is only useful if it
matches what a real terminal shows, so we measure that instead of asserting it:
identical bytes go to a real tmux pane and to our model, and the two cell
grids are diffed. Three suites do it — 34 curated cases, a three-way check that
only trusts a behaviour when tmux and GNU screen agree, and a generative
fuzz over random VT sequences. That campaign found and fixed 12 emulation bugs,
including the alternate screen buffer (pyte implements none of modes
1049/1047/47, so a full-screen program's output used to be painted over the main
screen and never restored). Scope and remaining edges:
LIMITATIONS.md.
Live effects
Real captures of the cmd-art fx engine — each GIF is the actual effect
rendered frame-by-frame through the project's own pipeline (no screen recorder).
Reproduce any with python -m fx play <name> (see Quickstart).
|
|
|
donut — the classic ASCII torus | fire — demoscene heat field | rain — Matrix digital rain |
🌐 Explore the live showcase → — play with the effect engine, drive a menu with arrow keys, and poke the widgets, right in your browser.
Install
Just want the three Claude Code skills? Download one zip, unzip it, done — no git, no pip, no marketplace:
curl -LO https://github.com/dwgx/SmartCLI/releases/latest/download/smartcli-skills.zipunzip smartcli-skills.zip -d ~/.claude/skills/That gives you cmd-art, drive-tui and tui-ui (309 KiB total). cmd-art and
tui-ui then work with nothing but CPython 3.10+ — verified on a bare virtualenv,
all 30 effects and all 17 widgets load. drive-tui additionally needs pyte, which
the PyPI install below provides. Or install all three via the plugin marketplace:
/plugin marketplace add dwgx/SmartCLI.
Primary — from PyPI (the library, the CLI, and the MCP server):
pip install smartcli-toolkitDistribution vs import name: the PyPI distribution is
smartcli-toolkit(the namessmartcli/smart-cliwere taken or blocked), but the importable package issmartcli_core. So afterpip install smartcli-toolkityou still writefrom smartcli_core import PtySession.
Alternative — reproduce the full dev environment from a source checkout:
git clone https://github.com/dwgx/SmartCLI SmartCLI
cd SmartCLI
python -m pip install -r requirements.txtrequirements.txt installs pyte, the MCP SDK, and pywinpty on Windows only
(POSIX uses the stdlib pty backend). pip install . installs smartcli_core
plus the smartcli-tui, smartcli-mcp, and smartcli-toolkit commands. The
visual cmd-art and tui-ui skills still run in place from a checkout via
python -m fx and python -m ui.
Optional extras (real FIGlet fonts, raster images, authoritative cell widths — all degrade gracefully to stdlib fallbacks when absent):
python -m pip install -r requirements-optional.txt
# or, from the checkout, via pyproject extras:
pip install ".[all]" # pyfiglet + Pillow + wcwidth
pip install ".[art]" # pyfiglet only
pip install ".[image]" # Pillow only (also: the PNG screenshot harness needs it)
pip install ".[width]" # wcwidth onlyWindows note: set UTF-8 output before running any skill so box-drawing and CJK glyphs encode cleanly (the CLIs also auto-reconfigure stdout, but set this to be safe):
set PYTHONIOENCODING=utf-8Verified dep versions on the dev box (Windows 11, CPython 3.14.6): pyte 0.8.2,
pywinpty 3.0.5, pyfiglet 1.0.4, Pillow 12.2.0, wcwidth 0.8.1.
Diagnostics. python -m smartcli_core prints your OS, Python, terminal, PTY
backend, and dependency versions. smartcli-tui doctor reports where the core
was loaded from and whether drive dependencies are present. Include both outputs
when filing a terminal-sensitive bug.
Quickstart
cmd-art — terminal visual effects
cd skills/cmd-art
python -m fx list # list all 30 effects
python -m fx play donut --seconds 5 # play one effect (bounded)
python -m fx gallery # one frame of each effect
python -m fx show --seq "donut:fire:3,plasma::3"tui-ui — cell-accurate terminal UI
cd skills/tui-ui
python -m ui widgets # list all 17 widgets
python -m ui gallery --width 100 --height 30
python -m ui demo table --width 80 --height 12 --theme dashboarddrive-tui — perceive & drive interactive programs
Persistent-session CLI (state survives across shell calls):
smartcli-tui start --cmd "python3 -i -q" --cols 80 --rows 24
smartcli-tui wait-regex --id <SID> ">>> " --timeout-ms 15000
smartcli-tui send-line --id <SID> "print(6*7)"
smartcli-tui snapshot --id <SID>
smartcli-tui close --id <SID>On Windows use py -i -q as the child command. From a source checkout, replace
smartcli-tui with python skills/drive-tui/scripts/tui.py.
Or drive from any MCP client — the same verbs as MCP tools, with the per-session token attached automatically:
pip install smartcli-toolkit
smartcli-mcp # stdio MCP server; smartcli-toolkit is an equivalent aliasAs a library
The shared core is importable directly:
import sys
from smartcli_core import PtySession
s = PtySession()
s.start([sys.executable, "-q"])
s.wait_for(r">>> ") # readiness sync, never a blind sleep
print(s.snapshot().to_text()) # pyte-backed structured screen
s.close()For the full command reference, the screenshot/AGENTCLI harnesses, and the regression
suite, see README-USAGE.md.
Features
cmd-art (skills/cmd-art) — a "living-template" effect engine: an Effect ABC +
@register decorator + auto-discovery. 30 effects (donut, solarsystem, fire, plasma,
rain, starfield, tunnel, text3d, cube, sphere, boids, life, fireworks, sparkle, decrypt,
gradient_text, banner_scroll, image2ascii, typewriter, julia, mandelbrot, perlin, flames, water, nebula, text_flyin, text_converge, text_decrypt, spectrum_bars, cbonsai) across 8 themes (mono, fire,
ocean, synthwave, viridis, pastel, matrix-green, rainbow). Effects are pure frame
producers; play is bounded by default and always restores the terminal.
tui-ui (skills/tui-ui) — a web-like terminal layout engine emitting tmux-safe
ANSI frames (SGR color runs + newlines only; no cursor moves, no alt-screen). 17
widgets (badge, banner, braille_chart, card, fuzzy_filter_list, gradient_rule, kv,
meter, panel, preview_pane, progress, radial_glow, rule, slider_track, table, tabs,
tree) over an engine of two modules the render path actually calls — field.py
(shader compositors) and raster.py (sub-cell half/quad/braille pixels). Two
further helpers, box_junction.py and color_model.py, shipped unwired through
0.3.2 and were removed in 0.3.3: nothing imported them, and tui-ui has no
auto-discovery over ui/, so no caller could ever reach them.
Display-cell accurate for CJK/emoji/ZWJ so columns never desync.
drive-tui (skills/drive-tui) — drives interactive terminal programs (REPLs,
menus, pagers, y/N prompts, wizards) through a PTY via a
perceive → decide → act → wait → confirm loop, never a blind sleep. A thin CLI
(scripts/tui.py) offers a persistent detached session and a one-shot run mode, with
an importable pattern library of 8 recipes (repl, menu_select, pager, search_filter,
confirm, form, progress, wizard) that classify() a screen and drive() it.
Where the wait capabilities live. The wait family can end when the child
process dies rather than sitting out the remaining timeout — a program that
crashes on your first input then costs one poll cycle instead of the whole
ceiling. It is opt-in and off by default: start --detect-child-exit /
run --detect-child-exit, or detect_child_exit on the MCP start tool. Off
is exactly the previous behaviour. On, every wait reply carries exited, and
wait reports reason=EXITED. Three other core capabilities — the
screen-revision wait baseline, the terminal-mode registry, and the session event
log — are library-only: they are importable from smartcli_core and are
deliberately not on the CLI or MCP surface. See
CHANGELOG.md (Unreleased) for the reasoning per capability.
Shared core (smartcli_core) — the pluggable PTY backend + pyte screen model +
semantic snapshot + readiness sync (pty_backend / screen_model / snapshot / readiness / session). The reusable, importable foundation under all three skills. Since 0.3.0 a
budgeted read path and an io block travel with every observation, so a caller can tell
quiet from not read yet (local_cut, byte watermarks, pending facts — unknown values are
null, never 0), STABLE requires a drained observation, and close reports
closed_confirmed or close_unconfirmed with the last progress instead of assuming a
returned native call means the child is gone.
Knowledge graph (knowledge/) — a wiki-link graph (140+ .md files) of exact
rendering formulas, ANSI sequences, and measured constants, each note carrying a
source and cross-links. See knowledge/INDEX.md.
Project layout
SmartCLI/
smartcli_core/ shared PTY + pyte engine (importable package)
skills/cmd-art/ fx effect package and CLI (30 effects, 8 themes)
skills/drive-tui/ TUI pattern library and PTY driver CLI (8 recipes)
skills/tui-ui/ terminal UI layout engine and widgets (17 widgets)
tools/screenshot/ pyte -> PNG smoke-test harness
tools/agentcli/ agent-CLI control validation harness
knowledge/ wiki-link knowledge graph, 140+ .md files (see knowledge/INDEX.md)
showcase/ rendered effect PNGs + demo GIFs (shown above)
tests/ direct script-style regressions
research/ archived first-pass research notesDocumentation
README-USAGE.md— the full usage cheat-sheet: every skill, the screenshot and AGENTCLI harnesses, and the regression commands.knowledge/INDEX.md— the knowledge graph (140+.mdfiles).AGENTCLI-VALIDATION.md— agent-CLI control test matrix.CHANGELOG.md— release history.Verification evidence tree — archived 2026-10-01. The former
verification/directory (receipts, probes, historical harness revisions) is no longer part of this repository, and is not distributed with the package. It was moved byte-for-byte, so nothing was deleted. It was pulled out because it held 8 stale copies ofsmartcli_core/screen_model.pytaken before three bug fixes, so a repo-wide search returned pre-fix code. The sha256 pins inside it still resolve — they name files that stayed in the repository.
License
MIT — see LICENSE.
Available Tools
14 toolsaliveARead-onlyIdempotent
Check whether the session's child process is still running.
Inputs: sid (required).
closeADestructiveIdempotent
Terminate a session and its daemon. Always close sessions when done.
Inputs: sid (required).
list_sessionsARead-onlyIdempotent
List active drive-tui sessions.
Returns {"ok", "sessions"}: each entry carries "sid", "port", "pid", "cmd", "cols", "rows", "cwd" and "started".
Inputs: no named parameters.
resizeBIdempotent
Resize the session's terminal to cols x rows.
Inputs: sid (required), cols (required), rows (required).
send_keysA
Send key tokens, e.g. ["Down", "Down", "Enter"], ["C-c"], ["M-x"].
Named tokens: Enter, Return, Tab, BackTab, Space, Backspace, Delete, Escape, Esc, Up, Down, Right, Left, Home, End, PageUp, PageDown, Insert, F1-F12. Combos: "C-" or "^" (Ctrl — letters plus @, Space, [, , ]) and "M-" (Meta/Alt, ESC prefix). Any other token is not an error — it is typed as literal text.
Arrow keys adapt to the app's cursor-key mode (SS3 under DECCKM, CSI else), so menu navigation works in curses apps.
Inputs: sid (required), keys (required).
send_lineA
Type text followed by Enter — the common 'run this command' action.
Inputs: sid (required), text (required).
send_textA
Type literal text into the session (no Enter). Use for filling fields.
Inputs: sid (required), text (required).
snapshotARead-onlyIdempotent
Read a semantic snapshot of the session's current screen.
Returns {"ok", "alive", "alt_screen", "text", "hash", "visual_hash"}:
alt_screen is true while a full-screen program (vim, less, htop, ...)
owns the screen — keys are commands to that program, not input to a
shell, and text is its frame rather than scrollback. text is the
rendered screen; json (the structured cell/cursor model) is included only
when as_json=true. hash covers text content only — use it as the
wait_change baseline; visual_hash also covers styling, selection and
cursor state — use it as the wait_visual_change baseline. Don't mix the
two. This is the 'perceive' step — always snapshot after acting rather
than assuming an action landed.
Inputs: sid (required), as_json.
startA
Spawn a program in a new detached, persistent session and return its id.
The session survives across tool calls (a localhost-only daemon owns the live
PtySession). cmd is the command line to spawn, e.g. "python3" or
"lazygit". cwd and env configure only the controlled child process.
Returns {"ok", "sid"} on success. Use the returned sid for every other tool.
Server-side limits (violations return an error): at most 8 concurrent
sessions by default (tunable via SMARTCLI_MAX_SESSIONS); sid must be 1-64
chars matching [A-Za-z0-9][A-Za-z0-9_.-]*; env keys must be valid
identifiers and may not start with SMARTCLI_TUI_; cwd must be an existing
directory; terminal size is capped at 1000 cols x 500 rows (100000 cells).
Note: env values pass through the process command line briefly (visible
in ps) — avoid secrets.
detect_child_exit (default false) makes this session's waits END when the
child dies instead of sitting out the remaining timeout: a program that
crashes on your first input costs one poll cycle instead of the whole
ceiling. Off is exactly the previous behaviour. On, every wait tool also
reports exited (true only when the wait ended that way), and wait_ready
reports reason: "EXITED" alongside the usual MARKER/STABLE/TIMEOUT.
Inputs: cmd (required), cwd, env, sid, +3 more.
wait_anyARead-onlyIdempotent
Wait for ANY of patterns to appear on screen (pexpect expect([...]) style).
Race several possible outcomes at once — e.g. patterns=[">>> ", "Error",
"Password:"] — and learn WHICH happened. Patterns are scanned in list order
each poll, so the earliest in the list wins a same-poll tie (put the most
specific first). Screen lines are right-padded with spaces — end-anchored
patterns never match; use unanchored markers. Returns {"ok", "index",
"matched", "alive", "exited", "text", "json"} where index is the 0-based
position of the matched pattern. Timeout is not an error: the call returns
ok=true with index=-1 and matched=false plus the final screen snapshot.
On a detect_child_exit session whose child died first, index is -1,
matched is false and exited is true — the wait returned at once rather
than running to timeout_ms.
Inputs: sid (required), patterns (required), timeout_ms.
wait_changeARead-onlyIdempotent
Block until the screen content changes, then snapshot.
The precise "did my action land?" primitive: call it right after send_line/
send_keys to wait for ANY change from the baseline (default: the screen at
call time; or pass a prior hash to change away from). Returns {"ok",
"changed", "hash", "alive", "exited", "text", "json"} — hash is the new
screen hash, reusable as the next baseline. Timeout is not an error: the
call returns ok=true with changed=false plus the final screen snapshot.
exited is true only on a detect_child_exit session whose child died
first. Can't false-positive on text that was already on screen, unlike
wait_regex.
Inputs: sid (required), timeout_ms, baseline_hash.
wait_readyARead-onlyIdempotent
Wait for a regex marker OR for the screen to go quiet (stable), then
snapshot. Use marker="" to wait purely for stability.
Returns a snapshot plus reason: "MARKER" (the regex appeared), "STABLE"
(the screen went quiet), "TIMEOUT", or — only on a session started with
detect_child_exit — "EXITED" (the child died; the wait returned at once
rather than running to max_wait_ms). exited reports the same fact as a
boolean on every wait tool. Timeout is not an error: the call still returns
ok=true with the final screen snapshot. Screen lines are right-padded with
spaces — end-anchored markers never match; use unanchored markers.
Inputs: sid (required), marker, quiet_ms, max_wait_ms.
wait_regexARead-onlyIdempotent
Block until pattern (a regex) appears on screen, then snapshot.
Returns {"ok", "matched", "alive", "exited", "text", "json"}. Timeout is
not an error: the call returns ok=true with matched=false plus the final
screen snapshot. exited is true only when the session was started with
detect_child_exit AND the child died before the pattern appeared, in
which case the wait returned at once instead of running to timeout_ms.
Screen lines are right-padded with spaces — end-anchored patterns never
match; use unanchored markers. This is the readiness sync — prefer it over
a blind delay after send_line/send_keys.
Inputs: sid (required), pattern (required), timeout_ms.
wait_visual_changeARead-onlyIdempotent
Wait for text, selection styling, or cursor position to change.
Prefer this after arrow/navigation keys in full-screen TUIs. Pass a prior
visual_hash, or omit it to use the current rendered state as the baseline.
Timeout is not an error: the call returns ok=true with changed=false plus
the final screen snapshot, with exited true only on a
detect_child_exit session whose child died first.
Inputs: sid (required), timeout_ms, baseline_hash.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Most tools are clearly distinct by action and target, but the five wait_* variants overlap conceptually. Their descriptions explicitly differentiate patterns, content hashes, visual hashes, multiple patterns, and readiness modes, so an agent can choose, though some confusion is possible.
Tool names consistently use snake_case and are mostly verb-first or verb_noun (list_sessions, send_keys, wait_regex, close, start). Minor noun/adjective names like snapshot and alive still fit the overall predictable style.
14 tools is a reasonable size for persistent terminal and TUI automation. The five wait tools are somewhat heavy, but each covers a distinct synchronization primitive rather than being redundant.
The set covers session lifecycle (start, list_sessions, close, alive, resize), input (send_text, send_line, send_keys), waits, and screen perception. Minor gaps exist for explicit signal/interrupt operations or scrollback retrieval, but send_keys and snapshots let agents work around them.
Maintenance
Related MCP Connectors
Make games with AI: one MCP server that connects your agent to Unity, Unreal and Godot editors.
Remote MCP server exposing your Node Command fleet (files, shell, processes, browser) to AI hosts.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Real-time chat for AI agents. Claude Code, Cursor, Cline and Codex join channels over MCP.
Related MCP Servers
- AlicenseAqualityDmaintenanceAn MCP server that lets AI agents launch, interact with, and inspect Textual TUI applications headlessly.124MIT
- AlicenseNot gradedqualityCmaintenanceMCP server that lets AI agents see and interact with terminal/CLI applications through virtual terminals and PNG screenshots.75 npmMIT
- AlicenseAqualityCmaintenanceMCP server that gives AI agents real interactive terminal sessions for running REPLs, SSH, database clients, and any interactive CLI with clean text output and smart completion detection.778 npm20MIT
- AlicenseBqualityDmaintenanceLocal + remote terminal interaction control MCP Server. Lets AI agents control interactive TUI programs the way a human would.297 npmMIT


