feat(cli): add /new command to start a fresh session while preserving…#20442
feat(cli): add /new command to start a fresh session while preserving…#20442ActuallyAnson wants to merge 1 commit intogoogle-gemini:mainfrom
Conversation
… current for /resume Unlike /clear which makes the current session unavailable for resumption, /new assigns a fresh session ID before reinitializing the recording service, ensuring the previous conversation remains accessible via /resume. Closes google-gemini#16835
Summary of ChangesHello @ActuallyAnson, 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 enhancement to the CLI by adding a Highlights
Changelog
Activity
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.
Code Review
This pull request introduces a /new command to start a fresh chat session while preserving the current one. The implementation includes the command logic, unit tests, and integration into the CLI's command loader.
My review found a critical issue in the implementation of the /new command's action. The logic for creating a new session recording is flawed due to a stale object reference, which prevents the command from working as intended. I have provided a detailed comment and a code suggestion to correct the sequence of operations.
| if (geminiClient) { | ||
| context.ui.setDebugMessage( | ||
| 'Starting new session and preserving current conversation.', | ||
| ); | ||
| await geminiClient.resetChat(); | ||
| } else { | ||
| context.ui.setDebugMessage('Starting new session.'); | ||
| } | ||
|
|
||
| // Reset user steering hints | ||
| config?.userHintService.clear(); | ||
|
|
||
| // Assign a new session ID before re-initializing the recording service. | ||
| // This ensures the previous session's recording is preserved on disk under | ||
| // its original session ID and remains available via /resume. | ||
| if (config && chatRecordingService) { | ||
| const newSessionId = randomUUID(); | ||
| config.setSessionId(newSessionId); | ||
| chatRecordingService.initialize(); | ||
| } |
There was a problem hiding this comment.
The current logic for starting a new session is flawed. The chatRecordingService variable is captured before geminiClient.resetChat() is called. Since resetChat() creates a new service instance internally, the chatRecordingService variable becomes a stale reference. Calling initialize() on this stale reference doesn't affect the active session, and the old session is not preserved as intended.
To fix this, set the new session ID on the config object before calling resetChat(). This allows resetChat() to use the new ID when it initializes the new session recording.
The chatRecordingService variable (defined on lines 27-30) will become unused with this change and should be removed.
if (geminiClient && config) {
context.ui.setDebugMessage(
'Starting new session and preserving current conversation.',
);
// Assign a new session ID before resetting the chat. `resetChat` will then
// use this new ID to initialize the new session recording.
const newSessionId = randomUUID();
config.setSessionId(newSessionId);
await geminiClient.resetChat();
} else {
context.ui.setDebugMessage('Starting new session.');
}
// Reset user steering hints
config?.userHintService.clear();
feat(cli): add /new command to start a fresh session
Introduce a built-in /new command that starts a new conversation
while preserving the current session for later use with /resume.
The command:
Includes unit tests covering lifecycle ordering and behavior
when the config service is absent.
Fixes #16848