Skip to content

feat(acp): add /compress slash command#27151

Closed
dorukozgen wants to merge 3 commits into
google-gemini:mainfrom
dorukozgen:feat/acp-compress-command
Closed

feat(acp): add /compress slash command#27151
dorukozgen wants to merge 3 commits into
google-gemini:mainfrom
dorukozgen:feat/acp-compress-command

Conversation

@dorukozgen
Copy link
Copy Markdown

Summary

Adds /compress as a first-class ACP slash command so longer-running ACP sessions can compact their history before hitting context-window limits. Today this works in the TUI but not over ACP, so the agent silently processes /compress as plain user text, burning tokens and producing no real compaction. This PR ports the TUI's existing command behaviour to the ACP command registry, giving ACP clients parity with the TUI in a self-contained ~90 lines of new code plus tests.

Details

The new CompressCommand mirrors packages/cli/src/ui/commands/compressCommand.ts:

  • Same name and aliases: /compress, /summarize, /compact.
  • Same force-compress semantics, calling geminiClient.tryCompressChat(promptId, /*force*/ true).
  • Same telemetry shape coming back: originalTokenCount, newTokenCount, compressionStatus.

ACP returns the result as text inside CommandExecutionResponse.data since the protocol doesn't yet carry typed compression metadata. Each CompressionStatus enum value maps to a distinct, user-readable message so clients can render structured feedback:

  • COMPRESSED → token delta line
  • NOOP → "No compression needed"
  • CONTENT_TRUNCATED → fall-back path with token delta
  • COMPRESSION_FAILED_* → specific failure reason for each enum value
  • Unknown or future status → generic failure

This is intentionally the smallest possible step toward #23945. It does not refactor acpClient.ts to use GeminiClient (the longer-term fix flagged effort/large on the issue), it does not add auto-compression checks before prompts, it does not add a token-count overflow guard, and it does not wire tryMaskToolOutputs() into the ACP path. Those are separate, independently reviewable changes.

Related Issues

Related to #23945

How to Validate

# From repo root, after `npm ci` and a one-time core build:
npm run build --workspace=@google/gemini-cli-core

# Lint the new + modified files
cd packages/cli
npx eslint src/acp/commands/compress.ts \
           src/acp/commands/compress.test.ts \
           src/acp/acpCommandHandler.ts \
           src/acp/acpCommandHandler.test.ts
# Expected: no errors.

# Run the new + extended test files
npx vitest run src/acp/commands/compress.test.ts \
              src/acp/acpCommandHandler.test.ts
# Expected: Test Files 2 passed, Tests 11 passed.

Manual smoke test against a live Gemini session over ACP:

  1. Start the CLI in ACP mode: gemini --experimental-acp.
  2. Run a handful of prompts to grow the conversation a bit.
  3. From the connected ACP client, send /compress (or /summarize, or /compact).
  4. Expected: the registry intercepts the slash command, tryCompressChat runs, and the response text reads Compressed conversation: <pre> → <post> tokens.

Edge cases the test file exercises: NOOP returns the "no compression needed" message, CONTENT_TRUNCATED surfaces the truncation fall-back, each COMPRESSION_FAILED_* enum value emits its specific reason, and a thrown error from the client is caught and reported via getErrorMessage.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Ports the TUI's compress command to ACP, addressing one of the
near-term solutions listed in google-gemini#23945:

  > Implement `/compress` as an ACP supported slash command.

The new `CompressCommand` mirrors `packages/cli/src/ui/commands/
compressCommand.ts` — same aliases (`/summarize`, `/compact`), same
force-compress semantics, and the same telemetry shape coming back
from `geminiClient.tryCompressChat()` (originalTokenCount,
newTokenCount, compressionStatus).

ACP returns the result as text via `CommandExecutionResponse.data`
since the protocol doesn't yet surface a typed compression result.
Each `CompressionStatus` enum value gets a distinct, user-readable
message — including the recoverable `NOOP` and `CONTENT_TRUNCATED`
paths — so clients can render structured feedback.

This is a self-contained, additive change. It does not refactor
`acpClient.ts` to use `GeminiClient` (the longer-term solution in
google-gemini#23945) — that's left for a follow-up. ACP clients (Zed, Cursor,
Fleetify, etc.) can now run `/compress` and get parity with the TUI.

Test plan:
- New `CompressCommand` unit tests cover the success path, NOOP,
  CONTENT_TRUNCATED, every structured failure status, the generic
  fallback, and a thrown-error path (10 cases).
- The shared `acpCommandHandler` parse test gains assertions for
  `/compress`, `/summarize`, and `/compact` so the registry wiring
  is verified end-to-end.
@dorukozgen dorukozgen requested a review from a team as a code owner May 16, 2026 16:03
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 16, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request adds the /compress slash command to the Agent Communication Protocol (ACP), allowing users to compact their conversation history and manage context-window limits effectively. By porting existing TUI compression logic to the ACP command registry, this change provides parity between the CLI's interactive mode and ACP-connected clients, while also introducing robust error handling and status reporting for the compression process.

Highlights

  • New ACP Command: Introduced the /compress slash command to the ACP registry, enabling conversation history compaction over the ACP protocol.
  • Command Parity: Implemented the new command with the same aliases (/summarize, /compact) and logic as the existing TUI implementation, ensuring consistent behavior across interfaces.
  • Structured Feedback: Added comprehensive handling for compression statuses, providing user-readable text responses for success, no-op, truncation, and various failure scenarios.
  • Testing: Added a new test suite for the CompressCommand and updated the command handler tests to verify command registration and alias resolution.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels May 16, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the /compress command (with /summarize and /compact aliases) to the ACP (Agent Context Protocol) implementation, allowing users to replace conversation history with a model-generated summary to manage context window limits. The changes include the new command implementation, registration in the CommandHandler, and comprehensive unit tests. The review feedback correctly identifies a potential runtime error due to missing null checks on the geminiClient and the result of tryCompressChat, recommending defensive programming practices consistent with the project's interface contracts.

Comment thread packages/cli/src/acp/commands/compress.ts Outdated
Mirrors the TUI compress command's defensive pattern: optional-chains
the geminiClient lookup and returns a structured 'client not
available' message instead of throwing if the field is ever missing.
The interface still declares it non-optional today, so this is a
forward-looking safeguard rather than a bug fix.

Adds a unit test covering the new not-available path; existing 11
tests still pass (12/12 total).
@dorukozgen
Copy link
Copy Markdown
Author

Code Review

This pull request introduces the /compress command (with /summarize and /compact aliases) to the ACP (Agent Context Protocol) implementation, allowing users to replace conversation history with a model-generated summary to manage context window limits. The changes include the new command implementation, registration in the CommandHandler, and comprehensive unit tests. The review feedback correctly identifies a potential runtime error due to missing null checks on the geminiClient and the result of tryCompressChat, recommending defensive programming practices consistent with the project's interface contracts.

Thanks for the catch. Pushed e45c8df with the optional chain on geminiClient and an explicit not-available branch, plus a test for that path. Worth flagging that the interface still declares geminiClient as non-optional in AgentLoopContext today, so this is more of a forward-looking safeguard than a current bug fix. Matching the TUI's compress pattern feels like the right call here either way.

@dorukozgen
Copy link
Copy Markdown
Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements the /compress command and its aliases, /summarize and /compact, within the ACP command handler. This feature enables conversation history compression via model-generated summaries to optimize context window usage. The changes include the new CompressCommand implementation, its registration in the command handler, and extensive unit tests for various success and failure states. I have no feedback to provide.

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented May 24, 2026

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented May 31, 2026

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

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

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p2 Important but can be addressed in a future release. status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant