PTY-Agent

VerifiedCaution

Interactive CLI program proxy via subprocess or pseudo-terminal (PTY). Use for maintain ongoing dialog with interactive programs or simulating user interaction tests.

Sby Skills Guide Bot
DevelopmentIntermediate
7/22/2026
Claude CodeCodex
#pty#cli-automation#interactive-process#subprocess#repl

Recommended for

Automated summary

PTY-Agent is a proxy that drives interactive CLI programs (REPLs, debuggers, servers) through a daemon started with app.py, sending input and waiting for specific output patterns.

Strengths

  • Send input and return on a regex trigger (-t), on output silence (--idle-timeout), or on a timeout, removing the need for arbitrary Sleep calls
  • Real-time detection of crashes, program exits and GUI windows while a session is running
  • Named session management (exec/send/read/kill/list/events) with incremental reading by line count, byte offset or grep
  • Encoding options (utf-8, gbk, big5…) and a JSON escaping mode for reliably sending multi-line content

Limitations

  • Requires starting and maintaining a daemon via app.py before any interaction
  • Explicitly unsuitable for complex TUIs, browsers and GUI interfaces, and --pty mode breaks shell operators such as | and &&
  • Quoting rules differ across cmd, PowerShell and bash, making nested commands fragile
When to use it

Use it when an agent genuinely needs a step-by-step dialogue with an interactive program such as GDB, a Python REPL or a server, waiting for specific prompts between steps.

When not to use it

Avoid it when a plain non-interactive script, an HTTP call or a single-shot CLI command already accomplishes the task.

Security analysis

Caution
Quality score86/100

The skill is a legitimate orchestration wrapper for interactive CLI programs, but it intentionally provides powerful process-control capabilities: arbitrary command execution, persistent PTY sessions, process termination, and GUI window closing. There is no evidence of destructive, exfiltrating, or obfuscated behavior, so it is not risky, but it warrants caution because it can run and control arbitrary local programs.

Findings
  • •Provides arbitrary command execution through `exec` and interactive PTY/subprocess sessions
  • •Can terminate sessions/processes via `kill` and close GUI windows via `closewin`
  • •Includes `--force-pty-mode` to bypass shell-operator detection, increasing execution flexibility
  • •Defaults to PowerShell/CMD and can launch any CLI program, debugger, or server
How this analysis is made

Examples

Interactive Python REPL
Start a new PTY session called py1 running `python -i` with trigger `>>>`, then send `print(sum(range(10)))` and wait for the next prompt.
Drive GDB step by step
Use PTY-Agent to launch gdb on ./a.out, set a breakpoint at main, run, and read the backtrace after each stop.
Detect a crashing process
Start a session for `node server.js`, wait for 'listening', then check the events log to see whether the process crashed or exited.

name: pty-agent description: Interactive CLI program proxy via subprocess or pseudo-terminal (PTY). Use when: (1) must maintain ongoing dialog with interactive programs (REPLs, debuggers, Servers) — send input and wait for specific prompts; (2) process may block, crash, or pop up GUI windows — need real-time state detection; (3) simulating user interaction tests. DO NOT use for: non-interactive scripts, web/HTTP API calls, GUI interfaces. If a plain script suffices, do not use this tool. allowed-tools: Bash, Read, Write, Edit

PTY-Agent

PTY-Agent 是一个命令行交互式程序交互代理,通过subprocess或伪终端(PTY)与交互式 CLI 程序双向通信

原理:程序后台有运行一个守护进程,由守护进程接受用户命令,对应CLI进行操作

程序位于app.py,运行方法:python app.py ...

何时使用

  • 迫不得已必须与交互式程序持续对话,需要发送输入并等待特定输出(提示符)后再继续,如GDB、服务器Server、大程序的编译操作。但是能写脚本执行就不用PTY-Agent
  • 进程可能阻塞或执行时间过长 — 需要定期检测状态
  • 子进程可能崩溃 — 需要实时感知崩溃事件
  • 被要求进行模拟用户操作的测试

何时不使用

  • 非交互式任务
  • 完全能写脚本执行、调试
  • GUI界面,浏览器,复杂的TUI程序

命令速查

| 命令 | 用途 | 典型选项 | 示例 | |------|------|----------|------| |start/stop| 手动启动/停止守护进程;启动守护进程exec可实现,一般无需手动 | | | | exec <new-session-id> <options> | 执行命令以启动会话 | -c "<command>"(req), -t "<regex>", --timeout <seconds>, --cwd <path> | exec id_py -c "python -i" -t ">>>" | | send <session-id> "<content>" [options] | 发送输入到运行中的会话 | -t "<regex>", --timeout <seconds> | send id_py "print(1)" -t ">>>" | | read <session-id> [options] | 读取会话输出 | --lines, --grep | read myid --lines 10 | | list | 列出所有会话 | | | | kill <session-id> | 终止会话 | | | | events <session-id> [options] | 查看会话事件 | --last <N>, --since <iso-datetime\|HH:MM> | events myid --last 10 | | closewin <session-id> <window-handle> | 关闭 GUI 窗口;<window-handle>支持十进制或 0x十六进制| |

命令 send 的返回条件

