Skip to content

Conversation

@shuv1337
Copy link
Collaborator

@shuv1337 shuv1337 commented Nov 30, 2025

anomalyco#4898 - Search in messages - High utility, well-implemented, enhances navigation
anomalyco#4791 - Bash output with ANSI - Solid DX improvement, token-efficient
anomalyco#4900 - Double Ctrl+C - Simple safety feature, prevents frustration
anomalyco#4709 - Show live token usage during streaming

Summary by CodeRabbit

  • New Features

    • Added global search functionality with match highlighting across messages (toggle with Ctrl+F)
    • Added bash command output viewer with pagination and full output access
    • Added exit confirmation prompt for safer app closure
    • Added prompt initialization support
  • Bug Fixes

    • Improved output truncation and formatting for terminal commands
    • Enhanced null safety checks for tool results
    • Refined token estimation logic
  • Style

    • Updated strikethrough syntax highlighting appearance

✏️ Tip: You can customize this high-level summary in your review settings.

actions-user and others added 29 commits November 26, 2025 23:33
- Added a search input component to allow users to search through messages.
- Implemented logic to highlight search matches and navigate between them.
- Updated the theme syntax rules to include strikethrough styling.
- Enhanced message rendering to support search highlighting for text and markdown parts.
Adds an bash output viewer with full ANSI color support. When bash commands
produce more than 20 lines of output, users can click to expand into a
full-screen viewer with syntax highlighting and keyboard navigation.

Key features:
- Full ANSI/VT color rendering using opentui-ansi-vt terminal emulation
- Truncated preview (20 lines) with 'Click to view full output' expansion
- Prompt text preservation when entering/exiting viewer
- Force color output in bash commands (FORCE_COLOR, CLICOLOR, TERM env vars)

Technical changes:
- Added opentui-ansi-vt dependency for terminal buffer rendering
- Added initialValue prop to Prompt component to restore draft text
- Strip ANSI codes for search to match actual text content
- Refactored match navigation logic to prevent scrolling to the same message when navigating through matches.
- Enhanced search highlighting to correctly identify and highlight query text within code blocks.
- Updated rendering of Assistant messages to include IDs for better scrolling functionality during searches.
…t get it working in Assistant Messages (markdown)
Merge upstream PR anomalyco#4898 from OpeOginni:
- Add SearchInput component for searching through messages
- Implement match navigation with highlighting
- Add strikethrough styling in theme syntax rules
- Enable Ctrl+F keybind to toggle search mode
Merges upstream PR anomalyco#4791 which adds:
- Bash output viewer with full ANSI color support using opentui-ansi-vt
- Terminal emulation for accurate color rendering
- Page up/down and Home/End navigation in bash output viewer
- Click to view full output for truncated bash results
- Forces color output in bash commands (FORCE_COLOR=1)
- Adds initialValue prop to Prompt component for restoring drafts

Preserves our local features:
- Token tracking and context percentage display
- Search in messages (Ctrl+F) from PR anomalyco#4898
…malyco#4900)

Merge upstream PR anomalyco#4900 from AmineGuitouni:
- Require pressing Ctrl+C twice within 2 seconds to exit
- Show warning toast on first press: 'Press again to exit'
- Prevents accidental exit during active sessions
…omalyco#4709)

Cherry-pick fix from upstream PR anomalyco#4709 by arsham:
- Use 'ignored' flag instead of 'synthetic' for accurate token counts
- Fix sentEstimate formula to prevent double-counting tool result tokens
- Add null checks in calculateToolResultTokens for safety
- Prevents exponential growth from double-counting in session totals
- Add header explaining this is a fork for PR integration testing
- Include table of merged PRs with upstream status
- Preserve original opencode documentation below
…#4900, anomalyco#4709 fixes

Merged upstream PRs:
- anomalyco#4898: Search in messages (Ctrl+F)
- anomalyco#4791: Bash output viewer with ANSI color support
- anomalyco#4900: Double Ctrl+C to exit
- anomalyco#4709: Token counting fixes for synthetic/noReply messages

Updated README for shuvcode fork project.
@coderabbitai
Copy link

coderabbitai bot commented Nov 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Pull request introduces a global search subsystem for TUI sessions with per-match highlighting across messages, a Bash command output viewer with pagination, enhancements to prompt components, and updates to token calculation and output processing logic.

Changes

Cohort / File(s) Summary
Prompt Component Enhancements
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx, packages/opencode/src/cli/cmd/tui/component/prompt/search.tsx
Added initialValue prop for prompt initialization; introduced two-step exit flow with toast notifications. New SearchInput component with keyboard bindings, textarea, ref-based imperative control (focus, blur, reset, getValue), and dynamic match highlighting via computed agent color.
Session Search & Bash Viewer
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
Integrated global search subsystem with match tracking, live query updates, and navigation helpers. Added Bash output viewer with truncated preview (20 lines) and full output modal. Implemented SearchHighlighter and MarkdownSearchHighlighter for inline highlighting. Extended session context to expose searchQuery, currentMatchIndex, matches, and bashOutput state.
Session UI Sidebar
packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx
Updated panel labels from "Open"/"Code" to "shuv"/"code".
Theme & Syntax
packages/opencode/src/cli/cmd/tui/context/theme.tsx
Replaced strikethrough syntax rule: changed from foreground-only to foreground + background + strikethrough styling.
Session Prompt Logic
packages/opencode/src/session/prompt.ts
Modified token estimation to exclude toolResultTokens from previous assistant results; changed user text extraction filter from synthetic parts to ignored parts.
Bash Tool Output
packages/opencode/src/tool/bash.ts
Added output truncation guard (MAX_OUTPUT_LENGTH), applied ptyToText conversion to final output, expanded spawn environment with color/output settings.
Token Calculation
packages/opencode/src/util/token.ts
Added null checks for part.state; use optional chaining for time?.compacted; default missing output to empty string; only add error token if part.state.error exists.
Dependencies & Configuration
packages/opencode/package.json, nix/hashes.json, README.md
Added "opentui-ansi-vt" dependency (v1.2.7); updated nodeModules hash; updated README fork description.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SearchInput
    participant SessionContext
    participant MessageRenderer
    participant TextPart

    User->>SearchInput: Ctrl+F triggers search
    SearchInput->>SessionContext: Update searchQuery
    Note over SessionContext: Compute matches over all messages
    SessionContext->>MessageRenderer: New matches available
    
    User->>SearchInput: Type search term
    SearchInput->>SessionContext: searchQuery updated
    SessionContext->>SessionContext: Recompute matches<br/>(memoized)
    SessionContext->>MessageRenderer: Render with highlighting
    MessageRenderer->>TextPart: Pass query & messageID
    TextPart->>TextPart: Choose renderer<br/>(SearchHighlighter or<br/>MarkdownSearchHighlighter)
    TextPart-->>MessageRenderer: Render with match highlight

    User->>SearchInput: Press Up/Down navigation
    SearchInput->>SessionContext: handleNextMatch/<br/>handlePrevMatch
    SessionContext->>SessionContext: Update currentMatchIndex
    SessionContext->>MessageRenderer: Scroll to matched message
    MessageRenderer->>MessageRenderer: Highlight active match
Loading
sequenceDiagram
    participant User
    participant BashTool
    participant SessionContext
    participant BashDisplay
    participant TerminalRenderer

    BashTool->>BashTool: Execute bash command
    BashTool->>BashTool: Collect output<br/>(apply truncation)
    BashTool->>BashTool: Convert via ptyToText
    BashTool-->>SessionContext: Return processed output
    
    SessionContext->>SessionContext: Store output in<br/>bashOutput context
    SessionContext->>BashDisplay: Render preview (20 lines)
    BashDisplay->>TerminalRenderer: Terminal buffer render
    TerminalRenderer-->>BashDisplay: Rendered preview UI

    User->>BashDisplay: Click "view full output"
    BashDisplay->>SessionContext: showBashOutput(full)
    SessionContext->>BashDisplay: Switch to full view
    BashDisplay->>TerminalRenderer: Render full terminal
    TerminalRenderer-->>User: Display paginated output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Areas requiring extra attention:

  • packages/opencode/src/cli/cmd/tui/routes/session/index.tsx — Complex search matching logic, memoization correctness, and interaction between search state and message rendering; verify scroll-to-match targeting and highlighted match index alignment.
  • packages/opencode/src/cli/cmd/tui/component/prompt/search.tsx — New component with keyboard handling, ref imperative API, and theme-aware styling; validate focus management and ref callback correctness.
  • packages/opencode/src/session/prompt.ts — Token calculation changes; confirm that excluding toolResultTokens and switching to ignored-based filtering produces correct token estimates.
  • packages/opencode/src/tool/bash.ts — Output truncation timing and ptyToText conversion; verify truncation occurs for each chunk and conversion produces expected terminal-like rendering.
  • Integration between SearchInput component and SessionContext search state — ensure query updates trigger re-renders and match highlighting across all message types.

Poem

🐰 A search bound through the session deep,
With bash outputs we now can keep,
Highlighted matches dance and gleam,
While prompts initialize from dreams—
The TUI leaps with vibrant flair!

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch merge-PRs

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 832fa1f and fe79203.

⛔ Files ignored due to path filters (2)
  • bun.lock is excluded by !**/*.lock
  • flake.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • README.md (1 hunks)
  • nix/hashes.json (1 hunks)
  • packages/opencode/package.json (1 hunks)
  • packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx (6 hunks)
  • packages/opencode/src/cli/cmd/tui/component/prompt/search.tsx (1 hunks)
  • packages/opencode/src/cli/cmd/tui/context/theme.tsx (1 hunks)
  • packages/opencode/src/cli/cmd/tui/routes/session/index.tsx (13 hunks)
  • packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx (1 hunks)
  • packages/opencode/src/session/prompt.ts (2 hunks)
  • packages/opencode/src/tool/bash.ts (4 hunks)
  • packages/opencode/src/util/token.ts (1 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

6 participants