-
Notifications
You must be signed in to change notification settings - Fork 10.2k
feat(cli): Pop up dialog when turns exceed threshold #15509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(cli): Pop up dialog when turns exceed threshold #15509
Conversation
Add new config variable renewSessionTurnsThreshold. If session turns exceed the threshold, pop up a dialog, let user choose to compress conversation or start a new session.
Summary of ChangesHello @circlepen, 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 CLI's conversational experience by introducing a mechanism to manage long-running sessions. It adds a configurable threshold for conversation turns, after which users are prompted with a dialog to either compress their current chat or begin a new one. This helps maintain context and prevent conversations from becoming unwieldy, improving overall usability and efficiency. Highlights
🧠 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 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. 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
|
There was a problem hiding this comment.
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 feature to prompt users when a session's turn count exceeds a configured threshold. The implementation is solid, but I've identified a couple of areas for improvement. There's a consistent naming convention violation for the new state variable RenewSessionConfirmationRequest, which should be camelCased for consistency with the rest of the codebase. Additionally, there's an opportunity to refactor the logic for resetting the session turn count to make it more explicit and robust. My detailed comments provide specific suggestions for these changes.
| handleApprovalModeChange, | ||
| activePtyId, | ||
| loopDetectionConfirmationRequest, | ||
| RenewSessionConfirmationRequest, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| !!customDialog || | ||
| confirmUpdateExtensionRequests.length > 0 || | ||
| !!loopDetectionConfirmationRequest || | ||
| !!RenewSessionConfirmationRequest || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| confirmationRequest, | ||
| confirmUpdateExtensionRequests, | ||
| loopDetectionConfirmationRequest, | ||
| RenewSessionConfirmationRequest, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (uiState.RenewSessionConfirmationRequest) { | ||
| return ( | ||
| <RenewSessionDialog | ||
| maxSessionTurns={ | ||
| settings.merged.model?.renewSessionTurnsThreshold ?? -1 | ||
| } | ||
| onComplete={uiState.RenewSessionConfirmationRequest.onComplete} | ||
| /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency and adherence to naming conventions, RenewSessionConfirmationRequest should be renewSessionConfirmationRequest.
| if (uiState.RenewSessionConfirmationRequest) { | |
| return ( | |
| <RenewSessionDialog | |
| maxSessionTurns={ | |
| settings.merged.model?.renewSessionTurnsThreshold ?? -1 | |
| } | |
| onComplete={uiState.RenewSessionConfirmationRequest.onComplete} | |
| /> | |
| if (uiState.renewSessionConfirmationRequest) { | |
| return ( | |
| <RenewSessionDialog | |
| maxSessionTurns={ | |
| settings.merged.model?.renewSessionTurnsThreshold ?? -1 | |
| } | |
| onComplete={uiState.renewSessionConfirmationRequest.onComplete} | |
| /> |
| confirmationRequest: ConfirmationRequest | null; | ||
| confirmUpdateExtensionRequests: ConfirmationRequest[]; | ||
| loopDetectionConfirmationRequest: LoopDetectionConfirmationRequest | null; | ||
| RenewSessionConfirmationRequest: RenewSessionConfirmationRequest | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other properties in this interface and to follow TypeScript/JavaScript naming conventions, this property should be named renewSessionConfirmationRequest (camelCase).
| RenewSessionConfirmationRequest: RenewSessionConfirmationRequest | null; | |
| renewSessionConfirmationRequest: RenewSessionConfirmationRequest | null; |
| const [RenewSessionConfirmationRequest, setRenewSessionConfirmationRequest] = | ||
| useState<{ | ||
| onComplete: (result: { | ||
| userSelection: 'compress_session' | 'new_session'; | ||
| }) => void; | ||
| } | null>(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React state variables should follow camelCase naming conventions for consistency with the rest of the codebase (e.g., loopDetectionConfirmationRequest). Please rename RenewSessionConfirmationRequest to renewSessionConfirmationRequest.
| const [RenewSessionConfirmationRequest, setRenewSessionConfirmationRequest] = | |
| useState<{ | |
| onComplete: (result: { | |
| userSelection: 'compress_session' | 'new_session'; | |
| }) => void; | |
| } | null>(null); | |
| const [renewSessionConfirmationRequest, setRenewSessionConfirmationRequest] = | |
| useState<{ | |
| onComplete: (result: { | |
| userSelection: 'compress_session' | 'new_session'; | |
| }) => void; | |
| } | null>(null); |
| const handleRenewSessionEvent = useCallback((): void => { | ||
| if (RenewSessionConfirmationRequest) { | ||
| return; | ||
| } | ||
|
|
||
| if (pendingHistoryItemRef.current) { | ||
| addItem(pendingHistoryItemRef.current, Date.now()); | ||
| setPendingHistoryItem(null); | ||
| } | ||
| geminiClient.resetSessionTurnCount(); | ||
|
|
||
| setRenewSessionConfirmationRequest({ | ||
| onComplete: (result: { | ||
| userSelection: 'compress_session' | 'new_session'; | ||
| }) => { | ||
| setRenewSessionConfirmationRequest(null); | ||
|
|
||
| if (result.userSelection === 'compress_session') { | ||
| void handleSlashCommandRef.current('/compress'); | ||
| } else if (result.userSelection === 'new_session') { | ||
| void handleSlashCommandRef.current('/clear'); | ||
| } | ||
| }, | ||
| }); | ||
| }, [ | ||
| addItem, | ||
| geminiClient, | ||
| RenewSessionConfirmationRequest, | ||
| pendingHistoryItemRef, | ||
| setPendingHistoryItem, | ||
| ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of improvements that can be made here:
- Naming Convention: The state variable
RenewSessionConfirmationRequestshould be renamed torenewSessionConfirmationRequestto follow camelCase conventions and for consistency with other similar variables in the codebase. - Logic Correction: The call to
geminiClient.resetSessionTurnCount()should be moved inside theonCompletehandler. Resetting the turn count should be a direct consequence of the user's action. Specifically, it should be tied to thecompress_sessionaction, as the/clearcommand (fornew_session) already handles resetting the turn count. This makes the logic clearer and more robust.
The suggested code applies these changes.
const handleRenewSessionEvent = useCallback((): void => {
if (renewSessionConfirmationRequest) {
return;
}
if (pendingHistoryItemRef.current) {
addItem(pendingHistoryItemRef.current, Date.now());
setPendingHistoryItem(null);
}
setRenewSessionConfirmationRequest({
onComplete: (result: {
userSelection: 'compress_session' | 'new_session';
}) => {
setRenewSessionConfirmationRequest(null);
if (result.userSelection === 'compress_session') {
geminiClient.resetSessionTurnCount();
void handleSlashCommandRef.current('/compress');
} else if (result.userSelection === 'new_session') {
void handleSlashCommandRef.current('/clear');
}
},
});
}, [
addItem,
geminiClient,
renewSessionConfirmationRequest,
pendingHistoryItemRef,
setPendingHistoryItem,
]);| handleApprovalModeChange, | ||
| activePtyId, | ||
| loopDetectionConfirmationRequest, | ||
| RenewSessionConfirmationRequest, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary
If the session turns exceed threshold or detect a new topic, ask user to compress or start new session.
Details
Add new config variable renewSessionTurnsThreshold.
If session turns exceed the threshold, pop up a dialog, let user choose to compress conversation
or start a new session.
TODO: Add detection for user query, if the new query is in different topic to previous ones, then pop up a dialog
to let user choose to compress conversation or start a new session.
Related Issues
How to Validate
Pre-Merge Checklist