Skip to content

feat(kiro_cli): add full TUI mode support with --legacy-ui fallback (#159)#163

Merged
haofeif merged 8 commits into
mainfrom
fix/kiro-tui-mode
Apr 10, 2026
Merged

feat(kiro_cli): add full TUI mode support with --legacy-ui fallback (#159)#163
haofeif merged 8 commits into
mainfrom
fix/kiro-tui-mode

Conversation

@haofeif

@haofeif haofeif commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Title

feat(kiro_cli): add full TUI mode support with --legacy-ui fallback (#159)

Summary

  • Remove hardcoded --legacy-ui from the Kiro CLI launch command — the provider now launches in TUI mode by default and auto-detects the output format
  • Add ▸ Credits: completion marker detection for TUI mode (TUI_CREDITS_PATTERN) alongside existing green arrow detection for legacy mode
  • Add separator-based message extraction (_extract_tui_message()) as fallback when no green arrows are found in pure TUI output
  • Add --legacy-ui retry fallback in initialize() — if TUI init times out, the provider sends /exit and retries with --legacy-ui automatically
  • Add "aren't available" to e2e REFUSAL_KEYWORDS to fix a Claude Code test false positive

What changed

src/cli_agent_orchestrator/providers/kiro_cli.py

Change Details
New patterns TUI_SEPARATOR_PATTERN = r"^[─]{4,}$", TUI_CREDITS_PATTERN = r"▸\s*Credits:\s*[\d.]+"
initialize() TUI-first launch → /exit + --legacy-ui fallback on timeout
get_status() Credits + idle prompt after it → COMPLETED; Credits without idle → PROCESSING
_extract_tui_message() New method: finds last separator before ▸ Credits:, skips user message paragraph, extracts agent response
extract_last_message_from_script() Falls back to _extract_tui_message() when no green arrows found

Status detection flow (updated)

No output           → ERROR
No idle prompt      → PROCESSING
Error indicators    → ERROR
Permission prompt   → WAITING_USER_ANSWER
Green arrow + idle  → COMPLETED  (legacy path)
Credits + idle      → COMPLETED  (TUI path)
Credits, no idle    → PROCESSING (TUI still rendering)
Idle only           → IDLE

test/providers/test_kiro_cli_unit.py

  • Updated test_initialize_success — asserts kiro-cli chat --agent developer (no --legacy-ui)
  • Updated test_initialize_kiro_cli_timeout — expects "both TUI and --legacy-ui failed"
  • Added test_initialize_legacy_ui_fallback — verifies TUI fail → /exit--legacy-ui retry
  • Added TestKiroCliTuiMode class (11 tests):
    • Idle, completed, processing detection from TUI fixtures
    • Message extraction (basic + complex with code blocks)
    • Error cases (no Credits, no separator)
    • Credits without idle = PROCESSING
    • Status-extraction synchronization guarantee

test/providers/fixtures/ (4 new files)

  • kiro_cli_tui_idle_output.txt — separator + header + idle prompt
  • kiro_cli_tui_completed_output.txt — user msg + agent response + Credits + idle
  • kiro_cli_tui_processing_output.txt — no idle prompt visible
  • kiro_cli_tui_complex_response.txt — code blocks, multiple paragraphs + Credits

docs/kiro-cli.md

  • Updated launch command (no --legacy-ui by default)
  • Documented dual-path extraction (green arrows first, TUI separator/Credits fallback)
  • Documented auto-detection and backward compatibility with --legacy-ui wrappers

test/e2e/test_allowed_tools.py

  • Added "aren't available" to REFUSAL_KEYWORDS (fixes Claude Code test_reviewer_cannot_write false positive)

Test plan

  • Unit tests: 69/69 passed (including 12 new tests)
  • Full non-e2e suite: 1106/1106 passed
  • Kiro CLI e2e: 11/11 passed in TUI mode (11m19s)
  • Verify --legacy-ui fallback triggers correctly when TUI is unavailable (e.g., older kiro-cli version)

Closes #159

…159)

Remove hardcoded --legacy-ui from launch command and add TUI-native
status detection and message extraction. The provider now:

- Launches in TUI mode by default, falls back to --legacy-ui on timeout
- Detects COMPLETED via ▸ Credits: marker + idle prompt (TUI path)
- Extracts messages using separator (────) boundaries when no green arrows
- Retains full backward compatibility with legacy UI patterns

Also adds "aren't available" to e2e REFUSAL_KEYWORDS for Claude Code test fix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@haofeif haofeif requested a review from a team April 8, 2026 05:25
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@haofeif haofeif added the enhancement New feature or request label Apr 8, 2026
Ask a question or describe a task

Strategy:
1. Find the last Credits line (response end marker)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be simplified by detecting the ghost text "Kiro is working" present in the user prompt space? Unless waiting for a tool permission, the "Kiro is working" text is always present when the agent is not idle. When a permission request appears the text changes to Yes, No and Always Allow for this session.

Ghost text

Image

Tool permission

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented — added TUI_PROCESSING_PATTERN = r'Kiro is working' as a positive PROCESSING signal (checked first in get_status()), and TUI_PERMISSION_PATTERN = r'Yes\s+No\s+Always [Aa]llow' for TUI permission prompt detection that triggers WAITING_USER_ANSWER. Both are in the latest commits.

return TerminalStatus.PROCESSING

# Check 5: TUI completion — Credits marker + idle prompt after it.
# In pure TUI mode, there are no green arrows. Completion is indicated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kiro in TUI mode allows queuing messages while the agent is working. The prompt remains in the queue until the current loop completes. It is similar to the current behaviour. Maybe exact checks for agent completion can be relaxed in the future and leverage the in-built functionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwalaQ Acknowledged — thanks for the insight on native queuing. CAO currently requires a strict send → wait for COMPLETED → extract response cycle across all providers (including Claude Code, which also supports native queuing). This is because CAO needs to extract each response to return it via the API, route it between agents (handoffs/assigns), and store conversation history. Relaxing completion checks would require a new CAO-level API contract (e.g., fire-and-forget with async response collection), which is a broader architectural change beyond this PR. Noted as a potential future optimization.

Also cao at the moment do not support "queuing message" for any providers, including Claude code, which by itself supports queuing messages long ago.

Comment thread test/providers/test_kiro_cli_unit.py Outdated
Comment thread src/cli_agent_orchestrator/providers/kiro_cli.py
Comment thread src/cli_agent_orchestrator/providers/kiro_cli.py Outdated
haofeif and others added 3 commits April 9, 2026 10:01
- Raise separator minimum from 4 to 20 chars to avoid matching short
  markdown separators in agent output (jwalaQ comment #4)
- Remove redundant ANSI cleanup in _extract_tui_message — input is
  already ANSI-stripped by caller (jwalaQ comment #5)
- Improve timeout error message wording (jwalaQ comment #3)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add "Kiro is working" ghost text as positive PROCESSING signal,
  checked before idle prompt absence (jwalaQ comment #1)
- Add TUI permission pattern "Yes No Always Allow" alongside legacy
  [y/n/t] format, requires all three options to avoid false positives
  on bare "Yes"/"No" in agent output (jwalaQ comment #2)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…output

Verified against real kiro-cli v1.29.1 TUI output via tmux capture-pane:
- Idle prompt is "Ask a question or describe a task" (capital A, no comma)
- Pattern now accepts both old (lowercase, comma) and new formats
- Updated fixtures to use real TUI output format
- Updated inline test strings to match v1.29+ output

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@haofeif haofeif requested a review from jwalaQ April 9, 2026 01:48
@haofeif

haofeif commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

@jwalaQ thanks very much for you looking into this, can you please review again, i believe your comments are addressed.

haofeif and others added 2 commits April 9, 2026 18:11
…utput separators (#159)

Changed _extract_tui_message() to find the first separator after the
previous turn's Credits line instead of the last separator before the
current Credits. This prevents false matches when agent output contains
box-drawing separator characters. Also updated docs for launch command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
────────────────────────────────────────────────────
What files are in this directory?

Analyzing the directory structure...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the "Kiro is working" ghost text here as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @jwalaQ thanks for your review

…#159)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@haofeif haofeif merged commit a9fdfdf into main Apr 10, 2026
4 checks passed
@haofeif haofeif deleted the fix/kiro-tui-mode branch April 10, 2026 08:40
@jwalaQ

jwalaQ commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI Mode Support for kiro_cli Provider

2 participants