Skip to content

fix: fix .envrc body prompt does not collapse#501

Closed
fluxdiv wants to merge 3 commits into
mainfrom
06-09-sea-594
Closed

fix: fix .envrc body prompt does not collapse#501
fluxdiv wants to merge 3 commits into
mainfrom
06-09-sea-594

Conversation

@fluxdiv

@fluxdiv fluxdiv commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Pull request

Summary

Long .envrc bodies in the permission prompt now start collapsed to a 5-line preview so the action options remain visible. Users can expand the full body with Ctrl+O and scroll through it with PageUp/PageDn, with a hard cap of 200 rendered lines for very large files.

Changes

  • .envrc body rendering defaults to a collapsed 5-line preview when the body exceeds that threshold, with a … +N lines (Ctrl+O to expand) truncation hint
  • Ctrl+O toggles the body between collapsed and expanded; collapsing resets the scroll offset to zero
  • PageUp/PageDn scroll the expanded body in 10-line steps
  • When expanded and the file exceeds 200 lines, a truncation notice directs the user to open the file directly
  • The picker option detail lines are hidden in the collapsed envrc view to keep the options block on screen
  • Footer hint text updates dynamically to reflect the available Ctrl+O / PgUp/PgDn actions
  • draw_body applies the scroll offset to the Paragraph widget when the body is expanded

Test plan

  • envrc_long_body_collapsed_by_default — verifies only the first 5 lines render and the expand hint appears
  • envrc_short_body_renders_fully_without_expand_hint — verifies short bodies render in full with no expand affordance
  • envrc_ctrl_o_expands_long_body — verifies Ctrl+O expands the body and shows the collapse hint
  • envrc_ctrl_o_again_toggles_back_to_collapsed_and_resets_scroll — verifies toggling back collapses and zeroes the scroll offset
  • envrc_collapsed_options_block_present_on_standard_height — renders to a TestBackend at 80×24 and asserts all four picker options are visible
  • envrc_expanded_page_down_scrolls_body — verifies PageDn/PageUp advance and retreat the scroll offset by ENVRC_BODY_SCROLL_STEP
  • envrc_expanded_body_keeps_200_line_safety_cap — verifies the 200-line cap and truncation message for a 250-line body

@linear-code

linear-code Bot commented Jun 9, 2026

Copy link
Copy Markdown

SEA-594

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 45ee62d8-0a46-45aa-9899-50cbe1189917

📥 Commits

Reviewing files that changed from the base of the PR and between bd17ee8 and d4271fc.

📒 Files selected for processing (1)
  • crates/seal-tui/src/permission_prompt.rs

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Collapsible, independently scrollable preview of the envrc body in the permission prompt (default collapsed); Ctrl+O toggles expand/collapse and resets scroll on collapse.
    • PageUp/PageDown scroll the envrc body with bounds clamping; compact option layout when collapsed.
    • 200-line safety cap with truncation notices and updated footer hints for envrc-specific keys.
  • Tests
    • Added unit tests for collapse/expand, scroll behavior and clamping, truncation messaging, context preservation, and compact layout.

Walkthrough

Adds a collapsible, scrollable .envrc body display to the permission prompt: model state (expanded + scroll), constructors reset state, key handling for toggle and paging, new rendering helper with a 200-line cap and compact picker mode, and comprehensive unit tests.

Changes

Collapsible envrc body expansion

Layer / File(s) Summary
Envrc body state model and management
crates/seal-tui/src/permission_prompt.rs
Adds ENVRC_BODY_PREVIEW_LINES, MAX_ENVRC_BODY_LINES, ENVRC_BODY_SCROLL_STEP. PermissionModel gains private fields for envrc_body_expanded and envrc_body_scroll_offset, initialized in constructors and reset when envrc info is attached. Implements helpers for line counting, collapsibility, toggling (reset scroll on collapse), and bounded scrolling.
Keyboard input for expand/collapse and scrolling
crates/seal-tui/src/permission_prompt.rs
handle_key handles Ctrl+O to toggle envrc expansion and PageUp/PageDown to scroll the expanded envrc body by the configured step; handlers return Pending.
Footer hints, envrc body rendering, and compact picker
crates/seal-tui/src/permission_prompt.rs
draw_footer shows envrc-specific key hints when body is collapsible. Adds push_envrc_body_lines to render headers, collapse/expand hint, collapsed preview, scroll-aware expanded view, and a 200-line truncation message. draw_body calls this helper. When the envrc body is collapsible and collapsed, option detail lines are omitted to keep choices visible.
Envrc test helpers and coverage
crates/seal-tui/src/permission_prompt.rs
Adds ratatui test imports and deterministic envrc test helpers. Comprehensive tests cover default-collapsed rendering for long bodies, short-body behavior without expand hints, Ctrl+O expand/collapse with scroll reset, PageUp/PageDown scrolling/clamping, context preservation while scrolling, and the 200-line cap/truncation messaging.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 In a prompt where envrc lines overflow,

