Skip to content

agent_ui: Add selection to terminal thread - #57301

Merged
MartinYe1234 merged 9 commits into
zed-industries:mainfrom
rkiyanchuk:fix-add-selection-to-terminal-thread
Jun 2, 2026
Merged

agent_ui: Add selection to terminal thread#57301
MartinYe1234 merged 9 commits into
zed-industries:mainfrom
rkiyanchuk:fix-add-selection-to-terminal-thread

Conversation

@rkiyanchuk

@rkiyanchuk rkiyanchuk commented May 20, 2026

Copy link
Copy Markdown
Contributor

NOTE:

I'm new both to Rust and Zed, so it's a crudely vibecoded fix for #57295, just as a PoC of expected behavior that works on macOS. So please be critical and skeptical of the code, as it may not account for many nuances and behavior on other platforms.

Summary

  • Fixes "Add to Agent Thread" not working with Terminal Threads #57295: the Add to Agent Thread action (or cmd->) was a silent
    no-op when a terminal thread was the active conversation in the agent panel.
  • The action's deferred handler only routed through active_conversation_view(),
    which returns None for BaseView::Terminal, so the selection was dropped.
  • Extends the handler with an else if branch that, when a terminal thread is
    active, formats the selection as @<rel-path>:<start>-<end> (matching the
    mention syntax CLI agents already understand) and pastes it into the
    terminal, then focuses the terminal so the user can edit/submit.

Test plan

  • Select a range of lines in a buffer, open a terminal thread in the agent
    panel, invoke Add to Agent Thread from the context menu → the formatted
    mention is pasted into the terminal.
  • Same flow via the cmd-> keybinding on macOS.
  • Multiple selections in one buffer produce space-separated mentions.
  • cargo check -p agent_ui and ./script/clippy -p agent_ui pass.

Demo

ScreenShot 2026-05-20 at 21 03 27
zed-selection-insert-agent-panel.mp4

Release Notes:

  • Fixed Add to Agent Thread being a no-op when a terminal thread is the active conversation in the agent panel

…minal thread

When a terminal thread is active in the agent panel, AddSelectionToThread
silently no-ops because the handler only routes through active_conversation_view.
Extend the handler to format the editor selection as @<rel-path>:<start>-<end>
and paste it into the terminal, mirroring the format CLI agents already accept.
@cla-bot

cla-bot Bot commented May 20, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @rkiyanchuk on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label May 20, 2026
@rkiyanchuk

Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 20, 2026
@cla-bot

cla-bot Bot commented May 20, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@linwanlong

Copy link
Copy Markdown

I’m really looking forward to this feature. It’s so convenient!

@smitbarmase smitbarmase added the area:ai/terminal threads Feedback for Zed's Terminal Threads label May 29, 2026
@MartinYe1234 MartinYe1234 self-assigned this Jun 2, 2026
The agent process inside a terminal thread resolves `@path` mentions
relative to its own working directory, not the buffer's worktree root.
Emit a path relative to the terminal's working directory when the
selection lives under it, and fall back to an absolute path otherwise.
Detect the foreground program of a terminal thread and format the
selection mention the way that agent expects. The codex CLI uses bare,
cwd-relative paths (quoted when they contain whitespace) with no leading
`@`, so emit that form when codex is running and fall back to the
generic `@path:line` mention otherwise.

Also append a trailing space so the mention doesn't fuse with subsequent
input at the prompt.
Cover the terminal-thread branch of the AddSelectionToThread action:
a no-op when nothing is highlighted, and the formatted
@<rel-path>:<start>-<end> mention once a selection exists.
Drop the per-CLI mention formatting and foreground-process detection.
Selections added to a terminal thread are now always pasted as
<path>:<start>-<end>, with no provider-specific quoting or prefix.
@MartinYe1234

Copy link
Copy Markdown
Contributor

Thanks for your contribution @rkiyanchuk , I made a few fixes and added a test.

@MartinYe1234
MartinYe1234 added this pull request to the merge queue Jun 2, 2026
Merged via the queue into zed-industries:main with commit a565ab4 Jun 2, 2026
32 checks passed
dandv pushed a commit to dandv/zed that referenced this pull request Jun 3, 2026
## **NOTE:**
I'm new both to Rust and Zed, so it's mostly vibecoded alleged fix for
zed-industries#57295, just as a PoC of expected behavior that works on macOS. So
please be critical and skeptical of the code, as it may not account for
many nuances and behavior on other platforms.

## Summary

