Skip to content

fix(cli): render assistant <options> blocks as a numbered list in terminal view - #6

Merged
jacobcoro merged 1 commit into
devfrom
apply-pr197-options-rendering
Sep 5, 2026
Merged

fix(cli): render assistant <options> blocks as a numbered list in terminal view#6
jacobcoro merged 1 commit into
devfrom
apply-pr197-options-rendering

Conversation

@jacobcoro

Copy link
Copy Markdown
Owner

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:

  • New apps/cli/src/utils/optionsParser.ts: shared options-parsing utilities
  • Updated messageFormatterInk.ts: accumulate text blocks and call formatTextWithOptionsForTerminal

…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>
Copilot AI lite review requested due to automatic review settings September 5, 2026 01:36
@jacobcoro
jacobcoro merged commit bcb4034 into dev Sep 5, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 result summary 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 segmentTrailingOptions is “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).
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.

2 participants