I nibble keys to make long pages go.
Ctrl-O unfolds, Page keys make me glide,
Scroll and cap, with tests by my side. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main changeset objective: enabling the .envrc body to collapse in the permission prompt, keeping action options visible.
Description check ✅ Passed The description comprehensively covers all aspects of the changeset, including collapsed preview behavior, keyboard shortcuts, truncation logic, dynamic footer hints, and detailed test cases.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-09-sea-594

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

fluxdiv commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • Merge Queue - adds this PR to the back of the merge queue
  • Merge Queue Fast Track - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@fluxdiv fluxdiv marked this pull request as ready for review June 9, 2026 22:02
Comment thread crates/seal-tui/src/permission_prompt.rs Outdated
@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces the always-expanded .envrc body rendering with a collapsed 5-line preview that keeps picker options visible, adding Ctrl+O toggle, PageUp/PageDn scroll, and a 200-line hard cap. Scroll is applied by skipping logical lines inside push_envrc_body_lines rather than via Paragraph::scroll(), so the security-critical path/capability/pattern header remains anchored regardless of scroll position.

  • envrc_body_expanded and envrc_body_scroll_offset are new fields on PermissionModel; push_envrc_body_lines replaces the inline body loop in draw_body and handles preview, full-expand, scroll offset, truncation hint, and the … +N lines collapse hint.
  • compact_envrc_picker suppresses the per-option detail lines when the body is collapsed, reclaiming ~8 rows on a 24-row terminal so all four picker options stay on screen.
  • Seven new tests cover collapsed default, short-body passthrough, toggle, scroll reset, options visibility at 80×24, scroll mechanics, and the 200-line cap.

Confidence Score: 5/5

Safe to merge — the envrc body scroll is applied by skipping logical lines rather than scrolling the Paragraph widget, so the path/capability/pattern header stays visible at all times, and all edge cases are covered by tests.

The change is self-contained: new state fields are initialised in every PermissionModel constructor, key handlers are guarded by is_envrc_body_expanded()/envrc_body_is_collapsible() and are no-ops for non-envrc prompts, and the scroll-position arithmetic uses saturating arithmetic throughout. Seven targeted unit tests give high confidence the feature behaves correctly.

No files require special attention.

Important Files Changed

Filename Overview
crates/seal-tui/src/permission_prompt.rs Adds envrc body collapse/expand/scroll with Ctrl+O, PageUp/PageDn, 200-line cap, compact picker mode, and seven unit tests; no blocking issues found.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    K[KeyEvent] --> CO{Ctrl+O?}
    CO -- yes --> TC[toggle_envrc_body]
    TC --> CC{is_collapsible?}
    CC -- no --> NOP[no-op]
    CC -- yes --> TOG[flip expanded flag\nclear scroll offset if collapsing]
    CO -- no --> PG{PageUp / PageDn?}
    PG -- PageDn --> SD[scroll_envrc_body_down\noffset += STEP, clamp to max_scroll_offset]
    PG -- PageUp --> SU[scroll_envrc_body_up\noffset -= STEP, floor 0]
    PG -- no --> OTHER[other key handlers]
    TOG --> RENDER
    SD --> RENDER
    SU --> RENDER
    NOP --> RENDER
    RENDER[draw_body / push_envrc_body_lines]
    RENDER --> EXP{is_expanded?}
    EXP -- yes --> SKIP[skip scroll_offset lines\ntake MAX-skip lines\nshow scroll hint]
    EXP -- no --> COL{is_collapsible?}
    COL -- yes --> PRV[take 5 preview lines\nshow … +N lines hint\nhide picker detail lines]
    COL -- no --> FULL[render all lines]
Loading

Reviews (3): Last reviewed commit: "fix: clamp max scroll" | Re-trigger Greptile

