-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: add Plan Mode support for Copilot CLI background agents #3881
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c78a30
Plan mode for background agents
DonJayamanne 8509b64
Updates
DonJayamanne a917c86
Fix cache directory name and correct markdown syntax in PlanAgentProv…
DonJayamanne a1ab287
Merge branch 'main' into don/background-plan-bare-fly
DonJayamanne 12ee5a2
Merge branch 'main' into don/background-plan-bare-fly
DonJayamanne f6cd139
feat: add Plan Mode support for Copilot CLI agents
DonJayamanne 862f840
fix: update configuration check for CLI Plan Mode in ChatSessionsContrib
DonJayamanne fe5015c
Ensure we log the error
DonJayamanne 57e8a34
fix tests
DonJayamanne 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
71 changes: 71 additions & 0 deletions
71
src/extension/chatSessions/vscode-node/copilotCLIPlanAgentProvider.ts
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,71 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { Uri, type CancellationToken, type ChatCustomAgentProvider, type ChatRequestModeInstructions, type ChatResource } from 'vscode'; | ||
| import { AGENT_FILE_EXTENSION } from '../../../platform/customInstructions/common/promptTypes'; | ||
| import { IVSCodeExtensionContext } from '../../../platform/extContext/common/extensionContext'; | ||
| import { IFileSystemService } from '../../../platform/filesystem/common/fileSystemService'; | ||
| import { ILogService } from '../../../platform/log/common/logService'; | ||
| import { Emitter } from '../../../util/vs/base/common/event'; | ||
| import { Disposable } from '../../../util/vs/base/common/lifecycle'; | ||
|
|
||
| const planPrompt = `Plan model is configured and defined within Github Copilot CLI`; | ||
|
|
||
| export function isCopilotCLIPlanAgent(mode: ChatRequestModeInstructions) { | ||
| return mode.name.toLowerCase() === 'plan' && mode.content.trim().includes(planPrompt.trim()); | ||
| } | ||
|
|
||
| export class PlanAgentProvider extends Disposable implements ChatCustomAgentProvider { | ||
|
DonJayamanne marked this conversation as resolved.
|
||
| private static readonly CACHE_DIR = 'github.copilotcli'; | ||
| private static readonly AGENT_FILENAME = `Plan${AGENT_FILE_EXTENSION}`; | ||
|
|
||
| private readonly _onDidChangeCustomAgents = this._register(new Emitter<void>()); | ||
| readonly onDidChangeCustomAgents = this._onDidChangeCustomAgents.event; | ||
|
|
||
| constructor( | ||
| @IVSCodeExtensionContext private readonly extensionContext: IVSCodeExtensionContext, | ||
| @IFileSystemService private readonly fileSystemService: IFileSystemService, | ||
| @ILogService private readonly logService: ILogService, | ||
| ) { | ||
| super(); | ||
| } | ||
|
|
||
| async provideCustomAgents( | ||
| _context: unknown, | ||
| _token: CancellationToken | ||
| ): Promise<ChatResource[]> { | ||
| // Generate .agent.md content | ||
| const content = `--- | ||
| name: Plan | ||
| description: Github Copilot CLI Plan agent | ||
|
DonJayamanne marked this conversation as resolved.
|
||
| target: github-copilot | ||
|
DonJayamanne marked this conversation as resolved.
|
||
| --- | ||
| ${planPrompt} | ||
| For more details on Plan mode, see https://github.blog/changelog/2026-01-21-github-copilot-cli-plan-before-you-build-steer-as-you-go/#plan-mode`; | ||
|
|
||
| // Write to cache file and return URI | ||
| const fileUri = await this.writeCacheFile(content); | ||
| return [{ uri: fileUri }]; | ||
| } | ||
|
|
||
| private async writeCacheFile(content: string): Promise<Uri> { | ||
| const cacheDir = Uri.joinPath( | ||
| this.extensionContext.globalStorageUri, | ||
| PlanAgentProvider.CACHE_DIR | ||
| ); | ||
|
|
||
| // Ensure cache directory exists | ||
| try { | ||
| await this.fileSystemService.stat(cacheDir); | ||
| } catch { | ||
| await this.fileSystemService.createDirectory(cacheDir); | ||
| } | ||
|
|
||
| const fileUri = Uri.joinPath(cacheDir, PlanAgentProvider.AGENT_FILENAME); | ||
| await this.fileSystemService.writeFile(fileUri, new TextEncoder().encode(content)); | ||
| this.logService.trace(`[PlanAgentProvider] Wrote agent file: ${fileUri.toString()}`); | ||
| return fileUri; | ||
| } | ||
| } | ||
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
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.