77import * as vscode from 'vscode' ;
88import { ITelemetry } from '../../common/telemetry' ;
99import { CopilotRemoteAgentManager } from '../../github/copilotRemoteAgent' ;
10+ import { FolderRepositoryManager } from '../../github/folderRepositoryManager' ;
1011
1112export interface CopilotRemoteAgentToolParameters {
1213 // The LLM is inconsistent in providing repo information.
@@ -36,6 +37,7 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
3637
3738 const targetRepo = await this . manager . repoInfo ( ) ;
3839 const autoPushEnabled = this . manager . autoCommitAndPushEnabled ( ) ;
40+ const openPR = existingPullRequest || await this . getActivePullRequestWithSession ( targetRepo ) ;
3941
4042 /* __GDPR__
4143 "remoteAgent.tool.prepare" : {}
@@ -46,8 +48,8 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
4648 pastTenseMessage : vscode . l10n . t ( 'Launched coding agent' ) ,
4749 invocationMessage : vscode . l10n . t ( 'Launching coding agent' ) ,
4850 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 )
5153 : ( targetRepo && autoPushEnabled
5254 ? 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 )
5355 : vscode . l10n . t ( 'The coding agent will start working on "**{0}**"' , title ) ) ,
@@ -70,18 +72,6 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
7072 ] ) ;
7173 }
7274
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-
8575 let pullRequestNumber : number | undefined ;
8676 if ( existingPullRequest ) {
8777 pullRequestNumber = parseInt ( existingPullRequest , 10 ) ;
@@ -91,13 +81,20 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
9181 ] ) ;
9282 }
9383 } 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 ) ;
9985 }
10086
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+
10198 if ( pullRequestNumber ) {
10299 await this . manager . addFollowUpToExistingPR ( pullRequestNumber , title , body ) ;
103100 return new vscode . LanguageModelToolResult ( [
@@ -119,4 +116,14 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
119116 new vscode . LanguageModelTextPart ( result . llmDetails )
120117 ] ) ;
121118 }
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+ }
122129}
0 commit comments