feat: add /new command#16848
Conversation
Summary of ChangesHello @sujay-bhandari, 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 user experience by introducing a /new command, enabling users to initiate a fresh conversational context without losing their terminal history. Additionally, it improves the /extensions update command's error reporting, making it more user-friendly by suggesting available extensions when a requested one is not found. These changes aim to streamline interaction and provide clearer feedback within the command-line interface. 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. 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
The pull request introduces a new command, /new, which allows users to start a fresh chat session. This includes resetting the chat history, generating a new session ID, and properly firing session end and start hooks. The changes also include a minor enhancement to the update command's error handling, providing more informative messages when an extension is not found. New test files have been added to ensure the correct functionality of the new command and the updated error handling. The code is well-structured and follows existing patterns within the codebase.
|
Hi @sujay-bhandari thanks for the contribution! 😄 Please update the PR description above with summary and details on this change. If you can we always recommend an image or screenshot and how to properly test it so we can try it out. Thanks! Looking forward to it. |
|
Thanks @jackwotherspoon! 😄 I've updated the PR description with the full summary and testing steps as requested. Quick summary of the changes:
I've added unit tests for both features. Let me know if you need anything else! |
@sujay-bhandari i don't see the PR description updated... maybe you forget to click "Save" (i do this a lot) Once you update we can take a proper look 😄 |
/new command for new session
All done! I've updated the description now. Thanks for the heads up! 😅 |
/new command for new session|
@sujay-bhandari it seems this pull request addresses two totally different issues... From a PR review and engineering best practices we like to follow a separation of concerns pattern. A PR should solve one thing and one thing only. To leave a clean history and in case we have to revert a PR in the future it makes things much cleaner. Do you mind making this PR focus on only one of the two issues and open a separate PR addressing the second piece. |
2b1cd5a to
9aed06b
Compare
jackwotherspoon
left a comment
There was a problem hiding this comment.
Overall I really like the direction of this PR @sujay-bhandari 👏
My main feedback is the following:
The logic in newCommand.ts is nearly identical to clearCommand.ts (resetting chat, managing session ID, firing hooks, flushing telemetry).
Can we extract the common "session reset" logic into a shared helper function (maybe in packages/cli/src/utils/sessionUtils.ts or somewhere similar.
This would reduce code duplication and ensure that future changes to session lifecycle management (like telemetry flushing or hook firing) are applied consistently to both commands.
|
Thanks @jackwotherspoon! Great point. I've refactored the code to extract the common session reset logic into a new shared helper startNewSession in packages/cli/src/utils/sessionUtils.ts. Both /new and the existing /clear command now use this helper to ensure consistent lifecycle management (hooks, telemetry, etc.). I also verified that the tests for both commands pass. Ready for another review! 🚀 |
jackwotherspoon
left a comment
There was a problem hiding this comment.
Overall, looks good to me.
I would look to add SessionStartSource.New and be mindful of license headers
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * Copyright 2026 Google LLC |
There was a problem hiding this comment.
license headers should remain the year the file is created, not updated. Leave this as 2025
| it('should reset chat and start a new session', async () => { | ||
| await newCommand.action(mockContext, ''); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any |
There was a problem hiding this comment.
why are we disabling all these checks?
| kind: CommandKind.BUILT_IN, | ||
| autoExecute: true, | ||
| action: async (context, _args) => { | ||
| await startNewSession(context, SessionStartSource.Clear, false); |
There was a problem hiding this comment.
hmm it looks like here we are using SessionStartSource.Clear?
I would recommend adding a SessionStartSource.New that way hooks or logging can easily differentiate between the two..? Does that sound right to you?
- Modify
packages/core/src/hooks/types.ts:
export enum SessionStartSource {
Startup = 'startup',
Resume = 'resume',
Clear = 'clear',
New = 'new', // Add this
}- Update the PR to use
SessionStartSource.Newhere
|
@jackwotherspoon
Tests are passing and ready for another look! 🚀 |
|
Hi there! Thank you for your contribution to Gemini CLI. To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md. This pull request is being closed because it is not currently linked to an issue. You can easily reopen this PR once you have linked it to an issue. How to link an issue: Thank you for your understanding and for being a part of our community! |
|
I think there is a bug in the session initialization sequence within
What is your take on this |
|
hi @sujay-bhandari i think when resolving conflicts you removed your changes in sessionUtils ie startNewSession please have a look at it otherwise all the tests will fail |
hi @sujay-bhandari awaiting your feedback on this 😁 |
|
@sujay-bhandari let me know if you want to take a look at @ved015 comments above |
| SessionStartSource, | ||
| flushTelemetry, | ||
| } from '@google/gemini-cli-core'; | ||
| import { startNewSession } from '../../utils/sessionUtils.js'; |
There was a problem hiding this comment.
This startNewSession function got deleted from
packages/cli/src/utils/sessionUtils.ts.
You will get that function on your previous commit. Here is the link
3fb37ba#diff-c86d2d5fda4df73694149d6625c00a6be42a13efafb38e474377d4a4d105fde4R539
|
Hi @jackwotherspoon! I noticed that @sujay-bhandari hasn't been active since January 20th, and a few other PRs trying to solve this issue have been closed recently to avoid duplication. If you give the green light, I'd love to help get this over the finish line. Let me know how you'd prefer to proceed |
|
Closing due to inactivity 👍 |
PR Description
Summary of Changes
This Pull Request addresses the following issue:
/newcommand: Implements a new slash command/newthat starts a fresh chat session without clearing the terminal history. This allows users to "start over" with the LLM context while preserving the visible history of the previous session, which is also saved to disk for future resumption.Details
/newCommandrandomUUID()to generate a new session ID.client.resetChat()to clear the in-memory chat context.ChatRecordingServiceto ensure the new session marks the end of the previous one (which is flushed to disk).SessionEnd(Clear) andSessionStart(Clear) hooks to maintain proper lifecycle management./clear), fulfilling the user requirement to keep context visible.Related Issue
Fixes #16835
How to Test
Testing
/newCommandnpm start./new./resume.