@@ -124,240 +124,4 @@ See `docs/TESTING.md` for details.
124124
125125## TUI Harness
126126
127- The TUI harness provides MCP tools for programmatically driving the AgentCore CLI terminal UI. The MCP server lives at
128- ` src/mcp-harness/ ` and the underlying library is at ` src/test-utils/tui-harness/ ` .
129-
130- ### Getting Started
131-
132- 1 . Run ` npm run build:harness ` to compile both the CLI and the MCP harness binary. The harness is dev-only tooling and
133- is not included in the standard ` npm run build ` .
134- 2 . Call ` tui_launch ` to start a TUI session. It returns a ` sessionId ` that all subsequent tool calls require.
135- - ` tui_launch({}) ` with no arguments defaults to ` command="node" ` , ` args=["dist/cli/index.mjs"] ` (the AgentCore CLI).
136- - The ` cwd ` parameter determines what the TUI sees: if ` cwd ` is a directory with an ` agentcore.config.json ` , the TUI
137- opens to the HelpScreen (command list). If ` cwd ` has no project, it opens to the HomeScreen ("No AgentCore project
138- found").
139- 3 . Common workflow: ** launch** -> ** navigate** -> ** verify** -> ** close** .
140-
141- ### MCP Tools
142-
143- - ` tui_launch ` -- Start a TUI session (defaults to AgentCore CLI if no command specified). Returns a ` sessionId ` used by
144- all other tools.
145- - ` tui_send_keys ` -- Send text or special keys (enter, tab, escape, arrow keys, ctrl+c, etc.).
146- - ` tui_read_screen ` -- Read current screen content. Options: ` numbered: true ` adds line numbers (useful for referencing
147- specific UI elements), ` includeScrollback: true ` includes lines scrolled above the viewport.
148- - ` tui_wait_for ` -- Wait for text or a regex pattern to appear on screen. Returns ` {found: false} ` on timeout, NOT an
149- error.
150- - ` tui_screenshot ` -- Capture a bordered screenshot with line numbers.
151- - ` tui_close ` -- Close a session and terminate the underlying process.
152- - ` tui_list_sessions ` -- List all active sessions.
153-
154- ### Screenshot Format
155-
156- ` tui_screenshot ` returns a bordered capture with line numbers:
157-
158- ```
159- ┌─ TUI Screenshot (120x40) ────────────────────────────────────────┐
160- 1 |
161- 2 | >_ AgentCore v0.3.0-preview.5.0
162- 3 |
163- 4 | >
164- 5 |
165- 6 | No AgentCore project found in this directory.
166- 7 |
167- 8 | You can:
168- 9 | create - Create a new AgentCore project here
169- 10 | or cd into an existing project directory
170- 11 |
171- 12 | Press Enter to create a new project
172- ...
173- └──────────────────────────────────────────────────────────────────┘
174- ```
175-
176- The response also includes metadata: cursor position, terminal dimensions, buffer type, and timestamp. Use line numbers
177- when referencing specific UI elements in your reasoning.
178-
179- ### Screen Identification Markers
180-
181- Use these stable text patterns with ` tui_wait_for ` to identify which screen is currently displayed.
182-
183- | Screen | Stable Text Marker | Notes |
184- | ------------------------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------- |
185- | HomeScreen (no project) | ` No AgentCore project found ` | Only shown when no project exists |
186- | HelpScreen (command list) | ` Commands ` or ` Type to filter ` | Main command list with project |
187- | CreateScreen (name input) | ` Project name ` | Text input for project name |
188- | CreateScreen (add agent prompt) | ` add an agent ` | "Would you like to add an agent now?" Yes/No |
189- | AddAgent (name) | ` Agent name ` | Text input with default "MyAgent" |
190- | AddAgent (type) | ` agent type ` | "Create new agent" vs "Bring my own code" |
191- | AddAgent (language) | ` Python ` | Language selection (TypeScript is "coming soon" / disabled) |
192- | AddAgent (build type) | ` Direct Code Deploy ` | "Direct Code Deploy" vs "Container" |
193- | AddAgent (framework) | ` Strands Agents SDK ` | Strands, LangChain, Google ADK, OpenAI Agents |
194- | AddAgent (model provider) | ` Amazon Bedrock ` | Bedrock, Anthropic, OpenAI, Google Gemini |
195- | AddAgent (memory) | ` No memory ` | None, Short-term, Long-term (only for Strands) |
196- | AddAgent (confirm) | ` Review Configuration ` | Summary of all selections before creating |
197- | CreateScreen (running) | ` [done] ` | Progress steps. Use ` tui_wait_for("created successfully") ` |
198- | CreateScreen (complete) | ` created successfully ` | Stable end state |
199- | AddScreen (resource types) | ` Add Resource ` | Agent, Memory, Identity, Gateway, Gateway Target |
200- | DeployScreen (confirm) | ` Deploy ` + ` confirm ` | Confirmation prompt |
201- | DeployScreen (loading) | Spinner (unstable) | Use ` tui_wait_for ` for specific completion text |
202- | Error state | ` Error ` or ` failed ` | Error messages |
203- | Selected list item | ` > ` cursor | Cursor indicator in any selection list |
204- | Text input active | ` > ` prompt | Input cursor in any text input field |
205- | Commands list items | ` add ` , ` dev ` , ` deploy ` , ` create ` , ` invoke ` , ` remove ` , ` status ` , ` validate ` | Individual command names visible in HelpScreen list |
206- | Exit prompt | ` Press Esc again to exit ` | Shown after first Escape on HelpScreen with no search query |
207-
208- ### Example: Create Project with Agent (Full Wizard)
209-
210- The create wizard embeds the full AddAgent flow. Here is every step captured from a real TUI session:
211-
212- ```
213- 1. tui_launch({cwd: "/path/to/empty/dir"})
214- -> Returns sessionId. Screen shows HomeScreen.
215-
216- 2. tui_wait_for({sessionId, pattern: "No AgentCore project found", timeoutMs: 10000})
217- -> Confirms HomeScreen loaded.
218-
219- 3. tui_send_keys({sessionId, specialKey: "enter"})
220- -> Navigates to CreateScreen.
221-
222- 4. tui_wait_for({sessionId, pattern: "Project name"})
223- -> CreateScreen: name input.
224-
225- 5. tui_send_keys({sessionId, keys: "my-agent"})
226- -> Types the project name.
227-
228- 6. tui_send_keys({sessionId, specialKey: "enter"})
229- -> Submits name. Moves to "add an agent?" prompt.
230-
231- 7. tui_wait_for({sessionId, pattern: "add an agent"})
232- -> "Would you like to add an agent now?" with Yes/No options.
233-
234- 8. tui_send_keys({sessionId, specialKey: "enter"})
235- -> Selects "Yes". Moves to Agent name input.
236-
237- 9. tui_wait_for({sessionId, pattern: "Agent name"})
238- -> Agent name input (default: "MyAgent").
239-
240- 10. tui_send_keys({sessionId, specialKey: "enter"})
241- -> Accepts default name. Moves to agent type selection.
242-
243- 11. tui_wait_for({sessionId, pattern: "agent type"})
244- -> "Create new agent" vs "Bring my own code".
245-
246- 12. tui_send_keys({sessionId, specialKey: "enter"})
247- -> Selects "Create new agent". Moves to language.
248-
249- 13. tui_wait_for({sessionId, pattern: "Python"})
250- -> Language selection. Note: "TypeScript (coming soon)" is disabled.
251-
252- 14. tui_send_keys({sessionId, specialKey: "enter"})
253- -> Selects Python. Moves to build type.
254-
255- 15. tui_wait_for({sessionId, pattern: "Direct Code Deploy"})
256- -> "Direct Code Deploy" vs "Container".
257-
258- 16. tui_send_keys({sessionId, specialKey: "enter"})
259- -> Selects Direct Code Deploy. Moves to framework.
260-
261- 17. tui_wait_for({sessionId, pattern: "Strands Agents SDK"})
262- -> Framework: Strands, LangChain, Google ADK, OpenAI Agents.
263-
264- 18. tui_send_keys({sessionId, specialKey: "enter"})
265- -> Selects Strands. Moves to model provider.
266-
267- 19. tui_wait_for({sessionId, pattern: "Amazon Bedrock"})
268- -> Model: Bedrock, Anthropic, OpenAI, Google Gemini.
269-
270- 20. tui_send_keys({sessionId, specialKey: "enter"})
271- -> Selects Bedrock. Skips API key (Bedrock uses IAM). Moves to memory.
272-
273- 21. tui_wait_for({sessionId, pattern: "No memory"})
274- -> Memory: None, Short-term, Long-term (Strands-only step).
275-
276- 22. tui_send_keys({sessionId, specialKey: "enter"})
277- -> Selects None. Moves to review.
278-
279- 23. tui_wait_for({sessionId, pattern: "Review Configuration"})
280- -> Summary panel showing all selections.
281-
282- 24. tui_send_keys({sessionId, specialKey: "enter"})
283- -> Confirms. Project creation begins (~25 seconds).
284-
285- 25. tui_wait_for({sessionId, pattern: "created successfully", timeoutMs: 60000})
286- -> Wait for completion. Use a long timeout (creation runs uv sync).
287-
288- 26. tui_screenshot({sessionId})
289- -> Capture success screen showing created file structure.
290-
291- 27. tui_close({sessionId})
292- -> Clean shutdown. Returns exitCode: 0.
293- ```
294-
295- Notes:
296-
297- - Step 20: If you select a non-Bedrock provider (Anthropic, OpenAI, Gemini), an API key input step appears between model
298- selection and memory.
299- - Step 21: The memory step only appears when Strands SDK is selected as the framework.
300- - Step 25: Project creation takes ~ 25 seconds due to ` uv sync ` . The ` timeoutMs ` cap for ` tui_wait_for ` is 30000, so use
301- 30000 or call it in a loop.
302-
303- ### Example: Navigate to Add Resource
304-
305- ```
306- 1. tui_launch({cwd: "/path/to/existing/project"})
307- -> HelpScreen with command list.
308-
309- 2. tui_wait_for({sessionId, pattern: "Commands"})
310- -> Confirms HelpScreen loaded.
311-
312- 3. tui_send_keys({sessionId, keys: "add"})
313- -> Filters command list to "add".
314-
315- 4. tui_send_keys({sessionId, specialKey: "enter"})
316- -> Navigates to AddScreen.
317-
318- 5. tui_wait_for({sessionId, pattern: "Add Resource"})
319- -> Shows: Agent, Memory, Identity, Gateway, Gateway Target.
320- ```
321-
322- ### Known Limitations
323-
324- 1 . ** Disabled items are invisible** : In selection lists, disabled items are shown only with dimmed color (ANSI). The
325- harness strips ANSI codes and returns plain text, so disabled items look identical to enabled ones. If pressing Enter
326- on a list item does not navigate to a new screen, the item may be disabled -- try a different item.
327- 2 . ** Spinner screens do not settle** : Screens with spinners (deploy progress, create running) continuously change text
328- content. Do not wait for the screen to "settle" -- use ` tui_wait_for ` with the specific text that indicates
329- completion (e.g., ` "created successfully" ` , ` "Deploy complete" ` ).
330- 3 . ** Max 10 concurrent sessions** : The harness allows up to 10 simultaneous TUI sessions. Close sessions when done.
331-
332- ### Navigation Patterns
333-
334- - ** Navigate to a command** : From HelpScreen, type the command name to filter, then press Enter. Or use arrow keys to
335- reach it, then Enter.
336- - ** Fill text input** : Type characters with ` tui_send_keys({keys: "..."}) ` , then press Enter to submit.
337- - ** Select from list** : Arrow down to the target item, then press Enter.
338- - ** Go back** : Press Escape.
339- - ** Exit app** : Press Escape until at HelpScreen, then Escape twice (or Ctrl+C from anywhere).
340- - ** Slow-rendering screens** : If a screen takes time to fully render, pass ` waitMs: 1000 ` (or higher) to ` tui_send_keys `
341- to give the screen more time to settle before reading it.
342-
343- ### Error Recovery
344-
345- When ` tui_wait_for ` returns ` {found: false} ` :
346-
347- 1 . Call ` tui_screenshot ` to see what's actually on screen.
348- 2 . Check if the screen has an error message (look for "Error" or "failed").
349- 3 . If the screen is still loading (spinner), increase ` timeoutMs ` and retry.
350- 4 . If you're on the wrong screen, use ` tui_send_keys({specialKey: "escape"}) ` to go back and try a different navigation
351- path.
352-
353- When ` tui_send_keys ` doesn't change the screen:
354-
355- 1 . Call ` tui_read_screen ` to check the current state.
356- 2 . The selected item may be disabled (see Known Limitations).
357- 3 . Try pressing Escape and navigating to a different item.
358-
359- When ` tui_launch ` returns an error:
360-
361- 1 . Ensure ` npm run build:harness ` was run recently -- both the CLI binary and the MCP harness must be up to date.
362- 2 . Check that ` cwd ` points to a valid directory.
363- 3 . The error response includes the screen content at time of failure -- use it to diagnose.
127+ See ` docs/tui-harness.md ` for the full TUI harness usage guide (MCP tools, screen markers, examples, and error recovery).
0 commit comments