ptywright 0.1.0
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/LICENSE +201 -0
- package/README.md +188 -0
- package/bin/ptywright +4 -0
- package/package.json +76 -0
- package/schemas/ptywright-script.schema.json +297 -0
- package/skills/ptywright-testing/SKILL.md +102 -0
- package/src/cli.ts +414 -0
- package/src/generator/doc_parser.ts +341 -0
- package/src/generator/generate.ts +161 -0
- package/src/generator/index.ts +10 -0
- package/src/generator/script_generator.ts +209 -0
- package/src/generator/step_extractor.ts +397 -0
- package/src/index.ts +16 -0
- package/src/mcp/http_server.ts +174 -0
- package/src/mcp/script_recording.ts +238 -0
- package/src/mcp/server.ts +1348 -0
- package/src/pty/bun_pty_adapter.ts +34 -0
- package/src/pty/bun_terminal_adapter.ts +149 -0
- package/src/pty/pty_adapter.ts +31 -0
- package/src/script/dsl.ts +188 -0
- package/src/script/module.ts +43 -0
- package/src/script/path.ts +151 -0
- package/src/script/run.ts +108 -0
- package/src/script/run_all.ts +229 -0
- package/src/script/runner.ts +983 -0
- package/src/script/schema.ts +237 -0
- package/src/script/steps/assert_snapshot_equals.ts +21 -0
- package/src/script/steps/index.ts +2 -0
- package/src/script/suite_report.ts +626 -0
- package/src/session/session_manager.ts +145 -0
- package/src/session/terminal_session.ts +473 -0
- package/src/terminal/ansi.ts +142 -0
- package/src/terminal/keys.ts +180 -0
- package/src/terminal/mask.ts +70 -0
- package/src/terminal/mouse.ts +75 -0
- package/src/terminal/snapshot.ts +196 -0
- package/src/terminal/style.ts +121 -0
- package/src/terminal/view.ts +49 -0
- package/src/trace/asciicast.ts +20 -0
- package/src/trace/asciinema_player_assets.ts +44 -0
- package/src/trace/cast_to_txt.ts +116 -0
- package/src/trace/recorder.ts +110 -0
- package/src/trace/report.ts +2092 -0
- package/src/types.ts +86 -0
- package/src/util/hash.ts +8 -0
- package/src/util/sleep.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# ptywright
|
|
2
|
+
|
|
3
|
+
一个通用的“终端版 DevTools / Playwright driver”原型:通过 PTY 启动任意 CLI/TUI,把 ANSI/VT 输出喂给 `@xterm/headless` 重建屏幕网格,并以 MCP(stdio)暴露工具接口。
|
|
4
|
+
|
|
5
|
+
## Run
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun install
|
|
9
|
+
|
|
10
|
+
# 默认:启动 MCP server(等价 `ptywright mcp`)
|
|
11
|
+
bun run bin/ptywright
|
|
12
|
+
|
|
13
|
+
# 显式写法:
|
|
14
|
+
# bun run bin/ptywright mcp
|
|
15
|
+
|
|
16
|
+
# 可选:以 Streamable HTTP 方式启动(Web transport)
|
|
17
|
+
# bun run bin/ptywright mcp-http --port 3000
|
|
18
|
+
|
|
19
|
+
# 可选:减少 tool 数量(降低 Agent 上下文压力)
|
|
20
|
+
# bun run bin/ptywright mcp --caps core
|
|
21
|
+
# 或:PTYWRIGHT_CAPS=core bun run bin/ptywright
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Tools (MVP)
|
|
25
|
+
|
|
26
|
+
工具默认全量开启(等价 `PTYWRIGHT_CAPS=all`)。如需减少 tool 数量,可设置 `PTYWRIGHT_CAPS=core` 或按需组合:
|
|
27
|
+
|
|
28
|
+
- 默认:`PTYWRIGHT_CAPS=all`
|
|
29
|
+
- 最小:`PTYWRIGHT_CAPS=core`
|
|
30
|
+
- 组合:`PTYWRIGHT_CAPS=core,debug,script,recording`
|
|
31
|
+
|
|
32
|
+
### core
|
|
33
|
+
|
|
34
|
+
- `list_sessions` / `select_session`:管理与选择会话
|
|
35
|
+
- `launch_session`:启动 PTY 会话(会自动成为默认会话)
|
|
36
|
+
- `send_text` / `press_key`:发送输入
|
|
37
|
+
- `snapshot_text`:返回可见屏幕文本(适合 Agent “看界面”与做 golden)
|
|
38
|
+
- `snapshot_view`:更适合人看的快照(带元信息+行号)
|
|
39
|
+
- `wait_for_text`:等待文本/正则出现
|
|
40
|
+
- `wait_for_stable_screen`:等待屏幕在 quiet window 内稳定(降低 flaky)
|
|
41
|
+
- `assert`:对当前屏幕做断言(text/regex/semantic)
|
|
42
|
+
- `close_session`:关闭会话
|
|
43
|
+
|
|
44
|
+
### debug(可选)
|
|
45
|
+
|
|
46
|
+
- `snapshot_ansi`:返回带 ANSI/SGR 样式的可见屏幕(适合 debug/人眼验收)
|
|
47
|
+
- `snapshot_view_ansi`:带 ANSI/SGR 样式的 `snapshot_view`
|
|
48
|
+
|
|
49
|
+
### script(可选)
|
|
50
|
+
|
|
51
|
+
- `run_routine`:一键执行多步交互(type/key/wait/assert/snapshot)
|
|
52
|
+
- `run_script`:运行 `scriptPath=file.json|file.ts` 并产出 artifacts(cast/report/失败快照)
|
|
53
|
+
- `run_all_scripts`:批量运行目录内脚本(递归;支持 `includeEntries/maxEntries` 控制输出)
|
|
54
|
+
- `generate_test_from_doc`:从文档(本地/URL)生成可执行脚本
|
|
55
|
+
- `inspect_failure`:查看最近一次失败的屏幕与错误
|
|
56
|
+
|
|
57
|
+
### recording(可选)
|
|
58
|
+
|
|
59
|
+
- `start_script_recording` / `stop_script_recording`:录制 MCP 工具调用并导出可复跑脚本(JSON + goldens)
|
|
60
|
+
- `mark`:在 trace 中打点(asciicast marker event)
|
|
61
|
+
|
|
62
|
+
`mask`(可选):`snapshot_text/snapshot_ansi/snapshot_view/snapshot_view_ansi` 支持 `mask=[{regex,flags?,replacement?,preserveLength?}]`,用于把随机 id/时间戳等变成可 diff 的稳定快照
|
|
63
|
+
|
|
64
|
+
### `press_key` Key Spec
|
|
65
|
+
|
|
66
|
+
支持单键与“修饰键 + 单键”的组合写法(大小写不敏感,`+`/`-` 都可作为分隔符):
|
|
67
|
+
- 单字符:`"a"` / `"?"`(原样写入 PTY)
|
|
68
|
+
- 特殊键:`Enter|Return`、`Esc|Escape`、`Backspace`、`Space`、`Tab`、`BackTab`
|
|
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`)
|
|
72
|
+
|
|
73
|
+
## Tests
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
bun test
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
包含:
|
|
80
|
+
- PTY + xterm 解析与快照测试
|
|
81
|
+
- MCP server 端到端 smoke(client 通过 stdio 启动 server 并调用 tools)
|
|
82
|
+
|
|
83
|
+
## Use With MCP Clients(可选)
|
|
84
|
+
|
|
85
|
+
本仓库也提供了一个可选的 Codex skill:`skills/ptywright-testing/`,用于指导 Agent 如何用 ptywright MCP/CLI 跑回归并读取 `run.summary.json`(尽量不把超长报告塞进上下文)。
|
|
86
|
+
|
|
87
|
+
本项目是一个 stdio transport 的 MCP server。直接启动:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# 默认等价 `ptywright mcp`
|
|
91
|
+
bun run bin/ptywright
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
也可以用 Streamable HTTP 启动(默认 endpoint: `http://127.0.0.1:3000/mcp`):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
bun run bin/ptywright mcp-http --port 3000
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
然后在你使用的 MCP client 里把它作为一个 stdio server 配置进去即可(不同 client 的配置方式不同)。
|
|
101
|
+
|
|
102
|
+
## Script Runner (JSON)
|
|
103
|
+
|
|
104
|
+
把一次 TUI 测试写成 JSON:启动 → 输入 → 等待 → 快照(可 mask)→ 断言,并自动产出 `.cast` + `report.html`。
|
|
105
|
+
|
|
106
|
+
可选:在 JSON 顶部加上 schema(编辑器补全/校验更友好):
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{ "$schema": "../schemas/ptywright-script.schema.json" }
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
bun run script:run scripts/m5_mask_demo.json
|
|
114
|
+
# 或(CLI)
|
|
115
|
+
bun run bin/ptywright run scripts/m5_mask_demo.json
|
|
116
|
+
# 或
|
|
117
|
+
bun run script:m5-mask-demo
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
批量执行(本地/CI):
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
bun run script:run-all
|
|
124
|
+
# 或(CLI)
|
|
125
|
+
bun run bin/ptywright run-all
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
会生成一个总览报告(类似 Playwright report 首页):
|
|
129
|
+
- 默认:`.tmp/run-all/index.html` + `.tmp/run-all/run.summary.json`
|
|
130
|
+
- 若传入 `--artifacts-root <dir>`:写到 `<dir>/index.html` + `<dir>/run.summary.json`
|
|
131
|
+
|
|
132
|
+
如果 JSON 里用到了 `type:"custom"`,用 `--steps <module.ts>` 注入 handlers(模块导出 `steps` 对象即可):
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
bun run script:run examples/json_custom_steps_demo.json --steps scripts/m6_json_custom_steps.ts
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
产物默认写到 `.tmp/runs/<name>/`(可用 `--artifacts-dir` 覆盖)。
|
|
139
|
+
|
|
140
|
+
失败时会额外落盘:
|
|
141
|
+
- `failure.error.txt`(错误堆栈)
|
|
142
|
+
- `failure.step.json`(失败的 step 信息)
|
|
143
|
+
- `failure.last.txt` / `failure.last.view.txt`(最后一帧快照)
|
|
144
|
+
|
|
145
|
+
`report.html` 现在包含 **Timeline View**,展示每一步操作后的屏幕快照(不仅是失败时)。点击顶部 `debug` badge 可切换到调试视图。
|
|
146
|
+
|
|
147
|
+
Cast Playback(完整录屏)会优先加载 report 同目录的 `asciinema-player.min.js` / `asciinema-player.css`(生成 report 时自动复制),因此离线打开 report 也可播放;若本地资源缺失则会 fallback 到 CDN。
|
|
148
|
+
|
|
149
|
+
内置 steps(无需 `--steps`):
|
|
150
|
+
- `assert`:**[NEW]** 断言文本/正则(`text`/`regex`)
|
|
151
|
+
- `assertSemantic`:**[NEW]** 语义断言占位符(`prompt`)
|
|
152
|
+
- `sleep`:固定等待
|
|
153
|
+
- `expectMeta`:断言终端 meta
|
|
154
|
+
- `waitForExit`:等待进程退出
|
|
155
|
+
- `sendMouse`:发送 SGR 鼠标事件
|
|
156
|
+
|
|
157
|
+
## Script Recording (MCP)
|
|
158
|
+
|
|
159
|
+
如果你设置了 `PTYWRIGHT_CAPS` 且未包含 `recording`,需要开启 `recording`(例如 `PTYWRIGHT_CAPS=core,recording`)。
|
|
160
|
+
|
|
161
|
+
在任意 MCP client/Agent 通过 MCP tools 驱动时,可以一键把工具调用“录成脚本”,并在 `mark` 处自动落盘 golden:
|
|
162
|
+
|
|
163
|
+
1) `start_script_recording(name="my_flow")`
|
|
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`)
|
|
167
|
+
|
|
168
|
+
## Script DSL (TypeScript)
|
|
169
|
+
|
|
170
|
+
用 TS builder 写 script(类型安全,可组合,支持自定义 step),底层仍复用同一个 runner:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
bun run script:run scripts/m6_dsl_demo.ts
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
约定:
|
|
177
|
+
- module 默认导出(`export default`),或导出 `script`。
|
|
178
|
+
- 可选导出 `steps`(custom step handlers),用于执行 `type:"custom"` 的步骤。
|
|
179
|
+
- 常用 handlers 可复用:`src/script/steps/*`。
|
|
180
|
+
- 需要测试“粘贴”时可用 `pasteText("...", { bracketed: true })`(bracketed paste)。
|
|
181
|
+
|
|
182
|
+
## Cast -> SVG/GIF (可选)
|
|
183
|
+
|
|
184
|
+
录像类产物建议只用于失败诊断或人工验收;稳定回归优先用 `snapshot_grid` 做 diff。
|
|
185
|
+
|
|
186
|
+
- SVG: `svg-term`(例如:`bunx svg-term --in <castPath> --out <outSvg>`)
|
|
187
|
+
- TXT: `bun run src/trace/cast_to_txt.ts --in <castPath> --out <outTxt>`
|
|
188
|
+
- GIF: `asciinema/agg`(例如:`agg --fps 30 <castPath> <outGif>`)
|
package/bin/ptywright
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ptywright",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Terminal/TUI automation driver over PTY + xterm, exposed as MCP tools",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agent",
|
|
7
|
+
"automation",
|
|
8
|
+
"mcp",
|
|
9
|
+
"playwright",
|
|
10
|
+
"pty",
|
|
11
|
+
"terminal",
|
|
12
|
+
"testing",
|
|
13
|
+
"tui"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/kingsword09/ptywright/tree/main#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/kingsword09/ptywright/issues"
|
|
18
|
+
},
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"author": "Kingsword kingsword09 <kingsword09@gmail.com>",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/kingsword09/ptywright.git"
|
|
24
|
+
},
|
|
25
|
+
"main": "src/index.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./src/index.ts",
|
|
28
|
+
"./mcp": "./src/mcp/server.ts",
|
|
29
|
+
"./session": "./src/session/terminal_session.ts",
|
|
30
|
+
"./script": "./src/script/runner.ts"
|
|
31
|
+
},
|
|
32
|
+
"bin": {
|
|
33
|
+
"ptywright": "bin/ptywright"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"bin",
|
|
37
|
+
"src",
|
|
38
|
+
"schemas",
|
|
39
|
+
"skills",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"type": "module",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev": "bun run src/index.ts",
|
|
46
|
+
"test": "bun test",
|
|
47
|
+
"test:mcp-all-tools": "bun test tests/mcp_all_tools_smoke.test.ts",
|
|
48
|
+
"lint": "oxlint --type-aware --type-check .",
|
|
49
|
+
"format": "oxfmt src tests '!tests/fixtures/**'",
|
|
50
|
+
"format:check": "oxfmt --check src tests '!tests/fixtures/**'",
|
|
51
|
+
"trace:report": "bun run src/trace/report.ts",
|
|
52
|
+
"trace:cast-to-txt": "bun run src/trace/cast_to_txt.ts",
|
|
53
|
+
"script:run": "bun run src/script/run.ts",
|
|
54
|
+
"script:run-all": "bun run src/script/run_all.ts",
|
|
55
|
+
"script:m5-mask-demo": "bun run src/script/run.ts scripts/m5_mask_demo.json",
|
|
56
|
+
"prepublishOnly": "bun run format:check && bun run lint && bun test"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
60
|
+
"@xterm/headless": "^6.0.0",
|
|
61
|
+
"asciinema-player": "3.9.0",
|
|
62
|
+
"bun-pty": "^0.4.7",
|
|
63
|
+
"zod": "^3.25.76"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"bun-types": "^1.3.6",
|
|
67
|
+
"oxfmt": "^0.24.0",
|
|
68
|
+
"oxlint": "^1.39.0",
|
|
69
|
+
"oxlint-tsgolint": "^0.11.1",
|
|
70
|
+
"typescript": "^5.9.2"
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"bun": ">=1.3.6"
|
|
74
|
+
},
|
|
75
|
+
"packageManager": "bun@1.3.6"
|
|
76
|
+
}
|