Skip to content

TUI: question/ask prompt renders one word per line when model emits carriage returns #36040

Description

@qingshanyuluo

Summary

When the agent uses the interactive question/ask tool, some model providers emit carriage-return (\r) characters inside the question header, question body, and option label/description. The TUI's opentui renderer treats a bare \r as a hard line break, so the prompt renders with nearly every word on its own line.

What happens

The question and its options become almost unreadable — each word (or CJK segment) wraps to a separate line, e.g.:

定位
换行
问题

TUI
里我输入
/粘贴的文字

instead of:

定位换行问题
TUI 里我输入/粘贴的文字

Root cause

Question strings flow from the model tool call through Question.ask (packages/opencode/src/question/index.ts), which publishes the question.asked event consumed by every render surface:

  • TUI: packages/tui/src/context/sync.tsxpackages/tui/src/routes/session/question.tsx
  • CLI footer: packages/opencode/src/cli/cmd/run/session-data.tspackages/opencode/src/cli/cmd/run/footer.question.tsx
  • Web: packages/app/src/pages/session/composer/session-question-dock.tsx
  • Scrollback: packages/opencode/src/cli/cmd/run/scrollback.writer.tsx

There is no \r normalization anywhere in this chain. Notably, the user's own prompt textarea already normalizes CRLF (packages/tui/src/component/prompt/index.tsx), but question content coming from the model was never sanitized. The opentui text buffer receives the raw bytes and each \r-separated token wraps to its own line.

Expected

\r characters from model-provided question text should be normalized before the data is stored/broadcast, so the prompt renders normally. Intentional newlines in the multi-line question body should be preserved.

Environment

  • Reproducible across models that emit \r in tool-call string output.
  • Affects the TUI most visibly (opentui hard-breaks on \r).

A fix PR follows.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions