Skip to content

refactor(shared): extract text truncation utilities to shared/text_utils.py#753

Open
github-actions[bot] wants to merge 2 commits into
mainfrom
fix/code-quality/extract-text-utils
Open

refactor(shared): extract text truncation utilities to shared/text_utils.py#753
github-actions[bot] wants to merge 2 commits into
mainfrom
fix/code-quality/extract-text-utils

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 25, 2026

Summary

Extract the duplicated text truncation functions from history_side_panel.py and richlog_visualizer.py into a new shared/text_utils.py module.

Changes

  • Created openhands_cli/shared/text_utils.py with the truncate_text() function
  • The new function consolidates:
    • _truncate() from history_side_panel.py (simple truncation)
    • _truncate_for_display() from richlog_visualizer.py (with from_start option)
  • Features of the consolidated function:
    • Supports truncation from start (default) or end (for paths)
    • Optional whitespace collapsing (newlines/carriage returns to spaces)
    • ELLIPSIS constant exported for consistent usage
  • Updated openhands_cli/shared/__init__.py to export truncate_text
  • Replaced local truncation functions in both TUI files with imports from shared module
  • Updated tests in tests/tui/widgets/test_richlog_visualizer.py to import ELLIPSIS from the shared module

Related Issue

Addresses findings from #751

Testing

  • Linting passes (make lint)
  • Tests pass (make test - 1353 tests)

This PR was automatically generated by the Code Quality Report workflow.


🚀 Try this PR

uvx --python 3.12 git+https://github.com/OpenHands/OpenHands-CLI.git@fix/code-quality/extract-text-utils

…ils.py

Extract the duplicated text truncation functions from history_side_panel.py
and richlog_visualizer.py into a new shared/text_utils.py module.

The new truncate_text() function consolidates:
- _truncate() from history_side_panel.py (simple truncation)
- _truncate_for_display() from richlog_visualizer.py (with from_start option)

Features of the consolidated function:
- Supports truncation from start (default) or end (for paths)
- Optional whitespace collapsing (newlines/carriage returns to spaces)
- ELLIPSIS constant exported for consistent usage

Addresses item from code quality report.

Closes #751

Co-authored-by: openhands <openhands@all-hands.dev>
@enyst
Copy link
Copy Markdown
Member

enyst commented May 25, 2026

@OpenHands make an empty commit to kick off CI and /iterate to green and approved by the AI reviewer from pr-review workflow.

@openhands-ai
Copy link
Copy Markdown

openhands-ai Bot commented May 25, 2026

I'm on it! enyst can track my progress at all-hands.dev

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions
Copy link
Copy Markdown
Contributor Author

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands_cli/shared
   __init__.py40100% 
   text_utils.py100100% 
openhands_cli/tui/panels
   history_side_panel.py2021692%217, 252–253, 257, 324, 330, 363, 376, 447, 452–454, 456–457, 459, 461
openhands_cli/tui/widgets
   richlog_visualizer.py3447378%75, 82–85, 87, 175, 182–183, 195, 290, 372, 422–425, 438, 441–443, 446–448, 451, 453, 456, 490–494, 498, 505–508, 512, 524, 562, 567–568, 571–573, 576, 582–585, 587, 594, 608–609, 611, 617, 636–637, 640, 693, 696–697, 701, 724–726, 742, 760–761, 763, 783, 787, 808, 811
TOTAL7064101085% 

@enyst enyst requested a review from openhands-agent May 25, 2026 13:10
Copy link
Copy Markdown
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

🟢 Good taste - Clean refactoring that eliminates code duplication without changing behavior.

The consolidated truncate_text() function is well-designed:

  • Clear parameters with sensible defaults
  • Correctly preserves behavior from both original implementations
  • The collapse_whitespace flag properly handles the difference between direct truncation and clean-then-truncate flows

[RISK ASSESSMENT]
🟢 LOW - Pure refactoring with no user-facing changes. Existing tests continue to pass and validate the preserved behavior.

VERDICT:
Worth merging - Solid refactoring that improves code maintainability.


Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/OpenHands-CLI/actions/runs/26402228478

@openhands-ai
Copy link
Copy Markdown

openhands-ai Bot commented May 25, 2026

Since the last summary, there were no additional changes or actions.

  • ✅ The request was completely addressed: an empty commit was pushed to trigger CI, CI was monitored to green, and the AI reviewer approved the PR.
  • ✅ Instructions were followed faithfully: PR context was inspected, the latest SHA was verified, checks were monitored, the OpenHands PR review workflow was triggered, and unresolved review threads were checked.
  • ✅ Changes were concise: only the requested empty commit was added; no code or unrelated files were modified.
  • ✅ No extraneous changes need to be reverted.

@enyst enyst enabled auto-merge (squash) May 25, 2026 13:26
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