feat(cli): prompt to resume session when first prompt matches history#24720
feat(cli): prompt to resume session when first prompt matches history#24720JayadityaGit wants to merge 1 commit intogoogle-gemini:mainfrom
Conversation
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 enhances the user experience by proactively identifying when a new session's initial prompt duplicates the start of a previous conversation. By intercepting the first submission, the application now offers users a seamless way to resume historical sessions, reducing friction and improving workflow continuity. 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 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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a session resume prompt that appears when a user's first message in a new session matches the first message of an existing session. The implementation includes state management in UIStateContext, a new SessionResumePromptDialog component, and logic in AppContainer to intercept submissions and check for matches. Feedback was provided regarding the matching logic: the cleanMessage utility should be used to ensure consistent comparison between raw input and sanitized session data, and findLast should be used to prioritize the most recent matching session over older ones.
| import { registerCleanup, runExitCleanup } from '../utils/cleanup.js'; | ||
| import { relaunchApp } from '../utils/processUtils.js'; | ||
| import type { SessionInfo } from '../utils/sessionUtils.js'; | ||
| import { type SessionInfo, getSessionFiles } from '../utils/sessionUtils.js'; |
There was a problem hiding this comment.
The cleanMessage utility is required to correctly compare the user's input with the stored session messages, as the latter are sanitized before being saved. Please add it to the imports from sessionUtils.js.
| import { type SessionInfo, getSessionFiles } from '../utils/sessionUtils.js'; | |
| import { type SessionInfo, getSessionFiles, cleanMessage } from '../utils/sessionUtils.js'; |
References
- Always treat user-provided data as untrusted and apply proper validation and sanitization at the point of use, even if it is believed to have been filtered or sanitized upstream.
| const matchingSession = sessions.find( | ||
| (s) => s.firstUserMessage === trimmed && !s.isCurrentSession, | ||
| ); |
There was a problem hiding this comment.
There are two issues with the current matching logic:
- Matching Accuracy: The
firstUserMessageinSessionInfois processed usingcleanMessage(which collapses whitespace and removes non-printable characters). Comparing it directly againsttrimmedwill fail if the user's input contains multiple spaces or newlines. You should applycleanMessageto the input before comparison. - Match Priority:
sessions.findreturns the first match found. SincegetSessionFilesreturns sessions sorted bystartTimeascending (oldest first), this will match the oldest session. Users typically expect to resume the most recent relevant conversation. UsingfindLastensures the most recent matching session is prioritized.
Note: findLast is supported in Node.js 20+.
const cleaned = cleanMessage(submittedValue);
const matchingSession = sessions.findLast(
(s) => s.firstUserMessage === cleaned && !s.isCurrentSession,
);
References
- Always treat user-provided data as untrusted and apply proper validation and sanitization at the point of use, even if it is believed to have been filtered or sanitized upstream.
- When selecting an item from a list where simple IDs may not be unique, use a guaranteed unique identifier, such as an index or a composite key, to avoid ambiguity when retrieving the selected item with methods like Array.prototype.find().
|
This is a feature where FOR THE VERY FIRST PROMPT of a NEW SESSION if the user prompts the same old prompt which is corresponding to the previous sessions then there will be a dialog which asks the user either to resume or start new again Usually to resume a session we need to use /chat But there are three main possibilties the user prompts their first prompt matching the old previous session (which at present starts as new request)
Remember this interception check only happens with the very FIRST PROMPT of a new session (VERY IMPORTANT) I feel like this is going to upgrade the "resume previous session feature (/chat)" which save time and also save costs. As of now i am marking this as draft i will work on this further if the communtiy shows interest. @jacob314 (tagging for visibility) |
|
Closing it because thoughts from @scidomino really had an impact on my vision in a positive way 👍 |
Summary
This PR adds a session resume prompt when the user's first prompt in a new session matches the first prompt of a previous historical session. This improves the user experience by proactively offering to resume ongoing conversations.
Details
AppContainer.tsx.~/.gemini/tmp/chatsfor sessions where the first user message exactly matches the current input.SessionResumePromptDialogallowing the user to choose between resuming the old session or starting a new one.dialogsVisibleto correctly manage UI state during the prompt.Related Issues
Closes #24719
Pre-Merge Checklist