Skip to content

feat(cli): Add /rewind <N> index argument for non-interactive use - #25150

Closed
tusaryan wants to merge 4 commits into
google-gemini:mainfrom
tusaryan:feat/rewind-index-argument
Closed

feat(cli): Add /rewind <N> index argument for non-interactive use#25150
tusaryan wants to merge 4 commits into
google-gemini:mainfrom
tusaryan:feat/rewind-index-argument

Conversation

@tusaryan

@tusaryan tusaryan commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds support for an optional [index] argument to the /rewind command. This allows external tools orchestrating the CLI to trim conversation history programmatically, maintaining prompt cache efficiency without needing to navigate the TUI. This PR also addresses internal code duplication by centralizing string manipulation utilities.

Details

  • Indexing: Supports 0-based indexing and Python-style negative indexing (e.g., /rewind -1 for the last message).
  • Buffer handling: Properly restores the cleaned prompt text back into the input buffer.
  • Refactoring: Centralized getCleanedRewindText() in formatters.ts to ensure consistent string padding across all rewind paths.
  • Error handling: rewindConversation() now returns a boolean to prevent displaying a success message when rewind fails.
  • Files Modified:
    • packages/cli/src/ui/commands/rewindCommand.tsx
    • packages/cli/src/ui/commands/rewindCommand.test.tsx
    • packages/cli/src/ui/components/RewindViewer.tsx
    • packages/cli/src/ui/utils/formatters.ts
    • docs/cli/rewind.md

Related Issues

Closes #24933

How to Validate

  1. Start Gemini CLI and send a few prompts.
  2. Enter /rewind -1 to delete the last user message and its response.
  3. Verify the chat history trims successfully and your input prompt restores the rewound text.
  4. Run the unit tests locally:
    npm test -w @google/gemini-cli -- src/ui/commands/rewindCommand.test.tsx
  5. Verify the full preflight suite passes:
    npm run preflight

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

Adds support for an optional integer index argument to the `/rewind` command.
This enables non-interactive, automated workflows to trim conversation history
and preserve prompt caches without navigating the TUI. Supports python-style
negative indexing.
@tusaryan
tusaryan requested review from a team as code owners April 10, 2026 21:17
@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 introduces a non-interactive way to rewind conversation history in the Gemini CLI by allowing users to pass an index argument to the /rewind command. This change is designed to support automated workflows and external tools that need to manage conversation state without interacting with the TUI. The implementation includes robust index validation, support for negative indexing, and ensures that the prompt text is correctly restored to the input buffer.

Highlights

  • Non-interactive Rewind Support: Added support for an optional index argument to the /rewind command, enabling programmatic conversation history trimming.
  • Indexing Flexibility: Implemented support for 0-based indexing and Python-style negative indexing (e.g., /rewind -1) to target specific messages.
  • Improved Error Handling: Updated rewindConversation to return a boolean status, preventing misleading success messages when operations fail.
  • Documentation and Testing: Updated CLI documentation and added comprehensive unit tests for the new index-based rewind functionality.
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 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 counter productive. 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/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 10, 2026

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

Copy link
Copy Markdown
Contributor

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 non-interactive, index-based rewinding for the /rewind command, enabling users to jump to specific messages using 0-based or negative indices. The changes include updated documentation, new test cases for index parsing and error handling, and a refactor of the rewindCommand to support asynchronous actions. Feedback suggests moving the duplicated text-cleaning logic into a shared utility to improve maintainability and ensure consistency with the interactive TUI.

Comment thread packages/cli/src/ui/commands/rewindCommand.tsx Outdated
Moves duplicated text cleaning logic into a shared utility file (formatters.ts) to ensure consistency between interactive and non-interactive rewind paths.
@tusaryan

Copy link
Copy Markdown
Contributor Author

/gemini review -> I've just staged changes that refactor the string cleaner to formatters.ts based on your previous feedback. Please take another look!

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

Copy link
Copy Markdown
Contributor

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 non-interactive, index-based rewinding to the /rewind command, allowing users to jump to specific messages using 0-based or negative indices. The implementation includes updates to the command logic to handle arguments, the migration of the getCleanedRewindText utility to a shared formatter, and comprehensive test coverage for the new functionality. Documentation has also been updated to reflect these changes. I have no feedback to provide as no review comments were submitted.

@spencer426

Copy link
Copy Markdown
Contributor

Thank you for your interest in contributing to the project! We are closing this PR as the issue was closed.

@spencer426 spencer426 closed this May 7, 2026
@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p3 Backlog - a good idea but not currently a priority. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add /rewind <user-message-index> to rewind to a specific message

3 participants