Skip to content

agent: Fix terminal command truncation in confirmation dialogs#40570

Merged
danilo-leal merged 12 commits intozed-industries:mainfrom
miguelcsx:refactor/message
Jan 14, 2026
Merged

agent: Fix terminal command truncation in confirmation dialogs#40570
danilo-leal merged 12 commits intozed-industries:mainfrom
miguelcsx:refactor/message

Conversation

@miguelcsx
Copy link
Contributor

@miguelcsx miguelcsx commented Oct 18, 2025

Closes #40322

When users run multi-line terminal commands, the confirmation dialog was only showing the first line with '- N more lines' truncated. This meant dangerous commands like 'rm -rf' or 'sudo' operations could be hidden from view, creating a security risk.

Now terminal commands always display in full, with scroll support for very long commands (20+ lines) to keep the confirmation buttons visible.

Other tools continue using truncation for better UI efficiency since they don't pose the same security concerns.

Release Notes:

  • Agent: Fixed terminal command truncation in the agent panel to better expose long commands (e.g., potentially dangerous multi-line commands are now fully visible before execution)

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 18, 2025
@SomeoneToIgnore SomeoneToIgnore added the area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features label Oct 18, 2025
@danilo-leal
Copy link
Member

Hey @miguelcsx, thanks for the PR! Quick question, though, how can I easily test this? I want to check the UI given that adding overflow scroll in the tool call container might cause double scroll, which is something we avoid having.

@miguelcsx miguelcsx force-pushed the refactor/message branch 3 times, most recently from 480d254 to aa413fa Compare October 20, 2025 01:05
@dinocosta
Copy link
Member

Hey @miguelcsx, thanks for the PR! Quick question, though, how can I easily test this? I want to check the UI given that adding overflow scroll in the tool call container might cause double scroll, which is something we avoid having.