Comment thread crates/seal-tui/src/permission_prompt.rs Outdated
Comment thread crates/seal-tui/src/permission_prompt.rs
Comment thread crates/seal-tui/src/permission_prompt.rs

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/seal-tui/src/permission_prompt.rs`:
- Around line 878-883: The envrc_body_line_count() repeatedly iterates
body.lines().count(); add a cached usize field (e.g., cached_envrc_body_lines)
to the struct, initialize it to 0 in all constructors, set/update it whenever
envrc_info is attached/changed (compute info.body.lines().count() then), and
change envrc_body_line_count() to just return the cached value; be sure code
paths that remove/replace envrc_info also reset/update the cached value so
envrc_body_is_collapsible, scroll_envrc_body_down, and push_envrc_body_lines
read the cached count.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6151fa98-3527-48ab-82b0-5460d487d388

📥 Commits

Reviewing files that changed from the base of the PR and between c96e21b and 8b3255f.

📒 Files selected for processing (1)
  • crates/seal-tui/src/permission_prompt.rs

Comment thread crates/seal-tui/src/permission_prompt.rs
Comment thread crates/seal-tui/src/permission_prompt.rs

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/seal-tui/src/permission_prompt.rs (1)

911-918: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clamp the envrc scroll offset before it can skip the whole body.

scroll_envrc_body_down() currently allows envrc_body_scroll_offset to reach min(line_count, MAX_ENVRC_BODY_LINES). push_envrc_body_lines() then does lines().skip(offset), so the last PageDown on a 50-line body skips all 50 accessible lines and renders an empty expanded body. Clamp to the last valid start line instead of the line count itself.

🛠️ Minimal fix
 fn scroll_envrc_body_down(&mut self) {
     if self.is_envrc_body_expanded() {
-        let max = self.envrc_body_line_count().min(MAX_ENVRC_BODY_LINES);
+        let max = self
+            .envrc_body_line_count()
+            .min(MAX_ENVRC_BODY_LINES)
+            .saturating_sub(1);
         self.envrc_body_scroll_offset = self
             .envrc_body_scroll_offset
             .saturating_add(ENVRC_BODY_SCROLL_STEP)
             .min(max);
     }
 }

Also applies to: 1653-1668

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/seal-tui/src/permission_prompt.rs` around lines 911 - 918, The scroll
logic for envrc allows envrc_body_scroll_offset to equal the total accessible
line count, which then makes push_envrc_body_lines().lines().skip(offset) render
nothing; change the clamp in scroll_envrc_body_down() to cap at the last valid
start line (i.e., compute max =
self.envrc_body_line_count().min(MAX_ENVRC_BODY_LINES).saturating_sub(1) and
then set envrc_body_scroll_offset =
self.envrc_body_scroll_offset.saturating_add(ENVRC_BODY_SCROLL_STEP).min(max));
do the same adjustment for the other identical block mentioned (around the
region noted at lines 1653-1668) so push_envrc_body_lines() never skips the
entire body.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@crates/seal-tui/src/permission_prompt.rs`:
- Around line 911-918: The scroll logic for envrc allows
envrc_body_scroll_offset to equal the total accessible line count, which then
makes push_envrc_body_lines().lines().skip(offset) render nothing; change the
clamp in scroll_envrc_body_down() to cap at the last valid start line (i.e.,
compute max =
self.envrc_body_line_count().min(MAX_ENVRC_BODY_LINES).saturating_sub(1) and
then set envrc_body_scroll_offset =
self.envrc_body_scroll_offset.saturating_add(ENVRC_BODY_SCROLL_STEP).min(max));
do the same adjustment for the other identical block mentioned (around the
region noted at lines 1653-1668) so push_envrc_body_lines() never skips the
entire body.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7c3d72e4-e1be-43ee-9915-6ee13dd64b0e

📥 Commits

Reviewing files that changed from the base of the PR and between 8b3255f and bd17ee8.

📒 Files selected for processing (1)
  • crates/seal-tui/src/permission_prompt.rs

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 9, 2026
@fluxdiv fluxdiv requested a review from mattwilkinsonn June 10, 2026 01:09
@graphite-app

graphite-app Bot commented Jun 11, 2026

Copy link
Copy Markdown

Merge activity

  • Jun 11, 2:31 AM UTC: fluxdiv added this pull request to the Graphite merge queue.
  • Jun 11, 2:36 AM UTC: CI is running for this pull request on a draft pull request (#515) due to your merge queue CI optimization settings.
  • Jun 11, 2:46 AM UTC: Merged by the Graphite merge queue via draft PR: #515.

@graphite-app graphite-app Bot closed this Jun 11, 2026
@graphite-app graphite-app Bot deleted the 06-09-sea-594 branch June 11, 2026 02:46
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants