Skip to content

fix(pi-fff): keep collapsed result row within available width - #896

Open
Ray0907 wants to merge 1 commit into
dmtrKovalenko:mainfrom
Ray0907:fix/pi-fff-collapsed-text-width
Open

Ray0907 wants to merge 1 commit into
dmtrKovalenko:mainfrom
Ray0907:fix/pi-fff-collapsed-text-width

Conversation

@Ray0907

@Ray0907 Ray0907 commented Oct 1, 2026 •

Copy link
Copy Markdown

Problem

CollapsedText.render (packages/pi-fff/src/index.ts) can return a row wider than the width it was given. When the first-line preview does not fit, it slices the preview to max(0, previewWidth - markerWidth) columns but still appends the full 3-column ... marker, so the row is markerWidth + 1 + suffixWidth columns even when previewWidth < markerWidth.

I hit this while using the pi coding agent with pi-fff installed (agent was mid-task). pi-tui requires every rendered line to be <= width; otherwise the TUI stops and throws Rendered line N exceeds terminal width, so the whole agent exits and the in-flight work is lost. Seen with @ff-labs/pi-fff 0.11.0 on @earendil-works/pi-coding-agent 0.99.2, in a 24-column pane, after an ffgrep call returned 218 lines:

Terminal width: 24
Line 1012 visible width: 25
[1011] (w=24)  ffgrep /REF|existsS...
[1012] (w=25)  ... ... (217 more lines)

The tool box is Box(1,1), so the component gets 22 columns; the suffix ... (217 more lines) is 20, leaving previewWidth = 1; the output was ... ... (217 more lines) (24 columns) plus 1 left pad = 25.

Fix

If previewWidth < markerWidth, return only the suffix. The Math.max(0, ...) clamp is no longer needed.

if (previewWidth < markerWidth) return [this.suffix];

Verification

  • bun test test/: 96 pass.
  • Swept widths 1-120 x several line counts x short, long, ANSI-coloured, CJK and empty previews through the real pi-tui Box(1,1), visibleWidth and sliceByColumn: 104 of 7800 combinations overflowed before, 0 after. Wider layouts produce the same output as before.
  • Not tested end to end in a running pi with a model.

Side effect: at very narrow widths the collapsed row drops the leading ... and shows only ... (N more lines).

🤖 Generated with Claude Code

CollapsedText appended the full "..." marker even when the preview had no
room left, so the row could be up to 3 columns wider than the width it was
given. In pi this makes the TUI throw "Rendered line N exceeds terminal
width" and exit (seen at 24 columns with a 217-line ffgrep result).

When previewWidth < markerWidth, return only the suffix.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@greptile-apps greptile-apps Bot 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 903dca3f-7db9-4d39-8a8e-a85f427f31b6

📥 Commits

Reviewing files that changed from the base of the PR and between 89c1927 and 23740b4.

📒 Files selected for processing (1)
  • packages/pi-fff/src/index.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

CollapsedText.render now returns only the suffix when the available preview width is narrower than the marker. Otherwise, it slices the preview using the available width.

Changes

Collapsed text rendering

Layer / File(s) Summary
Preview width handling
packages/pi-fff/src/index.ts
When the preview width is less than the marker width, rendering returns only the suffix. Otherwise, preview slicing uses the available width without a clamp.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested reviewers: gustav-fff

Merge Risk: ⚪ Minimal · up to 23740

The narrow preview change preserves the rendered-line width limit. No identified issue prevents merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix and its purpose: keeping the collapsed result row within the available width.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

This branch has not been deployed

No deployments
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.

1 participant