@danilo-leal I was able to test it by asking the AI to try and run the commands reported in the associated issue ( #40322 ) . Here's some screenshots of the before and after, in case it helps ↓

Before After
before after

@miguelcsx
Copy link
Contributor Author

miguelcsx commented Oct 20, 2025

Hi team, @danilo-leal is right. With this not-that long Nix command it's not easy to notice the behavior, but with longer commands I'm running into an issue: instead inner scroll, I get a nested scroll.

I tried two approaches:

  1. Showing the full command without scrolling, but that hurts the UX for long commands.
  2. Keeping the current behavior, but that still fails.

Right now I'm working on making that inner box scrollable. The challenge is that the markdown rendering creates a pretty complex structure , so I need to adjust it to make the inner part scroll properly.

@miguelcsx
Copy link
Contributor Author

I guess is ready for review, I added a scroll handle to track the scrolling in the inner box. Fell free to play with before I make it ready to review.

Here is a preview:

2025-10-20-17-03-19.mp4

@danilo-leal
Copy link
Member

Thanks for the follow up @miguelcsx, appreciate it!

I definitely feel like we shouldn't ship the double-scroll. But what we could do to improve the long command UX is: we should cap the container's height to an arbitrary max number of lines, so that if the command is bigger than, say, 8 lines, you need to click an "expand" button that would reveal the whole command (with no internal scroll). You can then of course always collapse that to clear out the UI again.

Using @dinocosta's image there as a base, this is how I'm thinking of it:

Screenshot 2025-10-20 at 8  01@2x

But just instead of like, just 2 lines being visible above the button, imagine you'd see something around 4 or close. Then you can expand to see the rest.

…ndustries#40322)

When users run multi-line terminal commands, the confirmation dialog was
only showing the first line with '- N more lines' truncated. This meant
dangerous commands like 'rm -rf' or 'sudo' operations could be hidden
from view, creating a security risk.

Now terminal commands always display in full, with scroll support for
very long commands (20+ lines) to keep the confirmation buttons visible.

Other tools continue using truncation for better UI efficiency since
they don't pose the same security concerns.

Closes zed-industries#40322

Release Notes:

- Fixed terminal command truncation in confirmation dialogs - dangerous
  multi-line commands are now fully visible before execution
@miguelcsx
Copy link
Contributor Author

I liked your idea @danilo-leal, I added a expand/collapse button, see it below:

2025-10-20-21-34-38.mp4

@miguelcsx miguelcsx marked this pull request as ready for review October 23, 2025 17:15
@maxdeviant maxdeviant changed the title agent: Fix terminal command truncation in confirmation dialogs (#40322) agent: Fix terminal command truncation in confirmation dialogs Oct 23, 2025
@danilo-leal
Copy link
Member

danilo-leal commented Oct 24, 2025

Nice, thanks for pushing it forward @miguelcsx! Also pushed a commit now making some progress on the design. However, this doesn't feel perfect yet... for a couple of reasons:

  1. After you allow the agent to run the command, the ability to expand/collapse the command goes away. That's because we're using the same boolean for both the command and the output expansion. We should have dedicated bools for each so that they persist. I feel like if the command was cropped before it ran, it should stay cropped after, too (unless the user explicitly uncollapses it).
  2. Ideally, we'd use an arbitrary number of lines instead of an arbitrary max height. That's because if the command is reasonably short, we don't need the ability to collapse/expand the command and the button.

I appreciate how using the number of lines might not be trivial, though. I myself would need to look it up and maybe reach out for some deeper help to pull it off, so feel free to not do it if it's too daunting!

@dinocosta
Copy link
Member

@miguelcsx Are you still working on these changes? The related issue – #40322 – has just been marked as stale but I can see that the issue is still happening and, I believe, it's still worth improving on.

If you currently don't have time to finish tackling Danilo's feedback, let us know, and I can push this over the finish line. Thanks! 🙂

- Update the way that the `TerminalTool` displays its command, returning
  back to the version where newlines are actually displayed, so if a
  multi-line command is used, it will be displayed as multiple lines.
- Refactor the `AcpThreadView.render_terminal_command_preview` in order
  to show, at maximum, three lines of the command, with an expand button
  to show the full command if it is longer. The label in the expand
  button will inform the user of how many additional lines are hidden.
- Replace `MarkdownElement` with manual line rendering for command text
- Only show expand/collapse button when command exceeds 3 lines
- Display "N more lines" label when collapsed instead of always showing button
- Remove `window` parameter from `render_terminal_command_preview`
@dinocosta
Copy link
Member

@danilo-leal Here's a quick screen recording of what the current changes look like! I believe it's now ready for another review 🙇

CleanShot.2026-01-12.at.14.52.45.mp4

These changes ensure we're again able to just run `cargo test -p
agent_ui` in order to run the test suite for the `agent_ui` crate.
@danilo-leal danilo-leal merged commit 8150d59 into zed-industries:main Jan 14, 2026
23 checks passed
@github-project-automation github-project-automation bot moved this from Community PRs to Done in Quality Week – December 2025 Jan 14, 2026
rtfeldman pushed a commit that referenced this pull request Jan 14, 2026
Closes #40322

When users run multi-line terminal commands, the confirmation dialog was
only showing the first line with '- N more lines' truncated. This meant
dangerous commands like 'rm -rf' or 'sudo' operations could be hidden
from view, creating a security risk.

Now terminal commands always display in full, with scroll support for
very long commands (20+ lines) to keep the confirmation buttons visible.

Other tools continue using truncation for better UI efficiency since
they don't pose the same security concerns.

Release Notes:

- Agent: Fixed terminal command truncation in the agent panel to better
expose long commands (e.g., potentially dangerous multi-line commands
are now fully visible before execution)

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
@dinocosta
Copy link
Member

@danilo-leal Thank you for taking this one over the line! 🙌

danilo-leal added a commit that referenced this pull request Jan 19, 2026
…47148)

Follow up to #40570.

This PR removes the UI treatment where we collapse a terminal command
into a disclosure component if it spans more than three lines. I
initially thought having this fancy treatment in the UI would make it
sleeker but it actually feels like a counter-productive move to
arbitrarily hide command lines; they're arguably always important to see
in full, even when they're super long. I'm happy to get some feedback
here, but I think for now, I'd feel better if users could see them all
without having to manually expand/collapse them.

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement

Projects

Development

Successfully merging this pull request may close these issues.

AI: Unable to review terminal command ("- N more lines")

4 participants