feat(acp): add /compress slash command#27151
Conversation
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.
|
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. |
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
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).
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. |
|
/gemini review |
There was a problem hiding this comment.
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.
|
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. |
|
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. |
Summary
Adds
/compressas 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/compressas 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
CompressCommandmirrorspackages/cli/src/ui/commands/compressCommand.ts:/compress,/summarize,/compact.geminiClient.tryCompressChat(promptId, /*force*/ true).originalTokenCount,newTokenCount,compressionStatus.ACP returns the result as text inside
CommandExecutionResponse.datasince the protocol doesn't yet carry typed compression metadata. EachCompressionStatusenum value maps to a distinct, user-readable message so clients can render structured feedback:COMPRESSED→ token delta lineNOOP→ "No compression needed"CONTENT_TRUNCATED→ fall-back path with token deltaCOMPRESSION_FAILED_*→ specific failure reason for each enum valueThis is intentionally the smallest possible step toward #23945. It does not refactor
acpClient.tsto useGeminiClient(the longer-term fix flaggedeffort/largeon the issue), it does not add auto-compression checks before prompts, it does not add a token-count overflow guard, and it does not wiretryMaskToolOutputs()into the ACP path. Those are separate, independently reviewable changes.Related Issues
Related to #23945
How to Validate
Manual smoke test against a live Gemini session over ACP:
gemini --experimental-acp./compress(or/summarize, or/compact).tryCompressChatruns, and the response text readsCompressed conversation: <pre> → <post> tokens.Edge cases the test file exercises:
NOOPreturns the "no compression needed" message,CONTENT_TRUNCATEDsurfaces the truncation fall-back, eachCOMPRESSION_FAILED_*enum value emits its specific reason, and a thrown error from the client is caught and reported viagetErrorMessage.Pre-Merge Checklist