Skip to content

Commit 5178ca1

Browse files
authored
Ability to add an open (but not checked out) PR as context to chat (#7596)
* Ability to add an open (but not checked out) PR as context to chat Fixes #7332 * active/open in the confirmation title
1 parent e378dcd commit 5178ca1

5 files changed

Lines changed: 59 additions & 11 deletions

File tree

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4027,11 +4027,25 @@
40274027
],
40284028
"toolReferenceName": "activePullRequest",
40294029
"displayName": "%languageModelTools.github-pull-request_activePullRequest.displayName%",
4030-
"modelDescription": "Get comprehensive information about the active or current GitHub pull request (PR). This includes the PR title, full description, list of changed files, review comments, PR state, and status checks/CI results. For PRs created by Copilot, it also includes the session logs which indicate the development process and decisions made by the coding agent. When asked about the active or current pull request, do this first! Use this tool for any request related to \"current changes,\" \"pull request details,\" \"what changed,\" \"PR status,\" or similar queries even if the user does not explicitly mention \"pull request.\"",
4030+
"modelDescription": "Get comprehensive information about the active GitHub pull request (PR). The active PR is the one that is currently checked out. This includes the PR title, full description, list of changed files, review comments, PR state, and status checks/CI results. For PRs created by Copilot, it also includes the session logs which indicate the development process and decisions made by the coding agent. When asked about the active or current pull request, do this first! Use this tool for any request related to \"current changes,\" \"pull request details,\" \"what changed,\" \"PR status,\" or similar queries even if the user does not explicitly mention \"pull request.\" When asked to use this tool, ALWAYS use it.",
40314031
"icon": "$(git-pull-request)",
40324032
"canBeReferencedInPrompt": true,
40334033
"userDescription": "%languageModelTools.github-pull-request_activePullRequest.description%",
40344034
"when": "config.githubPullRequests.experimental.chat"
4035+
},
4036+
{
4037+
"name": "github-pull-request_openPullRequest",
4038+
"tags": [
4039+
"github",
4040+
"pull request"
4041+
],
4042+
"toolReferenceName": "openPullRequest",
4043+
"displayName": "%languageModelTools.github-pull-request_openPullRequest.displayName%",
4044+
"modelDescription": "Get comprehensive information about the GitHub pull request (PR) which is currently visible, but not necessarily checked out. This includes the PR title, full description, list of changed files, review comments, PR state, and status checks/CI results. For PRs created by Copilot, it also includes the session logs which indicate the development process and decisions made by the coding agent. When asked about the currently open pull request, do this first! Use this tool for any request related to \"pull request details,\" \"what changed,\" \"PR status,\" or similar queries even if the user does not explicitly mention \"pull request.\" When asked to use this tool, ALWAYS use it.",
4045+
"icon": "$(git-pull-request)",
4046+
"canBeReferencedInPrompt": true,
4047+
"userDescription": "%languageModelTools.github-pull-request_openPullRequest.description%",
4048+
"when": "config.githubPullRequests.experimental.chat"
40354049
}
40364050
]
40374051
},

package.nls.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@
385385
"languageModelTools.github-pull-request_renderIssues.displayName": "Render issue items in a markdown table",
386386
"languageModelTools.github-pull-request_activePullRequest.displayName": "Active Pull Request",
387387
"languageModelTools.github-pull-request_activePullRequest.description": "Get information about the active GitHub pull request. This information includes: comments, files changed, pull request title + description, pull request state, and pull request status checks/CI.",
388+
"languageModelTools.github-pull-request_openPullRequest.displayName": "Open Pull Request",
389+
"languageModelTools.github-pull-request_openPullRequest.description": "Get information about the open GitHub pull request. This information includes: comments, files changed, pull request title + description, pull request state, and pull request status checks/CI.",
388390
"languageModelTools.github-pull-request_copilot-coding-agent.displayName": "Copilot coding agent",
389391
"languageModelTools.github-pull-request_copilot-coding-agent.userDescription": "Completes the provided task using an asynchronous coding agent. Use when the user wants copilot continue completing a task in the background or asynchronously. Launch an autonomous GitHub Copilot agent to work on coding tasks in the background. The agent will create a new branch, implement the requested changes, and open a pull request with the completed work."
390392
}

src/lm/tools/activePullRequestTool.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,29 @@ import { GitChangeType, InMemFileChange } from '../../common/file';
1010
import Logger from '../../common/logger';
1111
import { CopilotRemoteAgentManager } from '../../github/copilotRemoteAgent';
1212
import { PullRequestModel } from '../../github/pullRequestModel';
13-
import { PullRequestOverviewPanel } from '../../github/pullRequestOverview';
1413
import { RepositoriesManager } from '../../github/repositoriesManager';
1514
import { FetchIssueResult } from './fetchIssueTool';
1615