- Fixes zed-industries#57295: the `Add to Agent Thread` action (or `cmd->`) was a
silent
no-op when a terminal thread was the active conversation in the agent
panel.
- The action's deferred handler only routed through
`active_conversation_view()`,
which returns `None` for `BaseView::Terminal`, so the selection was
dropped.
- Extends the handler with an `else if` branch that, when a terminal
thread is
active, formats the selection as `@<rel-path>:<start>-<end>` (matching
the
  mention syntax CLI agents already understand) and pastes it into the
  terminal, then focuses the terminal so the user can edit/submit.

## Test plan

- [x] Select a range of lines in a buffer, open a terminal thread in the
agent
panel, invoke `Add to Agent Thread` from the context menu → the
formatted
      mention is pasted into the terminal.
- [x] Same flow via the `cmd->` keybinding on macOS.
- [x] Multiple selections in one buffer produce space-separated
mentions.
- [x] `cargo check -p agent_ui` and `./script/clippy -p agent_ui` pass.

## Demo

<img width="2928" height="1920" alt="ScreenShot 2026-05-20 at 21 03 27"
src="https://github.com/user-attachments/assets/dc29f380-a864-4c12-b454-bdb4201f5b8d"
/>


https://github.com/user-attachments/assets/9d3914d8-8ba2-4bcb-be43-78efb342d8a8


## Release Notes:

- Fixed `Add to Agent Thread` being a no-op when a terminal thread is
the active conversation in the agent panel

---------

Co-authored-by: Martin Ye <martin@zed.dev>
@lcmen

lcmen commented Jun 5, 2026

Copy link
Copy Markdown

Has this been released? It still does not work for me.

TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 8, 2026
## **NOTE:**
I'm new both to Rust and Zed, so it's mostly vibecoded alleged fix for
zed-industries#57295, just as a PoC of expected behavior that works on macOS. So
please be critical and skeptical of the code, as it may not account for
many nuances and behavior on other platforms.

## Summary

- Fixes zed-industries#57295: the `Add to Agent Thread` action (or `cmd->`) was a
silent
no-op when a terminal thread was the active conversation in the agent
panel.
- The action's deferred handler only routed through
`active_conversation_view()`,
which returns `None` for `BaseView::Terminal`, so the selection was
dropped.
- Extends the handler with an `else if` branch that, when a terminal
thread is
active, formats the selection as `@<rel-path>:<start>-<end>` (matching
the
  mention syntax CLI agents already understand) and pastes it into the
  terminal, then focuses the terminal so the user can edit/submit.

## Test plan

- [x] Select a range of lines in a buffer, open a terminal thread in the
agent
panel, invoke `Add to Agent Thread` from the context menu → the
formatted
      mention is pasted into the terminal.
- [x] Same flow via the `cmd->` keybinding on macOS.
- [x] Multiple selections in one buffer produce space-separated
mentions.
- [x] `cargo check -p agent_ui` and `./script/clippy -p agent_ui` pass.

## Demo

<img width="2928" height="1920" alt="ScreenShot 2026-05-20 at 21 03 27"
src="https://github.com/user-attachments/assets/dc29f380-a864-4c12-b454-bdb4201f5b8d"
/>


https://github.com/user-attachments/assets/9d3914d8-8ba2-4bcb-be43-78efb342d8a8


## Release Notes:

- Fixed `Add to Agent Thread` being a no-op when a terminal thread is
the active conversation in the agent panel

---------

Co-authored-by: Martin Ye <martin@zed.dev>
This was referenced Jun 18, 2026
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
## **NOTE:**
I'm new both to Rust and Zed, so it's mostly vibecoded alleged fix for
zed-industries#57295, just as a PoC of expected behavior that works on macOS. So
please be critical and skeptical of the code, as it may not account for
many nuances and behavior on other platforms.

## Summary

- Fixes zed-industries#57295: the `Add to Agent Thread` action (or `cmd->`) was a
silent
no-op when a terminal thread was the active conversation in the agent
panel.
- The action's deferred handler only routed through
`active_conversation_view()`,
which returns `None` for `BaseView::Terminal`, so the selection was
dropped.
- Extends the handler with an `else if` branch that, when a terminal
thread is
active, formats the selection as `@<rel-path>:<start>-<end>` (matching
the
  mention syntax CLI agents already understand) and pastes it into the
  terminal, then focuses the terminal so the user can edit/submit.

## Test plan

- [x] Select a range of lines in a buffer, open a terminal thread in the
agent
panel, invoke `Add to Agent Thread` from the context menu → the
formatted
      mention is pasted into the terminal.
