Skip to content

fix(q-cli): Handle percentage in agent prompt pattern#4

Merged
tuanknguyen merged 1 commit into
awslabs:mainfrom
anillohchab:fix/q-cli-percentage-prompt
Oct 10, 2025
Merged

fix(q-cli): Handle percentage in agent prompt pattern#4
tuanknguyen merged 1 commit into
awslabs:mainfrom
anillohchab:fix/q-cli-percentage-prompt

Conversation

@anillohchab

@anillohchab anillohchab commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Problem

The Q CLI provider's idle prompt pattern didn't account for the percentage display in prompts when chat.enableContextUsageIndicator is enabled (e.g., [developer] 2% >), causing handoff operations to timeout.

Root Cause

Q CLI wraps the percentage display in its own ANSI color codes (\x1b[38;5;10m2%). The original pattern expected plain text between the agent name and arrow, but Q CLI adds green color codes around the percentage.

Solution

Updated _idle_prompt_pattern to handle ANSI color codes around the percentage:
python

Before: Expected plain text percentage

rf'\x1b[38;5;14m{agent}\ ?:\s+\d+%?\s*...'

After: Expects ANSI-wrapped percentage

rf'\x1b[38;5;14m[{agent}]\s*(?:\x1b[38;5;10m\d+%\s*)?...'

Testing

  • ✅ Tested with percentage enabled ([developer] 2% >) - handoff completes in ~12s
  • ✅ Tested without percentage ([developer] >) - handoff completes in ~10s
  • ✅ Compatible with error prompts ([developer] !>) from upstream
  • ✅ Compatible with error + percentage ([developer] 5% !>)

Changes

  • Modified src/cli_agent_orchestrator/providers/q_cli.py:
    • Updated _idle_prompt_pattern to handle ANSI codes around percentage
    • Added explanatory comment about ANSI codes

Related

This fix maintains compatibility with the error prompt feature added in the upstream main branch.

@anillohchab anillohchab force-pushed the fix/q-cli-percentage-prompt branch 2 times, most recently from 307d0d4 to 1c2a1db Compare October 9, 2025 18:38
Update idle_prompt_pattern to support optional percentage display in Q CLI
prompts (e.g., [developer] 2% > in addition to [developer] >).

This fixes handoff timeout issues where the status detection failed to
recognize COMPLETED state when the prompt included a percentage indicator.

- Added (?:\s+\d+%)? to match optional space + digits + % in prompt
- Tested with both [agent] > and [agent] X% > formats
- Handoff now completes in ~10s instead of timing out at 60s

🤖 Assisted by Amazon Q Developer (https://aws.amazon.com/q/developer)
@anillohchab anillohchab force-pushed the fix/q-cli-percentage-prompt branch from 1c2a1db to 2d7d209 Compare October 9, 2025 20:51
@haofeif haofeif requested a review from tuanknguyen October 9, 2025 23:54
@tuanknguyen tuanknguyen merged commit c4bb2a2 into awslabs:main Oct 10, 2025
abdullahoff added a commit that referenced this pull request Apr 2, 2026
…l display, status accuracy, Ralph UI

Bug #3: Added AI-Powered Bead Creation with textarea and Generate Beads button
Bug #4: Added Context Monitor showing context usage (Xk ctx) in session cards
Bug #5: Added Model Display showing model name in session cards
Bug #10: Improved status detection in TerminalView with spinner pattern detection
Bug #12: Added Ralph Loop UI with PRD textarea and configuration inputs

All 10 bugs now have implementations.
haofeif added a commit that referenced this pull request Apr 9, 2026
- 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>
haofeif added a commit that referenced this pull request Apr 10, 2026
…159) (#163)

* feat(kiro_cli): add full TUI mode support with --legacy-ui fallback (#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>

* style: apply black formatting to kiro_cli provider and tests

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

* fix(kiro_cli): address PR #163 review comments

- 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>

* feat(kiro_cli): add TUI processing and permission detection patterns

- 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>

* fix(kiro_cli): update TUI idle pattern to match real kiro-cli v1.29+ 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>

* fix(kiro_cli): use forward-search for TUI separator to handle agent output 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>

* fix(test): add 'Kiro is working' ghost text to TUI processing fixture (#159)

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants