Skip to content

Fix: Make Q CLI Prompt Pattern Matching ANSI color-agnostic#18

Merged
haofeif merged 1 commit into
awslabs:mainfrom
nitin-k:main
Nov 6, 2025
Merged

Fix: Make Q CLI Prompt Pattern Matching ANSI color-agnostic#18
haofeif merged 1 commit into
awslabs:mainfrom
nitin-k:main

Conversation

@nitin-k

@nitin-k nitin-k commented Oct 31, 2025

Copy link
Copy Markdown
Contributor
  • Strip ANSI codes before pattern matching to handle color variations
  • Update idle and permission prompt patterns to be color-free
  • Add debug logging for pattern matching troubleshooting
  • Fixes timeout issues caused by color code mismatches in prompts

@haofeif haofeif requested a review from a team November 1, 2025 03:22
Comment thread src/cli_agent_orchestrator/providers/q_cli.py Outdated
Comment thread src/cli_agent_orchestrator/providers/q_cli.py Outdated
Comment thread src/cli_agent_orchestrator/providers/q_cli.py Outdated

@anilkmr-a2z anilkmr-a2z left a comment

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.

Instead of creating a new commit, could we just amend the original commit ? Its unnecessary to have "remove debug statements" in remote history ?

@nitin-k

nitin-k commented Nov 3, 2025

Copy link
Copy Markdown
Contributor Author

Instead of creating a new commit, could we just amend the original commit ? Its unnecessary to have "remove debug statements" in remote history ?

Yep, done.

@anilkmr-a2z anilkmr-a2z left a comment

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.

Thanks for updating it based on the comments.

@haofeif

haofeif commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

@nitin-k mind resolving the conflict ?

@nitin-k

nitin-k commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

Looks like there are plenty of changes happened on the main branch :(
I need to investigate why the tests are failing.

@haofeif

haofeif commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

Looks like there are plenty of changes happened on the main branch :( I need to investigate why the tests are failing.

@nitin-k take your time to investigate.

@gutosantos82 maybe able to provide some guidance per the failure.

@gutosantos82

Copy link
Copy Markdown
Contributor

Test Failures - Incomplete ANSI-Agnostic Implementation

The 16 failing tests reveal that extract_last_message_from_script() was not updated to use the new ANSI-agnostic approach.

The Issue

get_status() correctly strips ANSI codes before pattern matching:
python
clean_output = re.sub(ANSI_CODE_PATTERN, '', output)
has_idle_prompt = re.search(self._idle_prompt_pattern, clean_output) # ✅

But extract_last_message_from_script() searches raw output with ANSI codes:
python
idle_prompts = list(re.finditer(self._idle_prompt_pattern, script_output)) # ❌

The pattern expects [developer]> but raw output is \x1b[36m[developer]\x1b[35m>\x1b[39m.

Fix Needed

Strip ANSI codes before pattern matching, then map the clean position back to raw output for extraction (to preserve the original message with any formatting).

- Strip ANSI codes before pattern matching to handle color variations
- Update idle and permission prompt patterns to be color-free
- Add debug logging for pattern matching troubleshooting
- Fixes timeout issues caused by color code mismatches in prompts
@nitin-k

nitin-k commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

@gutosantos82 Thanks for your comment.

I fixed the feature and updated some tests accordingly.

@haofeif haofeif merged commit d772966 into awslabs:main Nov 6, 2025
5 checks passed
haofeif added a commit that referenced this pull request Feb 9, 2026
…t stabilization

Three bugs fixed in Gemini CLI provider (lessons #16, #17, #18):

1. Ink TUI keeps idle prompt visible during processing — added
   PROCESSING_SPINNER_PATTERN (Braille dots + "esc to cancel") check
   in get_status() to avoid premature COMPLETED when MCP tools are
   still executing.

2. Premature COMPLETED between text output and MCP tool call — replaced
   sequential wait_for_status + terminal count check with combined
   _wait_for_supervisor_done() polling in supervisor E2E tests.

3. Ink TUI shows idle prompt before -i prompt is processed — added
   _uses_prompt_interactive flag so initialize() waits for COMPLETED
   (not IDLE) when -i is used, preventing lost messages.

E2E test improvements across all providers:
- Accept both "idle" and "completed" as valid post-initialization states
- Add stabilization delay after COMPLETED detection in handoff/assign tests
- Add missing get_terminal_status import in test_handoff.py

E2E results: 13/14 pass (7/7 Gemini, 6/7 Codex — 1 pre-existing Codex
supervisor_assign output extraction failure).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
haofeif added a commit that referenced this pull request Feb 9, 2026
…t stabilization

Three bugs fixed in Gemini CLI provider (lessons #16, #17, #18):

1. Ink TUI keeps idle prompt visible during processing — added
   PROCESSING_SPINNER_PATTERN (Braille dots + "esc to cancel") check
   in get_status() to avoid premature COMPLETED when MCP tools are
   still executing.

2. Premature COMPLETED between text output and MCP tool call — replaced
   sequential wait_for_status + terminal count check with combined
   _wait_for_supervisor_done() polling in supervisor E2E tests.

3. Ink TUI shows idle prompt before -i prompt is processed — added
   _uses_prompt_interactive flag so initialize() waits for COMPLETED
   (not IDLE) when -i is used, preventing lost messages.

E2E test improvements across all providers:
- Accept both "idle" and "completed" as valid post-initialization states
- Add stabilization delay after COMPLETED detection in handoff/assign tests
- Add missing get_terminal_status import in test_handoff.py

E2E results: 13/14 pass (7/7 Gemini, 6/7 Codex — 1 pre-existing Codex
supervisor_assign output extraction failure).

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.

4 participants