Commit c51b1e2
feat: add TUI agent harness with MCP server (#548)
* feat: add TUI harness core library
Headless terminal harness using node-pty + @xterm/headless that spawns
real CLI processes in a PTY and reads screen state programmatically.
Core components:
- TuiSession: spawn, sendKeys, sendSpecialKey, readScreen, waitFor, close
- SettlingMonitor: text-content comparison to filter cursor blink
- Screen reader: viewport/scrollback reading, numbered output
- Key map: named keys to escape sequence mapping
- Session manager: global registry with process-exit cleanup
- Availability check: graceful skip when node-pty is missing
waitFor() throws WaitForTimeoutError on timeout (not silent return).
launch() races settle vs process exit, throws LaunchError on crash.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add MCP server for TUI harness
7 MCP tools exposed via stdio transport for AI agents to drive the TUI:
tui_launch, tui_send_keys, tui_read_screen, tui_wait_for,
tui_screenshot, tui_close, tui_list_sessions.
Session map with max 10 concurrent sessions. tui_wait_for catches
WaitForTimeoutError and returns {found: false} (not an MCP error).
tui_launch defaults to AgentCore CLI when no command specified.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: add dependencies and build config for TUI harness
- devDependencies: @xterm/headless, @modelcontextprotocol/sdk
- optionalDependencies: node-pty (native addon, graceful skip)
- esbuild: second entry point for mcp-harness bundle
- vitest: new 'tui' project with fileParallelism: false
- .mcp.json: MCP server discovery for Claude Code
- package.json: bin entry + test:tui script
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: add TUI harness documentation
AGENTS.md: TUI harness section with MCP tool reference, complete 27-step
create wizard example (verified against real TUI), screen identification
markers table, screenshot format, error recovery patterns, navigation
patterns, and known limitations.
TESTING.md: TUI integration test guide with TuiSession API reference,
ScreenState type, special keys list, waitFor vs settling guidance,
WaitForTimeoutError output example, and LaunchError handling.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor: consolidate TUI harness into src/tui-harness/
Move harness code from two separate directories (src/test-utils/tui-harness/
and src/mcp-harness/) into a single src/tui-harness/ directory with lib/ and
mcp/ subdirectories. Also cleans up dead code in tools.ts, derives SpecialKey
type from SPECIAL_KEY_VALUES array (single source of truth), and fixes
cross-boundary import of createMinimalProjectDir.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: make TUI harness build opt-in for dev only
The harness is dev-only tooling for AI agents and integration tests.
It should not ship to end users who install the CLI.
- Gate MCP harness esbuild behind BUILD_HARNESS=1 env var
- Remove agent-tui-harness bin entry from package.json
- Add !dist/mcp-harness to files array (npm publish exclusion)
- Remove node-pty from optionalDependencies (stays in devDependencies)
- Add build:harness script, update test:tui to use it
- Update AGENTS.md to reference npm run build:harness
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: move TUI harness guide from AGENTS.md to docs/tui-harness.md
Reduces AGENTS.md context overhead for agents that don't need TUI harness
details. Leaves a one-line pointer to the full guide in docs/.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* style: fix prettier formatting in AGENTS.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* style: rename TuiSession.ts to kebab-case tui-session.ts
Aligns with the kebab-case convention used by other files in
src/tui-harness/lib/.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jesse Turner <ajesstur@amazon.com>
Co-authored-by: Jesse Turner <57651174+jesseturner21@users.noreply.github.com>1 parent c2c646c commit c51b1e2
22 files changed
Lines changed: 3785 additions & 3 deletions
File tree
- docs
- integ-tests/tui
- src/tui-harness
- __tests__
- lib
- mcp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
128 | 350 | | |
129 | 351 | | |
130 | 352 | | |
131 | 353 | | |
132 | 354 | | |
133 | 355 | | |
| 356 | + | |
134 | 357 | | |
135 | 358 | | |
136 | 359 | | |
| |||
0 commit comments