-
Notifications
You must be signed in to change notification settings - Fork 13k
feat(plan): implement plan slash command
#17698
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
35a583d
complete
Adib234 ac5b286
fix build issues and address comment by bot
Adib234 b713344
create logic for accessing current plan based on exit plan mode
Adib234 80ce06c
change plan slash command doc
Adib234 fb75eba
fix tests
Adib234 c920454
remove /plan command from documentation for now
Adib234 e4480dd
address nits
Adib234 355e596
fix tests
Adib234 823d7d2
update naming to approved
Adib234 2a6cad5
address nits
Adib234 10014a8
add tests to confirm plan slash command is only available when plan m…
Adib234 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,133 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; | ||
| import { planCommand } from './planCommand.js'; | ||
| import { type CommandContext } from './types.js'; | ||
| import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; | ||
| import { MessageType } from '../types.js'; | ||
| import { | ||
| ApprovalMode, | ||
| coreEvents, | ||
| processSingleFileContent, | ||
| type ProcessedFileReadResult, | ||
| } from '@google/gemini-cli-core'; | ||
|
|
||
| vi.mock('@google/gemini-cli-core', async (importOriginal) => { | ||
| const actual = | ||
| await importOriginal<typeof import('@google/gemini-cli-core')>(); | ||
| return { | ||
| ...actual, | ||
| coreEvents: { | ||
| emitFeedback: vi.fn(), | ||
| }, | ||
| processSingleFileContent: vi.fn(), | ||
| partToString: vi.fn((val) => val), | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock('node:path', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('node:path')>(); | ||
| return { | ||
| ...actual, | ||
| default: { ...actual }, | ||
| join: vi.fn((...args) => args.join('/')), | ||
| }; | ||
| }); | ||
|
|
||
| describe('planCommand', () => { | ||
| let mockContext: CommandContext; | ||
|
|
||
| beforeEach(() => { | ||
| mockContext = createMockCommandContext({ | ||
| services: { | ||
| config: { | ||
| isPlanEnabled: vi.fn(), | ||
| setApprovalMode: vi.fn(), | ||
| getApprovedPlanPath: vi.fn(), | ||
| getApprovalMode: vi.fn(), | ||
| getFileSystemService: vi.fn(), | ||
| storage: { | ||
| getProjectTempPlansDir: vi.fn().mockReturnValue('/mock/plans/dir'), | ||
| }, | ||
| }, | ||
| }, | ||
| ui: { | ||
| addItem: vi.fn(), | ||
| }, | ||
| } as unknown as CommandContext); | ||
|
|
||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('should have the correct name and description', () => { | ||
| expect(planCommand.name).toBe('plan'); | ||
| expect(planCommand.description).toBe( | ||
| 'Switch to Plan Mode and view current plan', | ||
| ); | ||
| }); | ||
|
|
||
| it('should switch to plan mode if enabled', async () => { | ||
| vi.mocked(mockContext.services.config!.isPlanEnabled).mockReturnValue(true); | ||
| vi.mocked(mockContext.services.config!.getApprovedPlanPath).mockReturnValue( | ||
| undefined, | ||
| ); | ||
|
|
||
| if (!planCommand.action) throw new Error('Action missing'); | ||
| await planCommand.action(mockContext, ''); | ||
|
|
||
| expect(mockContext.services.config!.setApprovalMode).toHaveBeenCalledWith( | ||
| ApprovalMode.PLAN, | ||
| ); | ||
| expect(coreEvents.emitFeedback).toHaveBeenCalledWith( | ||
| 'info', | ||
| 'Switched to Plan Mode.', | ||
| ); | ||
| }); | ||
|
|
||
| it('should show "No approved plan found" if no approved plan path in config', async () => { | ||
| vi.mocked(mockContext.services.config!.isPlanEnabled).mockReturnValue(true); | ||
| vi.mocked(mockContext.services.config!.getApprovedPlanPath).mockReturnValue( | ||
| undefined, | ||
| ); | ||
|
|
||
| if (!planCommand.action) throw new Error('Action missing'); | ||
| await planCommand.action(mockContext, ''); | ||
|
|
||
| expect(coreEvents.emitFeedback).toHaveBeenCalledWith( | ||
| 'error', | ||
| 'No approved plan found. Please create and approve a plan first.', | ||
| ); | ||
| }); | ||
|
|
||
| it('should display the approved plan from config', async () => { | ||
| const mockPlanPath = '/mock/plans/dir/approved-plan.md'; | ||
| vi.mocked(mockContext.services.config!.isPlanEnabled).mockReturnValue(true); | ||
| vi.mocked(mockContext.services.config!.getApprovedPlanPath).mockReturnValue( | ||
| mockPlanPath, | ||
| ); | ||
| vi.mocked(processSingleFileContent).mockResolvedValue({ | ||
| llmContent: '# Approved Plan Content', | ||
| returnDisplay: '# Approved Plan Content', | ||
| } as ProcessedFileReadResult); | ||
|
|
||
| if (!planCommand.action) throw new Error('Action missing'); | ||
| await planCommand.action(mockContext, ''); | ||
|
|
||
| expect(coreEvents.emitFeedback).toHaveBeenCalledWith( | ||
| 'info', | ||
| 'Approved Plan: approved-plan.md', | ||
| ); | ||
| expect(mockContext.ui.addItem).toHaveBeenCalledWith({ | ||
| type: MessageType.GEMINI, | ||
| text: '# Approved Plan Content', | ||
| }); | ||
| }); | ||
| }); |
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,69 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { CommandKind, type SlashCommand } from './types.js'; | ||
| import { | ||
| ApprovalMode, | ||
| coreEvents, | ||
| debugLogger, | ||
| processSingleFileContent, | ||
| partToString, | ||
| } from '@google/gemini-cli-core'; | ||
| import { MessageType } from '../types.js'; | ||
| import * as path from 'node:path'; | ||
|
|
||
| export const planCommand: SlashCommand = { | ||
| name: 'plan', | ||
| description: 'Switch to Plan Mode and view current plan', | ||
| kind: CommandKind.BUILT_IN, | ||
| autoExecute: true, | ||
| action: async (context) => { | ||
| const config = context.services.config; | ||
| if (!config) { | ||
| debugLogger.debug('Plan command: config is not available in context'); | ||
| return; | ||
| } | ||
|
|
||
| const previousApprovalMode = config.getApprovalMode(); | ||
| config.setApprovalMode(ApprovalMode.PLAN); | ||
|
|
||
| if (previousApprovalMode !== ApprovalMode.PLAN) { | ||
| coreEvents.emitFeedback('info', 'Switched to Plan Mode.'); | ||
| } | ||
|
|
||
| const approvedPlanPath = config.getApprovedPlanPath(); | ||
|
|
||
| if (!approvedPlanPath) { | ||
| coreEvents.emitFeedback( | ||
| 'error', | ||
| 'No approved plan found. Please create and approve a plan first.', | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const content = await processSingleFileContent( | ||
| approvedPlanPath, | ||
| config.storage.getProjectTempPlansDir(), | ||
| config.getFileSystemService(), | ||
| ); | ||
| const fileName = path.basename(approvedPlanPath); | ||
|
|
||
| coreEvents.emitFeedback('info', `Approved Plan: ${fileName}`); | ||
|
|
||
| context.ui.addItem({ | ||
| type: MessageType.GEMINI, | ||
| text: partToString(content.llmContent), | ||
| }); | ||
| } catch (error) { | ||
| coreEvents.emitFeedback( | ||
| 'error', | ||
| `Failed to read approved plan at ${approvedPlanPath}: ${error}`, | ||
| error, | ||
| ); | ||
| } | ||
| }, | ||
| }; |
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
jerop marked this conversation as resolved.
Show resolved
Hide resolved
|
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.