-
Notifications
You must be signed in to change notification settings - Fork 13k
Add /rename slash command #14616
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
Closed
Closed
Add /rename slash command #14616
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e7cf4e8
Add /rename slash command
bl-ue 9bc0fd3
Fix Gemini's review
bl-ue d94c1d6
Merge branch 'main' into add-rename-slash-command
bl-ue fa31be2
Fix the tests
bl-ue 0be4803
Skip summary generation if the user renamed the current session
bl-ue b9c60c9
Merge branch 'main' into add-rename-slash-command
bl-ue cec0eee
Merge branch 'main' into add-rename-slash-command
bl-ue 7a35c2d
Add support for resuming via display name and summary
bl-ue 1ca7d38
Merge branch 'main' into add-rename-slash-command
bl-ue ef2aeb8
Merge branch 'main' into add-rename-slash-command
bl-ue 571db2b
Merge branch 'main' into add-rename-slash-command
bl-ue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { renameCommand } from './renameCommand.js'; | ||
| import { ChatRecordingService, type Config } from '@google/gemini-cli-core'; | ||
| import { SessionSelector } from '../../utils/sessionUtils.js'; | ||
| import type { CommandContext } from './types.js'; | ||
| import path from 'node:path'; | ||
|
|
||
| vi.mock('@google/gemini-cli-core'); | ||
| vi.mock('../../utils/sessionUtils.js'); | ||
|
|
||
| describe('renameCommand', () => { | ||
| let mockConfig: Config; | ||
| let mockContext: CommandContext; | ||
| let mockChatRecordingService: { | ||
| initialize: ReturnType<typeof vi.fn>; | ||
| setDisplayName: ReturnType<typeof vi.fn>; | ||
| }; | ||
| let mockSessionSelector: { | ||
| listSessions: ReturnType<typeof vi.fn>; | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| mockConfig = { | ||
| storage: { | ||
| getProjectTempDir: vi.fn().mockReturnValue('/tmp/gemini'), | ||
| }, | ||
| } as unknown as Config; | ||
|
|
||
| mockContext = { | ||
| services: { | ||
| config: mockConfig, | ||
| }, | ||
| } as unknown as CommandContext; | ||
|
|
||
| mockChatRecordingService = { | ||
| initialize: vi.fn(), | ||
| setDisplayName: vi.fn(), | ||
| }; | ||
| vi.mocked(ChatRecordingService).mockImplementation( | ||
| () => mockChatRecordingService as unknown as ChatRecordingService, | ||
| ); | ||
|
|
||
| mockSessionSelector = { | ||
| listSessions: vi.fn(), | ||
| }; | ||
| vi.mocked(SessionSelector).mockImplementation( | ||
| () => mockSessionSelector as unknown as SessionSelector, | ||
| ); | ||
| }); | ||
|
|
||
| it('should require a name argument', async () => { | ||
| const result = await renameCommand.action!(mockContext, ''); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: 'Please provide a new name for the session.', | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle empty name string', async () => { | ||
| const result = await renameCommand.action!(mockContext, ' '); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: 'Please provide a new name for the session.', | ||
| }); | ||
| }); | ||
|
|
||
| it('should silently ignore if no active session is found', async () => { | ||
| mockSessionSelector.listSessions.mockResolvedValue([ | ||
| { id: 'other-session', isCurrentSession: false }, | ||
| ]); | ||
|
|
||
| const result = await renameCommand.action!(mockContext, 'New Name'); | ||
|
|
||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should rename the current session', async () => { | ||
| const currentSession = { | ||
| id: 'current-session-id', | ||
| fileName: 'session-file.json', | ||
| isCurrentSession: true, | ||
| }; | ||
| mockSessionSelector.listSessions.mockResolvedValue([currentSession]); | ||
|
|
||
| const result = await renameCommand.action!(mockContext, 'New Name'); | ||
|
|
||
| const expectedFilePath = path.join( | ||
| '/tmp/gemini', | ||
| 'chats', | ||
| 'session-file.json', | ||
| ); | ||
|
|
||
| expect(mockChatRecordingService.initialize).toHaveBeenCalledWith({ | ||
| sessionId: 'current-session-id', | ||
| filePath: expectedFilePath, | ||
| }); | ||
| expect(mockChatRecordingService.setDisplayName).toHaveBeenCalledWith( | ||
| 'New Name', | ||
| ); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'Session renamed to "New Name"', | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { ChatRecordingService } from '@google/gemini-cli-core'; | ||
| import path from 'node:path'; | ||
| import { SessionSelector } from '../../utils/sessionUtils.js'; | ||
| import { | ||
| CommandKind, | ||
| type SlashCommand, | ||
| type SlashCommandActionReturn, | ||
| } from './types.js'; | ||
|
|
||
| export const renameCommand: SlashCommand = { | ||
| name: 'rename', | ||
| description: 'Set the display name for the current session', | ||
| kind: CommandKind.BUILT_IN, | ||
| action: async (context, input): Promise<SlashCommandActionReturn | void> => { | ||
| const newName = input.trim(); | ||
| if (!newName) { | ||
| return { | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: 'Please provide a new name for the session.', | ||
| }; | ||
| } | ||
|
|
||
| if (!context.services.config) { | ||
| return; | ||
| } | ||
|
|
||
| const sessionSelector = new SessionSelector(context.services.config); | ||
| const sessions = await sessionSelector.listSessions(); | ||
| const currentSession = sessions.find((s) => s.isCurrentSession); | ||
|
|
||
| if (!currentSession) { | ||
| return; | ||
| } | ||
|
|
||
| const chatsDir = path.join( | ||
| context.services.config.storage.getProjectTempDir(), | ||
| 'chats', | ||
| ); | ||
| const filePath = path.join(chatsDir, currentSession.fileName); | ||
|
|
||
| const recordingService = new ChatRecordingService(context.services.config); | ||
| recordingService.initialize({ | ||
| sessionId: currentSession.id, | ||
| filePath, | ||
| }); | ||
|
|
||
| recordingService.setDisplayName(newName); | ||
bl-ue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return { | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: `Session renamed to "${newName}"`, | ||
| }; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.