7
7
import * as vscode from 'vscode' ;
8
8
import { ITelemetry } from '../../common/telemetry' ;
9
9
import { CopilotRemoteAgentManager } from '../../github/copilotRemoteAgent' ;
10
+ import { FolderRepositoryManager } from '../../github/folderRepositoryManager' ;
10
11
11
12
export interface CopilotRemoteAgentToolParameters {
12
13
// The LLM is inconsistent in providing repo information.
@@ -36,6 +37,7 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
36
37
37
38
const targetRepo = await this . manager . repoInfo ( ) ;
38
39
const autoPushEnabled = this . manager . autoCommitAndPushEnabled ( ) ;
40
+ const openPR = existingPullRequest || await this . getActivePullRequestWithSession ( targetRepo ) ;
39
41
40
42
/* __GDPR__
41
43
"remoteAgent.tool.prepare" : {}
@@ -46,8 +48,8 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
46
48
pastTenseMessage : vscode . l10n . t ( 'Launched coding agent' ) ,
47
49
invocationMessage : vscode . l10n . t ( 'Launching coding agent' ) ,
48
50
confirmationMessages : {
49
- message : existingPullRequest
50
- ? vscode . l10n . t ( 'The coding agent will incorporate your feedback on existing pull request **#{0}**.' , existingPullRequest )
51
+ message : openPR
52
+ ? vscode . l10n . t ( 'The coding agent will incorporate your feedback on existing pull request **#{0}**.' , openPR )
51
53
: ( targetRepo && autoPushEnabled
52
54
? vscode . l10n . t ( 'The coding agent will continue work on "**{0}**" in a new branch on "**{1}/{2}**". Any uncommitted changes will be **automatically pushed**.' , title , targetRepo . owner , targetRepo . repo )
53
55
: vscode . l10n . t ( 'The coding agent will start working on "**{0}**"' , title ) ) ,
@@ -70,18 +72,6 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
70
72
] ) ;
71
73
}
72
74
73
-
74
- /* __GDPR__
75
- "remoteAgent.tool.invoke" : {
76
- "hasExistingPR" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
77
- "hasBody" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
78
- },
79
- */
80
- this . telemetry . sendTelemetryEvent ( 'copilot.remoteAgent.tool.invoke' , {
81
- hasExistingPR : existingPullRequest ? 'true' : 'false' ,
82
- hasBody : body ? 'true' : 'false'
83
- } ) ;
84
-
85
75
let pullRequestNumber : number | undefined ;
86
76
if ( existingPullRequest ) {
87
77
pullRequestNumber = parseInt ( existingPullRequest , 10 ) ;
@@ -91,13 +81,20 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
91
81
] ) ;
92
82
}
93
83
} else {
94
- const { repo, owner } = targetRepo ;
95
- const activePR = targetRepo . fm . activePullRequest ;
96
- if ( activePR && this . manager . getStateForPR ( owner , repo , activePR . number ) ) {
97
- pullRequestNumber = activePR . number ;
98
- }
84
+ pullRequestNumber = await this . getActivePullRequestWithSession ( targetRepo ) ;
99
85
}
100
86
87
+ /* __GDPR__
88
+ "remoteAgent.tool.invoke" : {
89
+ "hasExistingPR" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
90
+ "hasBody" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
91
+ },
92
+ */
93
+ this . telemetry . sendTelemetryEvent ( 'copilot.remoteAgent.tool.invoke' , {
94
+ hasExistingPR : pullRequestNumber ? 'true' : 'false' ,
95
+ hasBody : body ? 'true' : 'false'
96
+ } ) ;
97
+
101
98
if ( pullRequestNumber ) {
102
99
await this . manager . addFollowUpToExistingPR ( pullRequestNumber , title , body ) ;
103
100
return new vscode . LanguageModelToolResult ( [
@@ -119,4 +116,14 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
119
116
new vscode . LanguageModelTextPart ( result . llmDetails )
120
117
] ) ;
121
118
}
119
+
120
+ private async getActivePullRequestWithSession ( repoInfo : { repo : string ; owner : string ; fm : FolderRepositoryManager } | undefined ) : Promise < number | undefined > {
121
+ if ( ! repoInfo ) {
122
+ return ;
123
+ }
124
+ const activePR = repoInfo . fm . activePullRequest ;
125
+ if ( activePR && this . manager . getStateForPR ( repoInfo . owner , repoInfo . repo , activePR . number ) ) {
126
+ return activePR . number ;
127
+ }
128
+ }
122
129
}
0 commit comments