fix(cli): render assistant <options> blocks as a numbered list in terminal view - #6
Merged
Merged
Conversation
…minal view Port of happier-dev#197 (romerjon:fix/cli-options-rendering). Cherry-pick conflicted due to our dev diverging from upstream on runGemini.ts, so applied the two functional changes directly: - New apps/cli/src/utils/optionsParser.ts: shared options-parsing utilities including formatTextWithOptionsForTerminal, segmentTrailingOptions, and formatOptionsXml. Replaces the inline logic in the Gemini backend. - Updated messageFormatterInk.ts: accumulate contiguous SDK text blocks into one string before formatting so a trailing <options> block split across adjacent stream fragments is still recognised; call formatTextWithOptionsForTerminal on assistant and result messages. Raw <options> XML is no longer shown in terminal; it renders as a numbered list. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
It introduces new terminal formatting/parsing behavior without targeted unit tests and includes misleading “shared/sole owner” documentation while Gemini still uses a separate options parser.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the CLI terminal rendering so assistant responses ending in an <options>...</options> XML block no longer show raw XML, instead displaying the options as a numbered list.
Changes:
- Added a new shared utility module to detect and parse a turn-final
<options>block and format it for terminal output. - Updated the Ink message formatter to coalesce contiguous assistant text blocks (to handle streamed block boundaries) and apply the terminal options formatting.
- Applied the same terminal options formatting to successful
resultsummary text.
File summaries
| File | Description |
|---|---|
| apps/cli/src/utils/optionsParser.ts | Adds trailing-<options> segmentation and terminal formatting utilities. |
| apps/cli/src/ui/messageFormatterInk.ts | Coalesces streamed text blocks and formats turn-final <options> blocks as a numbered list in terminal output. |
Review details
Suppressed comments (1)
apps/cli/src/utils/optionsParser.ts:67
- This docstring claims
segmentTrailingOptionsis “reused by the terminal formatter AND the Gemini adapter”, but Gemini currently uses a different implementation with different matching rules (apps/cli/src/backends/gemini/utils/optionsParser.ts). Having two parsers undermines the “sole owner” idea; either consolidate the Gemini path onto this module (and delete the duplicate) or make this comment terminal-specific so it stays accurate.
* Canonical trailing-options segmenter — the sole owner of the options-block
* grammar, reused by the terminal formatter AND the Gemini adapter.
*
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+79
to
+83
| export function segmentTrailingOptions(text: string): { | ||
| before: string; | ||
| options: string[]; | ||
| hasIncompleteTrailingOptions: boolean; | ||
| } { |
Comment on lines
+9
to
+11
| * Single regex owning the <option> item grammar, shared by every consumer so the | ||
| * terminal formatter and the Gemini adapter never diverge. | ||
| * Matches one <option>...</option> pair (case-insensitive, non-greedy inner). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of happier-dev#197.
Raw
<options>XML is no longer shown in terminal sessions; it renders as a numbered list.Cherry-pick conflicted due to our dev diverging from upstream on
runGemini.ts, so applied the two functional changes directly:apps/cli/src/utils/optionsParser.ts: shared options-parsing utilitiesmessageFormatterInk.ts: accumulate text blocks and callformatTextWithOptionsForTerminal