17-
export class ActivePullRequestTool implements vscode.LanguageModelTool<FetchIssueResult> {
18-
public static readonly toolId = 'github-pull-request_activePullRequest';
16+
export abstract class PullRequestTool implements vscode.LanguageModelTool<FetchIssueResult> {
1917
constructor(
20-
private readonly folderManagers: RepositoriesManager,
18+
protected readonly folderManagers: RepositoriesManager,
2119
private readonly copilotRemoteAgentManager: CopilotRemoteAgentManager
2220
) { }
2321

24-
private _findActivePullRequest(): PullRequestModel | undefined {
25-
const folderManager = this.folderManagers.folderManagers.find((manager) => manager.activePullRequest);
26-
return folderManager?.activePullRequest ?? PullRequestOverviewPanel.currentPanel?.getCurrentItem();
27-
}
22+
protected abstract _findActivePullRequest(): PullRequestModel | undefined;
23+
24+
protected abstract _confirmationTitle(): string;
2825

2926
private shouldIncludeCodingAgentSession(pullRequest?: PullRequestModel): boolean {
3027
return !!pullRequest && this.copilotRemoteAgentManager.enabled && COPILOT_LOGINS.includes(pullRequest.author.login);
3128
}
3229

33-
3430
async prepareInvocation(): Promise<vscode.PreparedToolInvocation> {
3531
const pullRequest = this._findActivePullRequest();
3632
return {
3733
pastTenseMessage: pullRequest ? vscode.l10n.t('Read pull request "{0}"', pullRequest.title) : vscode.l10n.t('No active pull request'),
3834
invocationMessage: pullRequest ? vscode.l10n.t('Reading pull request "{0}"', pullRequest.title) : vscode.l10n.t('Reading active pull request'),
39-
confirmationMessages: { title: vscode.l10n.t('Active Pull Request'), message: pullRequest ? vscode.l10n.t('Allow reading the details of "{0}"?', pullRequest.title) : vscode.l10n.t('Allow reading the details of the active pull request?') },
35+
confirmationMessages: { title: this._confirmationTitle(), message: pullRequest ? vscode.l10n.t('Allow reading the details of "{0}"?', pullRequest.title) : vscode.l10n.t('Allow reading the details of the active pull request?') },
4036
};
4137
}
4238

@@ -166,4 +162,17 @@ export class ActivePullRequestTool implements vscode.LanguageModelTool<FetchIssu
166162
return result;
167163
}
168164

165+
}
166+
167+
export class ActivePullRequestTool extends PullRequestTool {
168+
public static readonly toolId = 'github-pull-request_activePullRequest';
169+
170+
protected _findActivePullRequest(): PullRequestModel | undefined {
171+
const folderManager = this.folderManagers.folderManagers.find((manager) => manager.activePullRequest);
172+
return folderManager?.activePullRequest;
173+
}
174+
175+
protected _confirmationTitle(): string {
176+
return vscode.l10n.t('Active Pull Request');
177+
}
169178
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { PullRequestModel } from '../../github/pullRequestModel';
8+
import { PullRequestOverviewPanel } from '../../github/pullRequestOverview';
9+
import { PullRequestTool } from './activePullRequestTool';
10+
11+
export class OpenPullRequestTool extends PullRequestTool {
12+
public static readonly toolId = 'github-pull-request_openPullRequest';
13+
14+
protected _findActivePullRequest(): PullRequestModel | undefined {
15+
return PullRequestOverviewPanel.currentPanel?.getCurrentItem();
16+
}
17+
18+
protected _confirmationTitle(): string {
19+
return vscode.l10n.t('Open Pull Request');
20+
}
21+
}

src/lm/tools/tools.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { CopilotRemoteAgentTool } from './copilotRemoteAgentTool';
1515
import { DisplayIssuesTool } from './displayIssuesTool';
1616
import { FetchIssueTool } from './fetchIssueTool';
1717
import { FetchNotificationTool } from './fetchNotificationTool';
18+
import { OpenPullRequestTool } from './openPullRequestTool';
1819
import { ConvertToSearchSyntaxTool, SearchTool } from './searchTools';
1920
import { SuggestFixTool } from './suggestFixTool';
2021
import { IssueSummarizationTool } from './summarizeIssueTool';
@@ -27,6 +28,7 @@ export function registerTools(context: vscode.ExtensionContext, credentialStore:
2728
registerSearchTools(context, credentialStore, repositoriesManager, chatParticipantState);
2829
registerCopilotAgentTools(context, copilotRemoteAgentManager, telemetry);
2930
context.subscriptions.push(vscode.lm.registerTool(ActivePullRequestTool.toolId, new ActivePullRequestTool(repositoriesManager, copilotRemoteAgentManager)));
31+
context.subscriptions.push(vscode.lm.registerTool(OpenPullRequestTool.toolId, new OpenPullRequestTool(repositoriesManager, copilotRemoteAgentManager)));
3032
}
3133

3234
function registerFetchingTools(context: vscode.ExtensionContext, credentialStore: CredentialStore, repositoriesManager: RepositoriesManager, chatParticipantState: ChatParticipantState) {

0 commit comments

Comments
 (0)