Skip to content

feat: implement /rewind command - #15720

Merged
Adib234 merged 47 commits into
mainfrom
adibakm/rewind-command
Jan 22, 2026
Merged

feat: implement /rewind command#15720
Adib234 merged 47 commits into
mainfrom
adibakm/rewind-command

Conversation

@Adib234

@Adib234 Adib234 commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR introduces the /rewind slash command, enabling users to revert their conversation history to a previous point. It supports reverting both the conversation state and any associated file system changes. Additionally, it improves the readability of content included via @ references by wrapping them in clear delimiters.

Details

The new built-in command provides a comprehensive workflow for rewinding a session:

  • Interactive Selection: Launches the RewindViewer component (introduced in a separate PR) to let users browse and select a target message.
  • Flexible Outcomes: Supports three modes of operation based on user choice:
    1. Rewind Only: Truncates conversation history to the selected point.
    2. Revert Only: Undoes file changes made by the model since the selected point, keeping history intact.
    3. Rewind and Revert: Performs both actions for a complete rollback.
  • State Management:
    • Leverages ChatRecordingService to persist the truncated history.
    • Updates the GeminiClient and ContextManager to reflect the new state.
    • Refreshes the UI by reloading the history with loadHistory.

@ Command Processor Updates

  • Content Delimiters: Modified handleAtCommand in atCommandProcessor.ts to wrap referenced file content with --- Content from referenced files --- and --- End of content ---.
  • Purpose: This clearly demarcates injected context from the user's actual prompt, which is crucial for the RewindViewer to correctly identify and strip this content when displaying past messages.

Integration

  • Registers the rewindCommand in BuiltinCommandLoader.ts (implied by file list).
  • Updates AppContainer.tsx and types.ts to support the new command structure (implied by file list).

Related Issues

Closes #1769

How to Validate

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

@Adib234
Adib234 requested a review from a team as a code owner December 30, 2025 16:35
@Adib234 Adib234 self-assigned this Dec 30, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Adib234, 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 significant new feature: the /rewind command, which empowers users with greater control over their conversational history within the CLI. This command allows users to jump back to any previous message, effectively resetting the conversation from that point, and can optionally revert any file changes that were made since that message. Alongside this, the way referenced file content is presented in the UI has been improved with distinct headers and footers for better clarity, and the loadHistory mechanism was enhanced to support pre-populating the input field, streamlining the user experience after a rewind operation.

Highlights

  • New Rewind Command: Introduces a /rewind command allowing users to navigate and reset their conversation history to a specific point.
  • File Reversion Capability: The /rewind command now supports reverting file changes associated with a chosen message, offering options for "Rewind Only", "Rewind and Revert", or "Revert Only".
  • Enhanced loadHistory Functionality: The loadHistory function in the UI context has been updated to accept an optional postLoadInput parameter, enabling the input buffer to be pre-filled after loading historical messages.
  • Improved Referenced File Display: The @commandProcessor now adds clear "--- Content from referenced files ---" headers and "--- End of content ---" footers around content retrieved from referenced files, enhancing readability.
  • Comprehensive Unit Tests: New unit tests have been added for the rewindCommand, ensuring its various functionalities and error handling scenarios are robustly covered.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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-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 a new "/rewind" command, enabling users to navigate back to a specific point in their conversation history and optionally revert associated file changes. The implementation correctly integrates with the existing command loading mechanism and UI state management. The changes to atCommandProcessor.ts for handling referenced content headers are also a good improvement for output clarity. The new test file for rewindCommand provides good coverage for various scenarios.

Comment thread packages/cli/src/ui/commands/rewindCommand.test.tsx Outdated
Comment thread packages/cli/src/ui/commands/rewindCommand.test.tsx Outdated
@Adib234 Adib234 changed the title Adibakm/rewind command feat: implement /rewind command Dec 30, 2025
@Adib234
Adib234 force-pushed the adibakm/rewind-viewer branch from 2ddfa74 to 4c4cb62 Compare December 30, 2025 17:50
@Adib234
Adib234 force-pushed the adibakm/rewind-command branch from 981efc2 to 7b23a67 Compare December 30, 2025 18:45
@gemini-cli gemini-cli Bot added status/need-issue Pull requests that need to have an associated issue. priority/p1 Important and should be addressed in the near term. and removed status/need-issue Pull requests that need to have an associated issue. labels Jan 7, 2026
Base automatically changed from adibakm/rewind-viewer to adibakm/rewind-confirmation-dialog January 9, 2026 20:32
@Adib234
Adib234 force-pushed the adibakm/rewind-confirmation-dialog branch 2 times, most recently from 965a708 to 09f82c0 Compare January 12, 2026 18:43
@Adib234
Adib234 force-pushed the adibakm/rewind-command branch 2 times, most recently from 37f0ec3 to 7dcdd0b Compare January 14, 2026 14:54
@gemini-cli gemini-cli Bot added size/l A large sized PR review/involved PRs that may take a lot of work to review labels Jan 14, 2026
Base automatically changed from adibakm/rewind-confirmation-dialog to main January 14, 2026 15:31
@Adib234

Adib234 commented Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

The implementation of the /rewind command is solid and follows the project's React and testing conventions well.

Actionable Feedback:

  • Documentation & Keybindings: In packages/cli/src/config/keyBindings.ts, please add Command.REWIND to the commandCategories (under "History & Search"). This will ensure the shortcut is automatically included in the autogenerated documentation table in docs/cli/keyboard-shortcuts.md when the generation script runs.
  • Consistency: While Command.REWIND is mapped to Esc, the double-ESC logic in InputPrompt.tsx still hardcodes the string '/rewind' in the onSubmit call.

Observations:

  • Tests: The tests in rewindCommand.test.tsx and RewindViewer.test.tsx correctly use renderWithProviders, waitFor with predicates, and act() where necessary, ensuring stability and adherence to the project's testing standards.
  • Typo Fixed: Confirmed that the rewindedConvesation typo has been corrected to rewindedConversation.
  • React Patterns: The use of ExpandableText and the integration with BaseSelectionList is consistent with the rest of the CLI's UI architecture.

@Adib234
Adib234 requested a review from a team as a code owner January 21, 2026 19:59
@Adib234

Adib234 commented Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

commits address the following:

  • messages shown from oldest to newest with the latest message selected by default
  • additional entry in the history dialog for the current rewind position
  • show a message saying "Nothing to rewind to" if /rewind is triggered and there is no history
  • The delimiters --- Content from referenced files --- and --- End of content --- are in a constants file
  • Removed rewind command integration file, double ESC was documented in keyboard-shortcuts.md in Additional context-specific shortcuts section
  • Don't need to deal with resource cleanup because we removed handleClearTextToastChange since we have the toasts we need from this PR 5217045

Consistency: While Command.REWIND is mapped to Esc, the double-ESC logic in InputPrompt.tsx still hardcodes the string '/rewind' in the onSubmit call.

This is consistent with other slash commands

Comment thread packages/cli/src/config/keyBindings.ts Outdated
[Command.HISTORY_DOWN]: [{ key: 'n', shift: false, ctrl: true }],
[Command.REVERSE_SEARCH]: [{ key: 'r', ctrl: true }],
[Command.REWIND]: [{ key: 'double escape' }],
// Note: original logic ONLY checked ctrl=false, ignored meta/shift/paste

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.

please revert the comment on line 193. I assume it is an error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reverted comment

if (conversation) {
await revertFileChanges(conversation, messageId);
}
// Proceed to rewind logic

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.

nit: having these // Proceed to rewind logic comments i a code smell. Instead call a
rewindConversation helper from both places with this logic. That way it is self documenting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Created a helper function

processedQuery: [
{ text: `@${getRelativePath(filePath)}` },
{ text: '\n--- Content from referenced files ---' },
{ text: `\n${REFERENCE_CONTENT_START}` },

@jacob314 jacob314 Jan 22, 2026

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.

test files should generally use the raw value not constants. Otherwise it is hard to tell what you are testing.
please revert these test changes using REFERENCE_CONTENT_START and END rather than the raw value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted test files

@jacob314 jacob314 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.

This PR is good enough to land once the nits mentioned here are addressed.
As a fast follow we should do the following:

  1. Ensure the radio button list of rewind locations doesn't wrap around as that is surprising. you should stick to the first message in the history not wrap all the way around to the last.
  2. Refresh is broken after changing the history when we are not in alternate buffer mode. There is a force refresh method you should call to resolve this. You can look at what happens when /clear is called if you need a breadcrumb.lgtm

@Adib234
Adib234 added this pull request to the merge queue Jan 22, 2026
@Adib234
Adib234 removed this pull request from the merge queue due to a manual request Jan 22, 2026
@Adib234 Adib234 mentioned this pull request Jan 22, 2026
@Adib234
Adib234 enabled auto-merge January 22, 2026 14:47
@Adib234
Adib234 added this pull request to the merge queue Jan 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 22, 2026
@Adib234
Adib234 added this pull request to the merge queue Jan 22, 2026
Merged via the queue into main with commit 3b9f580 Jan 22, 2026
25 checks passed
@Adib234
Adib234 deleted the adibakm/rewind-command branch January 22, 2026 15:43
thacio added a commit to thacio/auditaria that referenced this pull request Jan 24, 2026
SandyTao520 pushed a commit that referenced this pull request Jan 27, 2026
sidwan02 pushed a commit to sidwan02/gemini-cli-gemma that referenced this pull request Feb 6, 2026
kuishou68 pushed a commit to iOfficeAI/gemini-cli-pro that referenced this pull request Feb 27, 2026
cocosheng-g pushed a commit that referenced this pull request May 6, 2026
@sripasg sripasg added size/xl An extra large PR and removed size/l A large sized PR labels Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 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 priority/p1 Important and should be addressed in the near term. review/involved PRs that may take a lot of work to review size/xl An extra large PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Quick-history editing via arrow-key navigation (switch chat history)

4 participants