Skip to content

Commit 53ae22d

Browse files
authored
add follow up to tool call (#7171)
1 parent 0cd9002 commit 53ae22d

File tree

3 files changed

+55
-26
lines changed

3 files changed

+55
-26
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,6 +3380,10 @@
33803380
"body": {
33813381
"type": "string",
33823382
"description": "The body/description of the issue. Populate from chat context."
3383+
},
3384+
"existingPullRequest": {
3385+
"type": "number",
3386+
"description": "The number of an existing pull request that is connected to the current Coding Agent task. Look in the history for this number. In the chat it may look like 'Coding agent will continue work in #17...'. In this example, return just '17'."
33833387
}
33843388
}
33853389
}

src/github/copilotRemoteAgent.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,34 @@ export class CopilotRemoteAgentManager extends Disposable {
232232
}
233233
}
234234

235+
async addFollowUpToExistingPR(pullRequestNumber: number, userPrompt: string, summary?: string): Promise<string | undefined> {
236+
const repoInfo = await this.repoInfo();
237+
if (!repoInfo) {
238+
return;
239+
}
240+
try {
241+
const ghRepo = repoInfo.ghRepository;
242+
const pr = await ghRepo.getPullRequest(pullRequestNumber);
243+
if (!pr) {
244+
Logger.error(`Could not find pull request #${pullRequestNumber}`, CopilotRemoteAgentManager.ID);
245+
return;
246+
}
247+
// Add a comment tagging @copilot with the user's prompt
248+
const commentBody = `${COPILOT} ${userPrompt} \n\n --- \n\n ${summary ?? ''}`;
249+
const commentResult = await pr.createIssueComment(commentBody);
250+
if (!commentResult) {
251+
Logger.error(`Failed to add comment to PR #${pullRequestNumber}`, CopilotRemoteAgentManager.ID);
252+
return;
253+
}
254+
Logger.appendLine(`Added comment ${commentResult.htmlUrl}`, CopilotRemoteAgentManager.ID);
255+
// allow-any-unicode-next-line
256+
return vscode.l10n.t('🚀 Follow-up comment added to [#{0}]({1})', pullRequestNumber, commentResult.htmlUrl);
257+
} catch (err) {
258+
Logger.error(`Failed to add follow-up comment to PR #${pullRequestNumber}: ${err}`, CopilotRemoteAgentManager.ID);
259+
return;
260+
}
261+
}
262+
235263
async commandImpl(args?: ICopilotRemoteAgentCommandArgs): Promise<string | undefined> {
236264
if (!args) {
237265
return;
@@ -253,28 +281,7 @@ export class CopilotRemoteAgentManager extends Disposable {
253281
// {"owner":"monalisa","repo":"app","pullRequestNumber":18}
254282
let followUpPR: number | undefined = this.parseFollowup(followup, repoInfo);
255283
if (followUpPR) {
256-
try {
257-
const ghRepo = repoInfo.ghRepository;
258-
// Fetch the PullRequestModel by number
259-
const pr = await ghRepo.getPullRequest(followUpPR);
260-
if (!pr) {
261-
Logger.error(`Could not find pull request #${followUpPR}`, CopilotRemoteAgentManager.ID);
262-
return;
263-
}
264-
// Add a comment tagging @copilot with the user's prompt
265-
const commentBody = `${COPILOT} ${userPrompt} \n\n --- \n\n ${summary ?? ''}`;
266-
const commentResult = await pr.createIssueComment(commentBody);
267-
if (!commentResult) {
268-
Logger.error(`Failed to add comment to PR #${followUpPR}`, CopilotRemoteAgentManager.ID);
269-
return;
270-
}
271-
Logger.appendLine(`Added comment ${commentResult.htmlUrl}`, CopilotRemoteAgentManager.ID);
272-
// allow-any-unicode-next-line
273-
return vscode.l10n.t('🚀 Follow-up comment added to [#{0}]({1})', followUpPR, commentResult.htmlUrl);
274-
} catch (err) {
275-
Logger.error(`Failed to add follow-up comment to PR #${followUpPR}: ${err}`, CopilotRemoteAgentManager.ID);
276-
return;
277-
}
284+
return this.addFollowUpToExistingPR(followUpPR, userPrompt, summary);
278285
}
279286

280287
const repoName = `${owner}/${repo}`;

src/lm/tools/copilotRemoteAgentTool.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface CopilotRemoteAgentToolParameters {
1616
// };
1717
title: string;
1818
body?: string;
19+
existingPullRequest?: string;
1920
}
2021

2122
export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotRemoteAgentToolParameters> {
@@ -24,7 +25,7 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
2425
constructor(private manager: CopilotRemoteAgentManager) { }
2526

2627
async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<CopilotRemoteAgentToolParameters>): Promise<vscode.PreparedToolInvocation> {
27-
const { title } = options.input;
28+
const { title, existingPullRequest } = options.input;
2829

2930
// Check if the coding agent is available (enabled and assignable)
3031
const isAvailable = await this.manager.isAvailable();
@@ -38,9 +39,11 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
3839
pastTenseMessage: vscode.l10n.t('Launched coding agent'),
3940
invocationMessage: vscode.l10n.t('Launching coding agent'),
4041
confirmationMessages: {
41-
message: targetRepo && autoPushEnabled
42-
? 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)
43-
: vscode.l10n.t('The coding agent will start working on "**{0}**"', title),
42+
message: existingPullRequest
43+
? vscode.l10n.t('The coding agent will incorporate your feedback on existing pull request **#{0}**.', existingPullRequest)
44+
: (targetRepo && autoPushEnabled
45+
? 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)
46+
: vscode.l10n.t('The coding agent will start working on "**{0}**"', title)),
4447
title: vscode.l10n.t('Start coding agent?'),
4548
}
4649
};
@@ -52,12 +55,27 @@ export class CopilotRemoteAgentTool implements vscode.LanguageModelTool<CopilotR
5255
): Promise<vscode.LanguageModelToolResult | undefined> {
5356
const title = options.input.title;
5457
const body = options.input.body || '';
58+
const existingPullRequest = options.input.existingPullRequest || '';
5559
const targetRepo = await this.manager.repoInfo();
5660
if (!targetRepo) {
5761
return new vscode.LanguageModelToolResult([
5862
new vscode.LanguageModelTextPart(vscode.l10n.t('No repository information found. Please open a workspace with a Git repository.'))
5963
]);
6064
}
65+
66+
if (existingPullRequest) {
67+
const pullRequestNumber = parseInt(existingPullRequest, 10);
68+
if (isNaN(pullRequestNumber)) {
69+
return new vscode.LanguageModelToolResult([
70+
new vscode.LanguageModelTextPart(vscode.l10n.t('Invalid pull request number: {0}', existingPullRequest))
71+
]);
72+
}
73+
const result = await this.manager.addFollowUpToExistingPR(pullRequestNumber, title, body);
74+
return new vscode.LanguageModelToolResult([
75+
new vscode.LanguageModelTextPart(vscode.l10n.t('Follow-up added to pull request #{0}.', pullRequestNumber)),
76+
]);
77+
}
78+
6179
const result = await this.manager.invokeRemoteAgent(title, body);
6280
if (result.state === 'error') {
6381
throw new Error(result.error);

0 commit comments

Comments
 (0)