ptywright 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -119
- package/package.json +1 -1
- package/skills/ptywright-testing/SKILL.md +53 -33
package/README.md
CHANGED
|
@@ -1,188 +1,245 @@
|
|
|
1
1
|
# ptywright
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[中文文档](./README_ZH.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A universal "Terminal DevTools / Playwright driver": Launch any CLI/TUI via PTY, feed ANSI/VT output to `@xterm/headless` to rebuild the screen grid, and expose it as MCP (stdio) tools.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
|
-
|
|
10
|
+
# Recommended: Run with bunx (no install needed)
|
|
11
|
+
bunx ptywright@latest --help
|
|
9
12
|
|
|
10
|
-
#
|
|
11
|
-
bun
|
|
13
|
+
# Or install globally
|
|
14
|
+
bun add -g ptywright
|
|
15
|
+
ptywright --help
|
|
16
|
+
|
|
17
|
+
# Or via npm/npx
|
|
18
|
+
npx -y ptywright@latest --help
|
|
19
|
+
npm install -g ptywright
|
|
20
|
+
```
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Use as MCP Server
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# stdio mode (default)
|
|
28
|
+
bunx ptywright@latest mcp
|
|
15
29
|
|
|
16
|
-
#
|
|
17
|
-
|
|
30
|
+
# HTTP mode
|
|
31
|
+
bunx ptywright@latest mcp-http --port 3000
|
|
18
32
|
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
# 或:PTYWRIGHT_CAPS=core bun run bin/ptywright
|
|
33
|
+
# Minimal tools (reduce Agent context pressure)
|
|
34
|
+
bunx ptywright@latest mcp --caps core
|
|
22
35
|
```
|
|
23
36
|
|
|
24
|
-
|
|
37
|
+
### Configure MCP Client
|
|
25
38
|
|
|
26
|
-
|
|
39
|
+
**Claude Desktop / Cursor** (`~/.config/claude/claude_desktop_config.json`):
|
|
27
40
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"ptywright": {
|
|
45
|
+
"command": "bunx",
|
|
46
|
+
"args": ["ptywright@latest", "mcp"]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
31
51
|
|
|
32
|
-
|
|
52
|
+
**Minimal mode** (load core tools only):
|
|
33
53
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"mcpServers": {
|
|
57
|
+
"ptywright": {
|
|
58
|
+
"command": "bunx",
|
|
59
|
+
"args": ["ptywright@latest", "mcp", "--caps", "core"]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
43
64
|
|
|
44
|
-
|
|
65
|
+
**HTTP mode** (for Web clients):
|
|
45
66
|
|
|
46
|
-
|
|
47
|
-
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"mcpServers": {
|
|
70
|
+
"ptywright": {
|
|
71
|
+
"command": "bunx",
|
|
72
|
+
"args": ["ptywright@latest", "mcp-http", "--port", "3000"]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
48
77
|
|
|
49
|
-
###
|
|
78
|
+
### CLI Commands
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
- `generate_test_from_doc`:从文档(本地/URL)生成可执行脚本
|
|
55
|
-
- `inspect_failure`:查看最近一次失败的屏幕与错误
|
|
80
|
+
```bash
|
|
81
|
+
# Run a single test script
|
|
82
|
+
bunx ptywright@latest run scripts/demo.json
|
|
56
83
|
|
|
57
|
-
|
|
84
|
+
# Run all scripts (generate HTML report)
|
|
85
|
+
bunx ptywright@latest run-all --dir scripts
|
|
58
86
|
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
# Show help
|
|
88
|
+
bunx ptywright@latest --help
|
|
89
|
+
```
|
|
61
90
|
|
|
62
|
-
|
|
91
|
+
## Tools
|
|
63
92
|
|
|
64
|
-
|
|
93
|
+
All tools are enabled by default (`--caps all`). Use `--caps core` or combine as needed:
|
|
65
94
|
|
|
66
|
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
- 组合键:`Ctrl+C`、`Ctrl+Shift+R`、`Alt+X`/`Meta+X`、`Shift+Tab`、`Ctrl+Up`
|
|
70
|
-
- 导航键:`Up/Down/Left/Right`、`Home/End`、`PageUp/PageDown`、`Insert/Delete`、`F1..F12`
|
|
71
|
-
- 兼容:`c-x`(等价 `Ctrl+X`)
|
|
95
|
+
- Default: `--caps all`
|
|
96
|
+
- Minimal: `--caps core`
|
|
97
|
+
- Combined: `--caps core,debug,script,recording`
|
|
72
98
|
|
|
73
|
-
|
|
99
|
+
### core
|
|
74
100
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
101
|
+
- `list_sessions` / `select_session`: Manage and select sessions
|
|
102
|
+
- `launch_session`: Start a PTY session (becomes default session)
|
|
103
|
+
- `send_text` / `press_key`: Send input
|
|
104
|
+
- `snapshot_text`: Return visible screen text (for Agent "seeing" and golden snapshots)
|
|
105
|
+
- `snapshot_view`: Human-friendly snapshot (with metadata + line numbers)
|
|
106
|
+
- `wait_for_text`: Wait for text/regex to appear
|
|
107
|
+
- `wait_for_stable_screen`: Wait for screen to stabilize within quiet window (reduce flaky)
|
|
108
|
+
- `assert`: Assert on current screen (text/regex/semantic)
|
|
109
|
+
- `close_session`: Close session
|
|
78
110
|
|
|
79
|
-
|
|
80
|
-
- PTY + xterm 解析与快照测试
|
|
81
|
-
- MCP server 端到端 smoke(client 通过 stdio 启动 server 并调用 tools)
|
|
111
|
+
### debug (optional)
|
|
82
112
|
|
|
83
|
-
|
|
113
|
+
- `snapshot_ansi`: Return visible screen with ANSI/SGR styles (for debug/human review)
|
|
114
|
+
- `snapshot_view_ansi`: `snapshot_view` with ANSI/SGR styles
|
|
84
115
|
|
|
85
|
-
|
|
116
|
+
### script (optional)
|
|
86
117
|
|
|
87
|
-
|
|
118
|
+
- `run_routine`: Execute multi-step interactions in one call (type/key/wait/assert/snapshot)
|
|
119
|
+
- `run_script`: Run `scriptPath=file.json|file.ts` and produce artifacts (cast/report/failure snapshots)
|
|
120
|
+
- `run_all_scripts`: Run scripts in directory recursively (supports `includeEntries/maxEntries`)
|
|
121
|
+
- `generate_test_from_doc`: Generate executable scripts from documentation (local/URL)
|
|
122
|
+
- `inspect_failure`: View last failure screen and error
|
|
88
123
|
|
|
89
|
-
|
|
90
|
-
# 默认等价 `ptywright mcp`
|
|
91
|
-
bun run bin/ptywright
|
|
92
|
-
```
|
|
124
|
+
### recording (optional)
|
|
93
125
|
|
|
94
|
-
|
|
126
|
+
- `start_script_recording` / `stop_script_recording`: Record MCP tool calls and export replayable scripts (JSON + goldens)
|
|
127
|
+
- `mark`: Add marker to trace (asciicast marker event)
|
|
95
128
|
|
|
96
|
-
|
|
97
|
-
bun run bin/ptywright mcp-http --port 3000
|
|
98
|
-
```
|
|
129
|
+
### `mask` Parameter
|
|
99
130
|
|
|
100
|
-
|
|
131
|
+
`snapshot_text/snapshot_ansi/snapshot_view/snapshot_view_ansi` support `mask=[{regex,flags?,replacement?,preserveLength?}]` to convert random IDs/timestamps into diffable stable snapshots.
|
|
132
|
+
|
|
133
|
+
### `press_key` Key Spec
|
|
134
|
+
|
|
135
|
+
Supports single keys and modifier combinations (case-insensitive, `+`/`-` as separator):
|
|
136
|
+
- Single char: `"a"` / `"?"` (written to PTY as-is)
|
|
137
|
+
- Special keys: `Enter|Return`, `Esc|Escape`, `Backspace`, `Space`, `Tab`, `BackTab`
|
|
138
|
+
- Combos: `Ctrl+C`, `Ctrl+Shift+R`, `Alt+X`/`Meta+X`, `Shift+Tab`, `Ctrl+Up`
|
|
139
|
+
- Navigation: `Up/Down/Left/Right`, `Home/End`, `PageUp/PageDown`, `Insert/Delete`, `F1..F12`
|
|
140
|
+
- Compatible: `c-x` (equals `Ctrl+X`)
|
|
101
141
|
|
|
102
142
|
## Script Runner (JSON)
|
|
103
143
|
|
|
104
|
-
|
|
144
|
+
Write TUI tests as JSON: launch → input → wait → snapshot (with mask) → assert, automatically producing `.cast` + `report.html`.
|
|
105
145
|
|
|
106
|
-
|
|
146
|
+
Optional: Add schema for editor completion/validation:
|
|
107
147
|
|
|
108
148
|
```json
|
|
109
|
-
{ "$schema": "
|
|
149
|
+
{ "$schema": "node_modules/ptywright/schemas/ptywright-script.schema.json" }
|
|
110
150
|
```
|
|
111
151
|
|
|
112
152
|
```bash
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
#
|
|
117
|
-
|
|
153
|
+
# Run single script
|
|
154
|
+
bunx ptywright@latest run scripts/m5_mask_demo.json
|
|
155
|
+
|
|
156
|
+
# Run all scripts
|
|
157
|
+
bunx ptywright@latest run-all --dir scripts
|
|
118
158
|
```
|
|
119
159
|
|
|
120
|
-
|
|
160
|
+
Artifacts go to `.tmp/runs/<name>/` by default (override with `--artifacts-dir`).
|
|
121
161
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
bun run bin/ptywright run-all
|
|
126
|
-
```
|
|
162
|
+
Batch runs generate an overview report:
|
|
163
|
+
- Default: `.tmp/run-all/index.html` + `.tmp/run-all/run.summary.json`
|
|
164
|
+
- With `--artifacts-root <dir>`: `<dir>/index.html` + `<dir>/run.summary.json`
|
|
127
165
|
|
|
128
|
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
166
|
+
On failure, additional files are saved:
|
|
167
|
+
- `failure.error.txt` (error stack)
|
|
168
|
+
- `failure.step.json` (failed step info)
|
|
169
|
+
- `failure.last.txt` / `failure.last.view.txt` (last frame snapshot)
|
|
131
170
|
|
|
132
|
-
|
|
171
|
+
`report.html` includes **Timeline View** showing screen snapshots after each step. Click the `debug` badge to switch to debug view.
|
|
172
|
+
|
|
173
|
+
Built-in steps (no `--steps` needed):
|
|
174
|
+
- `assert`: Assert text/regex (`text`/`regex`)
|
|
175
|
+
- `assertSemantic`: Semantic assertion placeholder (`prompt`)
|
|
176
|
+
- `sleep`: Fixed wait
|
|
177
|
+
- `expectMeta`: Assert terminal meta
|
|
178
|
+
- `waitForExit`: Wait for process exit
|
|
179
|
+
- `sendMouse`: Send SGR mouse events
|
|
180
|
+
|
|
181
|
+
For `type:"custom"` steps, inject handlers with `--steps <module.ts>`:
|
|
133
182
|
|
|
134
183
|
```bash
|
|
135
|
-
|
|
184
|
+
bunx ptywright@latest run demo.json --steps custom_steps.ts
|
|
136
185
|
```
|
|
137
186
|
|
|
138
|
-
|
|
187
|
+
## Script Recording (MCP)
|
|
139
188
|
|
|
140
|
-
|
|
141
|
-
- `failure.error.txt`(错误堆栈)
|
|
142
|
-
- `failure.step.json`(失败的 step 信息)
|
|
143
|
-
- `failure.last.txt` / `failure.last.view.txt`(最后一帧快照)
|
|
189
|
+
Record tool calls into replayable scripts from any MCP client/Agent:
|
|
144
190
|
|
|
145
|
-
|
|
191
|
+
1) `start_script_recording(name="my_flow")`
|
|
192
|
+
2) Execute normally: `launch_session/send_text/press_key/wait_for_*`
|
|
193
|
+
3) Add checkpoints: `mark(label="checkpoint")` (auto-generates `snapshot + expectGolden`)
|
|
194
|
+
4) `stop_script_recording(recordingId=...)` (writes `scripts/my_flow.json` + `tests/golden/scripts/my_flow/*.txt`)
|
|
146
195
|
|
|
147
|
-
|
|
196
|
+
## Script DSL (TypeScript)
|
|
148
197
|
|
|
149
|
-
|
|
150
|
-
- `assert`:**[NEW]** 断言文本/正则(`text`/`regex`)
|
|
151
|
-
- `assertSemantic`:**[NEW]** 语义断言占位符(`prompt`)
|
|
152
|
-
- `sleep`:固定等待
|
|
153
|
-
- `expectMeta`:断言终端 meta
|
|
154
|
-
- `waitForExit`:等待进程退出
|
|
155
|
-
- `sendMouse`:发送 SGR 鼠标事件
|
|
198
|
+
Write scripts with TS builder (type-safe, composable, custom steps):
|
|
156
199
|
|
|
157
|
-
|
|
200
|
+
```bash
|
|
201
|
+
bunx ptywright@latest run scripts/demo.ts
|
|
202
|
+
```
|
|
158
203
|
|
|
159
|
-
|
|
204
|
+
Conventions:
|
|
205
|
+
- Module default export (`export default`), or export `script`.
|
|
206
|
+
- Optional `steps` export (custom step handlers) for `type:"custom"` steps.
|
|
207
|
+
- Use `pasteText("...", { bracketed: true })` for bracketed paste testing.
|
|
160
208
|
|
|
161
|
-
|
|
209
|
+
## Cast -> SVG/GIF (Optional)
|
|
162
210
|
|
|
163
|
-
|
|
164
|
-
2) 正常执行:`launch_session/send_text/press_key/wait_for_*`
|
|
165
|
-
3) 关键节点打点:`mark(label="checkpoint")`(会自动生成 `snapshot + expectGolden`)
|
|
166
|
-
4) `stop_script_recording(recordingId=...)`(写入 `scripts/my_flow.json` + `tests/golden/scripts/my_flow/*.txt`)
|
|
211
|
+
Recording artifacts are best for failure diagnosis or manual review; prefer `snapshot_grid` diff for stable regression.
|
|
167
212
|
|
|
168
|
-
|
|
213
|
+
- SVG: `bunx svg-term --in <castPath> --out <outSvg>`
|
|
214
|
+
- GIF: `agg --fps 30 <castPath> <outGif>` (requires [asciinema/agg](https://github.com/asciinema/agg))
|
|
169
215
|
|
|
170
|
-
|
|
216
|
+
## Development
|
|
171
217
|
|
|
172
218
|
```bash
|
|
173
|
-
bun
|
|
219
|
+
bun install
|
|
220
|
+
|
|
221
|
+
# Start MCP server
|
|
222
|
+
bun run bin/ptywright mcp
|
|
223
|
+
|
|
224
|
+
# Run tests
|
|
225
|
+
bun test
|
|
226
|
+
|
|
227
|
+
# Lint & Format
|
|
228
|
+
bun run lint
|
|
229
|
+
bun run format:check
|
|
230
|
+
|
|
231
|
+
# Run scripts
|
|
232
|
+
bun run bin/ptywright run scripts/m5_mask_demo.json
|
|
233
|
+
bun run bin/ptywright run-all
|
|
174
234
|
```
|
|
175
235
|
|
|
176
|
-
|
|
177
|
-
- module 默认导出(`export default`),或导出 `script`。
|
|
178
|
-
- 可选导出 `steps`(custom step handlers),用于执行 `type:"custom"` 的步骤。
|
|
179
|
-
- 常用 handlers 可复用:`src/script/steps/*`。
|
|
180
|
-
- 需要测试“粘贴”时可用 `pasteText("...", { bracketed: true })`(bracketed paste)。
|
|
236
|
+
## Environment Variables
|
|
181
237
|
|
|
182
|
-
|
|
238
|
+
- `TUI_TEST_PTY_BACKEND=auto|bun-terminal|bun-pty`
|
|
239
|
+
- default `auto`: macOS/Linux prefers `bun-terminal`, Windows uses `bun-pty`
|
|
240
|
+
- `PTYWRIGHT_CAPS=all|core|debug|script|recording`
|
|
241
|
+
- Equivalent to `--caps` parameter
|
|
183
242
|
|
|
184
|
-
|
|
243
|
+
## License
|
|
185
244
|
|
|
186
|
-
-
|
|
187
|
-
- TXT: `bun run src/trace/cast_to_txt.ts --in <castPath> --out <outTxt>`
|
|
188
|
-
- GIF: `asciinema/agg`(例如:`agg --fps 30 <castPath> <outGif>`)
|
|
245
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -3,20 +3,23 @@ name: ptywright-testing
|
|
|
3
3
|
description: Terminal/TUI automation and regression testing using ptywright (PTY + xterm) via CLI or MCP tools. Use when you need to (1) drive a CLI/TUI app (send keys/mouse, wait, snapshot), (2) run scripted regressions (run/run-all) and review the HTML report (index.html + run.summary.json), or (3) record an interactive MCP-driven session into a replayable script with golden checkpoints.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Ptywright Testing
|
|
6
|
+
# Ptywright Testing
|
|
7
7
|
|
|
8
|
-
Use ptywright to run deterministic CLI/TUI regression tests with readable
|
|
8
|
+
Use ptywright to run deterministic CLI/TUI regression tests with readable "terminal screenshots" and a Playwright-like HTML report.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Installation & Usage
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
```bash
|
|
13
|
+
# 推荐:bunx 一次性运行
|
|
14
|
+
bunx ptywright@latest <command>
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
# 或全局安装
|
|
17
|
+
bun add -g ptywright
|
|
18
|
+
ptywright <command>
|
|
19
|
+
|
|
20
|
+
# 本仓库内开发
|
|
21
|
+
bun run bin/ptywright <command>
|
|
22
|
+
```
|
|
20
23
|
|
|
21
24
|
## Choose the interface
|
|
22
25
|
|
|
@@ -25,42 +28,57 @@ This CLI is Bun-based (`#!/usr/bin/env bun`). For a released package, prefer `bu
|
|
|
25
28
|
|
|
26
29
|
## Start the MCP server
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
```bash
|
|
32
|
+
# stdio (default)
|
|
33
|
+
bunx ptywright@latest mcp
|
|
34
|
+
|
|
35
|
+
# 精简 tools(降低上下文压力)
|
|
36
|
+
bunx ptywright@latest mcp --caps core
|
|
37
|
+
|
|
38
|
+
# HTTP 模式
|
|
39
|
+
bunx ptywright@latest mcp-http --port 3000
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Capabilities (`--caps`): `all|core|debug|script|recording` (comma separated)
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
## Configure MCP Client
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
**Claude Desktop / Cursor** (`~/.config/claude/claude_desktop_config.json`):
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"mcpServers": {
|
|
51
|
+
"ptywright": {
|
|
52
|
+
"command": "bunx",
|
|
53
|
+
"args": ["ptywright@latest", "mcp"]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
41
58
|
|
|
42
59
|
## Run scripts (deterministic regression)
|
|
43
60
|
|
|
44
61
|
### Run the whole suite (preferred)
|
|
45
62
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
- Output to focus on:
|
|
50
|
-
- `reportPath` (open in a browser)
|
|
51
|
-
- `summaryPath` (`run.summary.json` for agents/CI)
|
|
63
|
+
```bash
|
|
64
|
+
bunx ptywright@latest run-all --dir scripts
|
|
65
|
+
```
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
Output to focus on:
|
|
68
|
+
- `reportPath` (open in a browser)
|
|
69
|
+
- `summaryPath` (`run.summary.json` for agents/CI)
|
|
54
70
|
|
|
71
|
+
MCP equivalent:
|
|
55
72
|
- `run_all_scripts` (defaults: `dir="scripts"`, suite report in `.tmp/run-all/`)
|
|
56
73
|
- Keep MCP output small: `run_all_scripts(includeEntries="failures", maxEntries=20)`
|
|
57
74
|
|
|
58
75
|
### Run one script
|
|
59
76
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
```bash
|
|
78
|
+
bunx ptywright@latest run <file.json|file.ts> [--artifacts-dir <dir>]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
MCP: `run_script(scriptPath=...)`
|
|
64
82
|
|
|
65
83
|
## Debug a failure
|
|
66
84
|
|
|
@@ -85,7 +103,9 @@ Tip: for flaky waits, prefer `scope="buffer"` when the content may have scrolled
|
|
|
85
103
|
|
|
86
104
|
To verify ptywright MCP tool coverage without relying on external apps/network, run:
|
|
87
105
|
|
|
88
|
-
|
|
106
|
+
```bash
|
|
107
|
+
bun test tests/mcp_all_tools_smoke.test.ts
|
|
108
|
+
```
|
|
89
109
|
|
|
90
110
|
This exercises `core + debug + script + recording` tools end-to-end.
|
|
91
111
|
|