Skip to content

feat: introduce useRewindLogic hook for conversation history navigation - #15716

Merged
Adib234 merged 7 commits into
mainfrom
adibakm/rewind-hook
Jan 12, 2026
Merged

feat: introduce useRewindLogic hook for conversation history navigation#15716
Adib234 merged 7 commits into
mainfrom
adibakm/rewind-hook

Conversation

@Adib234

@Adib234 Adib234 commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR adds the useRewindLogic React hook, which centralizes the state and logic for selecting rewind points in a conversation. It enables the CLI UI to display user interactions, calculate their individual turn stats, and determine the cumulative file system impact when preparing for a history rewind.

Details

The useRewindLogic hook serves as the core state manager for the rewind feature's UI components:

  • Interaction Extraction: Automatically filters and memoizes user-initiated messages (interactions) from the conversation record to provide a clean list of potential rewind points.
  • Selection Management: Manages the selectedMessageId and provides selectMessage and clearSelection functions to handle user navigation within the history.
  • Exposes turn-based statistics via getStats for inline display in the history list.
  • Automatically calculates the total confirmationStats (cumulative line changes and file counts) whenever a message is selected, facilitating a detailed confirmation dialog before execution.

Related Issues

After this PR gets merged here are the other PRs that will get merged in order
#15717
#15718
#15720

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 self-assigned this Dec 30, 2025
@Adib234
Adib234 requested a review from a team as a code owner December 30, 2025 16:34
@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 core React hook, useRewindLogic, designed to streamline the implementation of a conversation 'rewind' feature. It centralizes the management of user interactions, selection state, and the calculation of file system impacts when rewinding to a specific message, ensuring a consistent and testable approach to this functionality.

Highlights

  • New useRewindLogic Hook: Introduces a new React hook, useRewindLogic, which encapsulates the state and logic required for a 'rewind' feature in a conversation-based UI. This hook manages user interactions, selected messages, and associated file change statistics.
  • Interaction Filtering: The useRewindLogic hook automatically filters conversation messages to present only user-initiated interactions, making it easier to select specific points for rewinding.
  • State Management: The hook manages the selectedMessageId and confirmationStats (file change statistics) states, providing functions to selectMessage, clearSelection, and getStats for a given message.
  • Comprehensive Testing: A new test file, useRewindLogic.test.ts, has been added, providing thorough unit tests for the new hook, covering its initialization, state updates, selection logic, and integration with utility functions.

🧠 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 the useRewindLogic hook and its corresponding tests. The overall structure is good. I've provided feedback on the hook's implementation to improve its correctness and performance by ensuring function references are stable with useCallback and by making the message selection logic more robust. The accompanying tests are well-written.

Comment thread packages/cli/src/ui/hooks/useRewindLogic.ts Outdated
Comment thread packages/cli/src/ui/hooks/useRewindLogic.ts Outdated
@Adib234 Adib234 changed the title completed useRewindLogic hook feat: introduce useRewindLogic hook for conversation history navigation Dec 30, 2025
@Adib234
Adib234 force-pushed the adibakm/rewind-hook branch from 0c36d2a to 035a2a4 Compare December 30, 2025 17:41
@Adib234
Adib234 force-pushed the adibakm/rewind-fileops branch 3 times, most recently from 37c0ec4 to b16120c Compare January 7, 2026 17:35
@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-fileops to main January 8, 2026 22:27
@Adib234
Adib234 force-pushed the adibakm/rewind-hook branch from 035a2a4 to e8f0bd2 Compare January 8, 2026 22:33
@github-actions

github-actions Bot commented Jan 8, 2026

Copy link
Copy Markdown

Size Change: -2 B (0%)

Total Size: 22.3 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 22.3 MB -2 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@Adib234
Adib234 enabled auto-merge January 9, 2026 15:04
}
}
return prompts;
}, [conversation.messages]);

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.

warning: this isn't safe if conversation.messages can be mutated (e.g. has messages added to it).

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.

Removed interactions

}, []);

return {
interactions,

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.

if we can avoid adding interactions to the public api that would be good. would allow avoiding memoizing it within this class.

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.

Removed interactions, I'll derive it in the UI component later on

type FileChangeStats,
} from '../utils/rewindFileOps.js';

export function useRewindLogic(conversation: ConversationRecord) {

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: remove Logic from the name. Every hook is logic... it is a filler word. Might call this "useRewind"

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.

changed name

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

lgtm

@Adib234
Adib234 added this pull request to the merge queue Jan 12, 2026
Merged via the queue into main with commit 1589172 Jan 12, 2026
26 checks passed
@Adib234
Adib234 deleted the adibakm/rewind-hook branch January 12, 2026 17:50
thacio added a commit to thacio/auditaria that referenced this pull request Jan 24, 2026
kuishou68 pushed a commit to iOfficeAI/gemini-cli-pro that referenced this pull request Feb 27, 2026
@sripasg sripasg added the size/m A medium sized PR label 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

priority/p1 Important and should be addressed in the near term. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants