[PR #2759] fix: add title cleansing for TUI conversations #10432

Closed
opened 2026-02-16 18:15:04 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/2759

State: closed
Merged: No


Summary

Added CleanTitle function to normalize session titles from multi-line or code-fenced AI responses. This prevents titles taking multiple lines in the TUI conversation list.

image image

Or... is it a feature? 😄

Changes

  • Implemented CleanTitle in packages/tui/internal/util/util.go to handle multi-line inputs and code-fenced content
  • Applied cleansing in UpdateSession and session update event handler in packages/tui/internal/app/app.go and packages/tui/internal/tui/tui.go
  • Added comprehensive tests in packages/tui/internal/util/util_test.go

Reproduction Steps

  1. Send a prompt with a constraint like "Answer only in JSON format" or "Respond with code fence"
  2. Observe that the generated title includes multi-lines(which naturally comes with code fences), making it malformed on the top of the TUI

Before & After Examples

Multi-line title

Before: Hello\nWorld
After: Hello World

Code-fenced JSON

Before: json\n{"title": "Test"}\n
After: {"title": "Test"}

Normal title

Before: Hello World
After: Hello World

Note

As a TypeScript developer, I used LLM assistance for Go code implementation. However, I faithfully reviewed all code. This commit was written using OpenCode.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/2759 **State:** closed **Merged:** No --- ## Summary Added `CleanTitle` function to normalize session titles from multi-line or code-fenced AI responses. This prevents titles taking multiple lines in the TUI conversation list. <img width="538" height="76" alt="image" src="https://github.com/user-attachments/assets/ff39da4b-a4a4-407d-9cfe-bdd386d89ce5" /> <img width="492" height="198" alt="image" src="https://github.com/user-attachments/assets/9c96fc52-719b-4047-8b88-d168b0d469f4" /> > Or... is it a _feature_? 😄 ## Changes - Implemented `CleanTitle` in `packages/tui/internal/util/util.go` to handle multi-line inputs and code-fenced content - Applied cleansing in `UpdateSession` and session update event handler in `packages/tui/internal/app/app.go` and `packages/tui/internal/tui/tui.go` - Added comprehensive tests in `packages/tui/internal/util/util_test.go` ## Reproduction Steps 1. Send a prompt with a constraint like "Answer only in JSON format" or "Respond with code fence" 2. Observe that the generated title includes multi-lines(which naturally comes with code fences), making it malformed on the top of the TUI ## Before & After Examples ### Multi-line title **Before:** `Hello\nWorld` **After:** `Hello World` ### Code-fenced JSON **Before:** ````json\n{"title": "Test"}\n```` **After:** `{"title": "Test"}` ### Normal title **Before:** `Hello World` **After:** `Hello World` ## Note As a TypeScript developer, I used LLM assistance for Go code implementation. However, I faithfully reviewed all code. This commit was written using OpenCode.
yindo added the pull-request label 2026-02-16 18:15:04 -05:00
yindo closed this issue 2026-02-16 18:15:04 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10432