Skip to content

Add built-in /compact slash command to the native agent - #58663

Merged
bennetbo merged 10 commits into
mainfrom
agent-compact-slash-command
Jun 9, 2026
Merged

Add built-in /compact slash command to the native agent#58663
bennetbo merged 10 commits into
mainfrom
agent-compact-slash-command

Conversation

@rtfeldman

@rtfeldman rtfeldman commented Jun 5, 2026

Copy link
Copy Markdown
Contributor
Screenshot 2026-06-09 at 2 15 51 AM Screenshot 2026-06-09 at 2 16 04 AM Screenshot 2026-06-09 at 2 18 08 AM

Adds an always-available /compact slash command to Zed's native agent that forces a summary-based context compaction of the current conversation, regardless of token usage. This reuses the agent's existing compaction logic (always the summary strategy, never provider-native), bypassing the automatic-compaction token threshold and minimum-context-window guard since the user explicitly asked to compact. The command lives entirely in NativeAgent/NativeAgentConnection, so external (ACP) agents are untouched and keep their own /compact implementations.

The command is gated behind the handoff feature flag, matching the gate on automatic compaction, so it's only advertised and dispatched when that flag is enabled. When the flag is off, typing /compact is treated as an ordinary prompt.

Because the agent panel always renders the typed /compact as a user message, the manual compaction records a matching zero-content user message in the model thread (skipped when building model requests) so that rewinding/truncating that message works instead of erroring, while keeping the command itself out of the model's context.

The slash-command popup now groups commands into separate sections by source — "Commands" (built-in, e.g. /compact), "MCP Server Commands", and "ACP Agent Commands" — so same-named commands from different sources show up as distinguishable duplicates. The source category travels on each command's ACP _meta.

Release Notes:

  • N/A

@rtfeldman rtfeldman self-assigned this Jun 5, 2026
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 5, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Jun 5, 2026
rtfeldman added 3 commits June 8, 2026 21:15
Force-prefix MCP prompts that collide with the built-in /compact, defer the
rewind marker so cancelled/failed/no-op compactions leave no trailing message,
queue text typed after /compact instead of dropping it, and order slash-command
completion groups by relevance so an exact prefix match is the default
selection.
@rtfeldman
rtfeldman marked this pull request as ready for review June 9, 2026 06:21
@rtfeldman
rtfeldman requested review from bennetbo and danilo-leal and removed request for danilo-leal June 9, 2026 06:21
/// it as a follow-up message. The queued remainder auto-processes when the
/// command turn stops, so e.g. `/compact do X` compacts and then runs `do X`
/// rather than discarding it.
fn send_command_queueing_remainder(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if we really need this. I feel like we can get away with typing /compact something something doing nothing (treat it as normal text). Seems like this is what all the other tools are doing too

@bennetbo
bennetbo enabled auto-merge June 9, 2026 09:05
@bennetbo
bennetbo added this pull request to the merge queue Jun 9, 2026
Merged via the queue into main with commit e505296 Jun 9, 2026
32 checks passed
@bennetbo
bennetbo deleted the agent-compact-slash-command branch June 9, 2026 09:36
This was referenced Jun 18, 2026
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…es#58663)

<img width="851" height="315" alt="Screenshot 2026-06-09 at 2 15 51 AM"
src="https://github.com/user-attachments/assets/958f2d2f-db7d-4afb-b4b3-ed11f36b00e7"
/>

<img width="644" height="260" alt="Screenshot 2026-06-09 at 2 16 04 AM"
src="https://github.com/user-attachments/assets/e6a74c6b-aba5-4fbb-991c-25842ced5832"
/>

<img width="619" height="128" alt="Screenshot 2026-06-09 at 2 18 08 AM"
src="https://github.com/user-attachments/assets/ba7fa303-852b-4a17-b8df-ea5bd4df7c11"
/>


Adds an always-available `/compact` slash command to Zed's native agent
that forces a summary-based context compaction of the current
conversation, regardless of token usage. This reuses the agent's
existing compaction logic (always the summary strategy, never
provider-native), bypassing the automatic-compaction token threshold and
minimum-context-window guard since the user explicitly asked to compact.
The command lives entirely in `NativeAgent`/`NativeAgentConnection`, so
external (ACP) agents are untouched and keep their own `/compact`
implementations.

The command is gated behind the `handoff` feature flag, matching the
gate on automatic compaction, so it's only advertised and dispatched
when that flag is enabled. When the flag is off, typing `/compact` is
treated as an ordinary prompt.

Because the agent panel always renders the typed `/compact` as a user
message, the manual compaction records a matching zero-content user
message in the model thread (skipped when building model requests) so
that rewinding/truncating that message works instead of erroring, while
keeping the command itself out of the model's context.

The slash-command popup now groups commands into separate sections by
source — "Commands" (built-in, e.g. `/compact`), "MCP Server Commands",
and "ACP Agent Commands" — so same-named commands from different sources
show up as distinguishable duplicates. The source category travels on
each command's ACP `_meta`.

Release Notes:

- N/A

---------

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…es#58663)

<img width="851" height="315" alt="Screenshot 2026-06-09 at 2 15 51 AM"
src="https://github.com/user-attachments/assets/958f2d2f-db7d-4afb-b4b3-ed11f36b00e7"
/>

<img width="644" height="260" alt="Screenshot 2026-06-09 at 2 16 04 AM"
src="https://github.com/user-attachments/assets/e6a74c6b-aba5-4fbb-991c-25842ced5832"
/>

<img width="619" height="128" alt="Screenshot 2026-06-09 at 2 18 08 AM"
src="https://github.com/user-attachments/assets/ba7fa303-852b-4a17-b8df-ea5bd4df7c11"
/>


Adds an always-available `/compact` slash command to Zed's native agent
that forces a summary-based context compaction of the current
conversation, regardless of token usage. This reuses the agent's
existing compaction logic (always the summary strategy, never
provider-native), bypassing the automatic-compaction token threshold and
minimum-context-window guard since the user explicitly asked to compact.
The command lives entirely in `NativeAgent`/`NativeAgentConnection`, so
external (ACP) agents are untouched and keep their own `/compact`
implementations.

The command is gated behind the `handoff` feature flag, matching the
gate on automatic compaction, so it's only advertised and dispatched
when that flag is enabled. When the flag is off, typing `/compact` is
treated as an ordinary prompt.

Because the agent panel always renders the typed `/compact` as a user
message, the manual compaction records a matching zero-content user
message in the model thread (skipped when building model requests) so
that rewinding/truncating that message works instead of erroring, while
keeping the command itself out of the model's context.

The slash-command popup now groups commands into separate sections by
source — "Commands" (built-in, e.g. `/compact`), "MCP Server Commands",
and "ACP Agent Commands" — so same-named commands from different sources
show up as distinguishable duplicates. The source category travels on
each command's ACP `_meta`.

Release Notes:

- N/A

---------

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants