-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(cli): implement /plan command for plan mode #2921
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 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
135699d
feat(cli): implement /plan command for plan mode
wenshao 007fff6
fix(cli): fix /plan command bugs and clean up hallucinated i18n keys
wenshao 63c4bd0
fix(docs): align /plan description wording with i18n keys
wenshao 09ccc1b
fix(docs): add /plan <task> usage example to commands table
wenshao c597847
feat(core): add prePlanMode tracking to restore previous approval mode
wenshao b8e81c0
feat(core): add plan file persistence to disk
wenshao 7a2f588
fix(core): use optional field syntax for prePlanMode declaration
wenshao e038ce9
fix(core): only suppress ENOENT in loadPlan, rethrow other errors
wenshao ee8fcc9
docs: add /plan command usage to approval mode documentation
wenshao 2e089cc
fix(docs): fix mode count and update plan example in approval-mode docs
wenshao 6bb5e0a
Merge remote-tracking branch 'origin/main' into feat/plan-mode
wenshao b50f23f
fix: correct copyright year from 2026 to 2025 in planCommand.ts
wenshao 1d4c17b
fix: rename /plan execute to /plan exit
wenshao 121af70
fix: ProceedOnce should set DEFAULT mode, not restore pre-plan mode
wenshao 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
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
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
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,159 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect, beforeEach, vi, type Mock } from 'vitest'; | ||
| import { planCommand } from './planCommand.js'; | ||
| import { type CommandContext } from './types.js'; | ||
| import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; | ||
| import { ApprovalMode } from '@qwen-code/qwen-code-core'; | ||
|
|
||
| describe('planCommand', () => { | ||
| let mockContext: CommandContext; | ||
|
|
||
| beforeEach(() => { | ||
| mockContext = createMockCommandContext({ | ||
| services: { | ||
| config: { | ||
| getApprovalMode: vi.fn().mockReturnValue(ApprovalMode.DEFAULT), | ||
| getPrePlanMode: vi.fn().mockReturnValue(ApprovalMode.DEFAULT), | ||
| setApprovalMode: vi.fn(), | ||
| } as unknown as import('@qwen-code/qwen-code-core').Config, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should switch to plan mode if not in plan mode', async () => { | ||
| if (!planCommand.action) { | ||
| throw new Error('The plan command must have an action.'); | ||
| } | ||
|
|
||
| const result = await planCommand.action(mockContext, ''); | ||
|
|
||
| expect(mockContext.services.config?.setApprovalMode).toHaveBeenCalledWith( | ||
| ApprovalMode.PLAN, | ||
| ); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: | ||
| 'Enabled plan mode. The agent will analyze and plan without executing tools.', | ||
| }); | ||
| }); | ||
|
|
||
| it('should return submit prompt if arguments are provided when switching to plan mode', async () => { | ||
| if (!planCommand.action) { | ||
| throw new Error('The plan command must have an action.'); | ||
| } | ||
|
|
||
| const result = await planCommand.action(mockContext, 'refactor the code'); | ||
|
|
||
| expect(mockContext.services.config?.setApprovalMode).toHaveBeenCalledWith( | ||
| ApprovalMode.PLAN, | ||
| ); | ||
| expect(result).toEqual({ | ||
| type: 'submit_prompt', | ||
| content: [{ text: 'refactor the code' }], | ||
| }); | ||
| }); | ||
|
|
||
| it('should return already in plan mode if mode is already plan', async () => { | ||
| if (!planCommand.action) { | ||
| throw new Error('The plan command must have an action.'); | ||
| } | ||
|
|
||
| (mockContext.services.config?.getApprovalMode as Mock).mockReturnValue( | ||
| ApprovalMode.PLAN, | ||
| ); | ||
|
|
||
| const result = await planCommand.action(mockContext, ''); | ||
|
|
||
| expect(mockContext.services.config?.setApprovalMode).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'Already in plan mode. Use "/plan exit" to exit plan mode.', | ||
| }); | ||
| }); | ||
|
|
||
| it('should return submit prompt if arguments are provided and already in plan mode', async () => { | ||
| if (!planCommand.action) { | ||
| throw new Error('The plan command must have an action.'); | ||
| } | ||
|
|
||
| (mockContext.services.config?.getApprovalMode as Mock).mockReturnValue( | ||
| ApprovalMode.PLAN, | ||
| ); | ||
|
|
||
| const result = await planCommand.action(mockContext, 'keep planning'); | ||
|
|
||
| expect(mockContext.services.config?.setApprovalMode).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ | ||
| type: 'submit_prompt', | ||
| content: [{ text: 'keep planning' }], | ||
| }); | ||
| }); | ||
|
|
||
| it('should exit plan mode when exit argument is passed', async () => { | ||
| if (!planCommand.action) { | ||
| throw new Error('The plan command must have an action.'); | ||
| } | ||
|
|
||
| (mockContext.services.config?.getApprovalMode as Mock).mockReturnValue( | ||
| ApprovalMode.PLAN, | ||
| ); | ||
|
|
||
| const result = await planCommand.action(mockContext, 'exit'); | ||
|
|
||
| expect(mockContext.services.config?.setApprovalMode).toHaveBeenCalledWith( | ||
| ApprovalMode.DEFAULT, | ||
| ); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'Exited plan mode. Previous approval mode restored.', | ||
| }); | ||
| }); | ||
|
|
||
| it('should restore pre-plan mode when executing from plan mode', async () => { | ||
| if (!planCommand.action) { | ||
| throw new Error('The plan command must have an action.'); | ||
| } | ||
|
|
||
| (mockContext.services.config?.getApprovalMode as Mock).mockReturnValue( | ||
| ApprovalMode.PLAN, | ||
| ); | ||
| (mockContext.services.config?.getPrePlanMode as Mock).mockReturnValue( | ||
| ApprovalMode.AUTO_EDIT, | ||
| ); | ||
|
|
||
| const result = await planCommand.action(mockContext, 'exit'); | ||
|
|
||
| expect(mockContext.services.config?.setApprovalMode).toHaveBeenCalledWith( | ||
| ApprovalMode.AUTO_EDIT, | ||
| ); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'Exited plan mode. Previous approval mode restored.', | ||
| }); | ||
| }); | ||
|
|
||
| it('should return error when execute is used but not in plan mode', async () => { | ||
| if (!planCommand.action) { | ||
| throw new Error('The plan command must have an action.'); | ||
| } | ||
|
|
||
| // Default mock returns ApprovalMode.DEFAULT (not PLAN) | ||
| const result = await planCommand.action(mockContext, 'exit'); | ||
|
|
||
| expect(mockContext.services.config?.setApprovalMode).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: 'Not in plan mode. Use "/plan" to enter plan mode first.', | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.