- [x] Same flow via the `cmd->` keybinding on macOS.
- [x] Multiple selections in one buffer produce space-separated
mentions.
- [x] `cargo check -p agent_ui` and `./script/clippy -p agent_ui` pass.

## Demo

<img width="2928" height="1920" alt="ScreenShot 2026-05-20 at 21 03 27"
src="https://github.com/user-attachments/assets/dc29f380-a864-4c12-b454-bdb4201f5b8d"
/>


https://github.com/user-attachments/assets/9d3914d8-8ba2-4bcb-be43-78efb342d8a8


## Release Notes:

- Fixed `Add to Agent Thread` being a no-op when a terminal thread is
the active conversation in the agent panel

---------

Co-authored-by: Martin Ye <martin@zed.dev>
handlename added a commit to handlename/ztx that referenced this pull request Jul 26, 2026
Zed's `agent::AddSelectionToThread` (`cmd->`) has worked with
Terminal Threads since zed-industries/zed#57301 (merged
2026-06-02, a565ab4): it formats the selection as
`@<rel-path>:<start>-<end>` and pastes it into the active terminal
thread. Feature 4 existed only to fill that gap.

The removal reaches further than the feature itself.

`ztx setup zed` installed nothing but the `ztx: send selection`
task and its `cmd-alt-z` binding, so it loses its reason to exist
along with `ztx send`. Four subcommands remain: run, export,
notify, sessions.

The IPC paste path had `ztx send` as its only caller. notify's
control frames share the socket but not the code path, so the
socket, `ipc::send` and one-session-per-project routing all stay.

CONTROL_PREFIX (the leading NUL) stays even though every frame is
now a control frame: a session started by an older ztx still
pastes any non-NUL payload straight into the agent's prompt, so
dropping the marker would make a new `ztx notify` spray JSON into
it. Non-control frames are now logged and discarded.

docs/*/getting-started/zed-setup.md shrinks rather than disappears
-- its terminal_init_command section is onboarding content
unrelated to selections.

Verified manually with Claude Code: `cmd->` pastes the mention and
the agent resolves the line range. antigravity-cli is left
unverified by decision, not oversight; if it does not resolve
`@path:start-end` the fix belongs upstream rather than in a
restored `ztx send`.

BREAKING CHANGE: the `ztx send` and `ztx setup zed` subcommands
are removed. Zed's built-in `cmd->` replaces them.

User request: zedのターミナルセッションでも AddSelectionToThread が使えるようになっていたようだ。 zed-industries/zed#57301 つまり、ztx の "Pull editor selections into the session" 機能は不要という事にならないか?

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
## **NOTE:**
I'm new both to Rust and Zed, so it's mostly vibecoded alleged fix for
zed-industries#57295, just as a PoC of expected behavior that works on macOS. So
please be critical and skeptical of the code, as it may not account for
many nuances and behavior on other platforms.

## Summary

- Fixes zed-industries#57295: the `Add to Agent Thread` action (or `cmd->`) was a
silent
no-op when a terminal thread was the active conversation in the agent
panel.
- The action's deferred handler only routed through
`active_conversation_view()`,
which returns `None` for `BaseView::Terminal`, so the selection was
dropped.
- Extends the handler with an `else if` branch that, when a terminal
thread is
active, formats the selection as `@<rel-path>:<start>-<end>` (matching
the
  mention syntax CLI agents already understand) and pastes it into the
  terminal, then focuses the terminal so the user can edit/submit.

## Test plan

- [x] Select a range of lines in a buffer, open a terminal thread in the
agent
panel, invoke `Add to Agent Thread` from the context menu → the
formatted
      mention is pasted into the terminal.
- [x] Same flow via the `cmd->` keybinding on macOS.
- [x] Multiple selections in one buffer produce space-separated
mentions.
- [x] `cargo check -p agent_ui` and `./script/clippy -p agent_ui` pass.

## Demo

<img width="2928" height="1920" alt="ScreenShot 2026-05-20 at 21 03 27"
src="https://github.com/user-attachments/assets/dc29f380-a864-4c12-b454-bdb4201f5b8d"
/>


https://github.com/user-attachments/assets/9d3914d8-8ba2-4bcb-be43-78efb342d8a8


## Release Notes:

- Fixed `Add to Agent Thread` being a no-op when a terminal thread is
the active conversation in the agent panel

---------

Co-authored-by: Martin Ye <martin@zed.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai/terminal threads Feedback for Zed's Terminal Threads cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Add to Agent Thread" not working with Terminal Threads

6 participants