| 模式 | 条件 | 返回信息 | |------|------|----------| | 带trigger | 匹配到正则 | 增量输出 | | 带idle-timeout | 静默超时 | 增量输出 | | 带timeout | 达到超时 | 增量输出 | | 都不带 | 达到默认超时 | 增量输出 | | 未关闭GUI检测 | 检测到GUI窗口(subprocess不一定可用) | GUI窗口信息+增量输出 | | | 有进程崩溃 | 相关事件+增量输出 | | | 程序退出 | 增量输出 |

注:高效利用本程序的条件返回功能,及时根据对应程序的输出结果更新条件(特别是-t),灵活使用不同的返回条件。不建议终端执行Sleep,不建议反复send后又read

exec 用法

python app.py exec <session-id> <options>

选项基本与 send 一致 特殊选项:

  • -c "<command>"(req) 执行的命令,必填
  • --shell <shell> 支持cmd/powershell/pwsh/bash(默认PowerShell,环境不支持自动回退CMD);只有在exec启动时才能配置终端
  • --pty 启用完整伪终端(不支持 |、&& 等shell语法)
    • --force-pty-mode 忽略--pty下的shell操作符检测
  • --cwd <path> 子进程工作目录,不填则默认为调用者(客户端)的工作目录;如果与期望工作目录不一致,建议指定

send 用法

python app.py send <session-id> "<content>" [options]

选项

  • -t/--trigger "<regex>" 匹配正则
    • --newline — 换行后才检查正则触发条件, 与-t搭配
  • --timeout <seconds> 等待超时(默认120s)
    • --idle-after-first-output 首次输出后才开始检测静默,与--idle-timeout搭配
    • 注:高效利用本程序的条件返回功能,及时根据对应程序的输出结果更新条件(特别是-t),灵活使用不同的返回条件。不建议终端执行Sleep,不建议反复send后又read
  • --idle-timeout <seconds> 输出静默超时,程序在指定时间内不输出时触发条件
  • --full 返回终端全部数据(数据大,尽量用--lines N)
  • --json-escaping JSON 转义模式,将<content>进行JSON转义(\\ \" \n \t \r \uXXX ...),建议在发送多行内容时使用

<content>末尾自动追加换行 没有--input参数

引号处理规则(命令行层)

  • cmd 写 \" 嵌套: -c "python -c \"print(1)\""
  • PowerShell/Pwsh 外层单引号,内层双引号: -c 'python -c "print(1)"'

read 用法

python app.py read <session-id> [options]

选项:

  • --lines <N> 最后 N 行
  • --lines start:end 范围行
  • --grep "<regex>" 正则过滤
  • --offset <bytes> 增量读取
  • --full 返回终端全部数据(数据大,尽量用--lines N)

events 完整用法

python app.py events <session-id> [options]

选项:

  • --last N
  • --since <iso-datetime\|HH:MM>
  • --until <iso-datetime\|HH:MM>

全局/通用选项

  • --keep-ansi 保留控制码
  • --color - 启用终端颜色输出
  • --output-by-natural-language 自然语言输出
  • --encoding <encoding> 终端编码,乱码时设置utf-8/gbk/gb2312/gb18030/big5
  • --no-debug 禁用响应中的 debug 输出(进程树/GUI 窗口/事件)
  • --show-config [KEY] 查看当前调用配置
  • --default <KEY> <VALUE> 临时覆盖默认配置(可用键:output-by-natural-language/timeout/newline/keep-ansi/encoding/debug,<VALUE>是配置值或者on/off)

输出格式

  1. JSON 模式(默认)— stdout 仅输出 JSON,每行一个 JSON 对象,。所有非命令响应(守护进程启停信息、配置查询、帮助文本、警告等)也以 JSON 格式输出:
    • 命令响应:{"type": "result", ...} / {"type": "ok", ...} / {"type": "error", ...}
    • 守护进程信息:{"type": "info", "message": "[pty-agent] 守护进程已启动 (端口 12345)"}
    • 配置查询:{"type": "config", "content": "当前调用配置:\n ..."}
    • 帮助文本:{"type": "help", "content": "usage: pty-agent ..."}
    • 警告信息:{"type": "warning", "message": "..."}
  2. 自然语言模式 — 使用 --output-by-natural-language 切换

示例场景

长时运行进程监控 + 中途读取 + 终止

app.py exec srv -c "python server.py" --idle-timeout 3 # 启动,idle-timeout 使首次输出后快速返回
app.py read srv --lines 20 # 中途查看最近20行输出
app.py read srv --offset 1024 # 增量读取(从上次 offset 继续)
app.py read srv --grep "ERROR" # 只看错误行
app.py kill srv # 不再需要时终止

进程崩溃检测

app.py exec job -c "python worker.py" --idle-timeout 5 # 启动,idle-timeout 等待输出
# 若进程崩溃,返回中 trigger.reason="ended",program.exit_code 非零,error_message 含崩溃信息
app.py events job --last 10 # 查看崩溃事件详情(process_crash 类型)

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/pty-agent-mrwakae7/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/pty-agent-mrwakae7' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/pty-agent-mrwakae7/download' --output '.skill-downloads/pty-agent-mrwakae7/SKILL.md.part' && mv '.skill-downloads/pty-agent-mrwakae7/SKILL.md.part' '.skill-downloads/pty-agent-mrwakae7/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

This file does not provide a usable name/description header for this native procedure. It remains available to download and inspect; use the manual method below.

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/pty-agent-mrwakae7/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills