Skip to content

Commit 383829a

Browse files
authored
implement remoteCodingAgents proposal to integrate in chat (microsoft/vscode-copilot#18918) (#7078)
1 parent 3b4e6f5 commit 383829a

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"contribShareMenu",
3030
"diffCommand",
3131
"quickDiffProvider",
32+
"remoteCodingAgents",
3233
"shareProvider",
3334
"tokenInformation",
3435
"treeViewMarkdownMessage"
@@ -64,6 +65,14 @@
6465
"virtualWorkspaces": true
6566
},
6667
"contributes": {
68+
"remoteCodingAgents": [
69+
{
70+
"command": "githubpr.remoteAgent",
71+
"displayName": "GitHub Coding Agent",
72+
"description": "The GitHub Coding Agent.",
73+
"when": "config.githubPullRequests.codingAgent.enabled"
74+
}
75+
],
6776
"chatParticipants": [
6877
{
6978
"id": "githubpr",
@@ -814,6 +823,11 @@
814823
]
815824
},
816825
"commands": [
826+
{
827+
"command": "githubpr.remoteAgent",
828+
"title": "Remote agent integration",
829+
"enablement": "config.githubPullRequests.codingAgent.enabled"
830+
},
817831
{
818832
"command": "github.api.preloadPullRequest",
819833
"title": "Preload Pull Request",
@@ -1790,6 +1804,10 @@
17901804
"command": "github.api.preloadPullRequest",
17911805
"when": "false"
17921806
},
1807+
{
1808+
"command": "githubpr.remoteAgent",
1809+
"when": "false"
1810+
},
17931811
{
17941812
"command": "pr.configureRemotes",
17951813
"when": "gitHubOpenRepositoryCount != 0"

src/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,9 @@ ${contents}
14651465
context.subscriptions.push(
14661466
vscode.commands.registerCommand('pr.continueAsyncWithCopilot', async () => copilotRemoteAgentManager.commandImpl())
14671467
);
1468+
context.subscriptions.push(
1469+
vscode.commands.registerCommand('githubpr.remoteAgent', async (args) => copilotRemoteAgentManager.commandImpl(args))
1470+
);
14681471
context.subscriptions.push(
14691472
vscode.commands.registerCommand('pr.applySuggestionWithCopilot', async (comment: GHPRComment) => {
14701473
/* __GDPR__

src/github/copilotRemoteAgent.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,37 @@ export class CopilotRemoteAgentManager extends Disposable {
108108
return continueWithCopilot;
109109
}
110110

111-
async commandImpl() {
111+
async commandImpl(args?: any) {
112+
// https://github.com/microsoft/vscode-copilot/issues/18918
113+
if (args?.userPrompt) {
114+
const userPrompt: string = args.userPrompt;
115+
const summary: string | undefined = args.summary;
116+
117+
if (!userPrompt || userPrompt.trim().length === 0) {
118+
vscode.window.showErrorMessage(vscode.l10n.t('User prompt cannot be empty'));
119+
return;
120+
}
121+
122+
const result = await this.invokeRemoteAgent(userPrompt, summary || 'No summary provided...oops.');
123+
if (result.state !== 'success') {
124+
vscode.window.showErrorMessage(result.error);
125+
return;
126+
}
127+
128+
const { webviewUri, link } = result;
129+
const openLink = vscode.l10n.t('View');
130+
vscode.window.showInformationMessage(
131+
// allow-any-unicode-next-line
132+
vscode.l10n.t('🚀 Coding agent started! Track progress at {0}', link)
133+
, openLink
134+
).then(selection => {
135+
if (selection === openLink) {
136+
vscode.env.openExternal(webviewUri);
137+
}
138+
});
139+
return;
140+
}
141+
112142
const body = await vscode.window.showInputBox({
113143
prompt: vscode.l10n.t('Describe a task for the coding agent'),
114144
title: vscode.l10n.t('Finish With Coding Agent'),
@@ -168,7 +198,7 @@ export class CopilotRemoteAgentManager extends Disposable {
168198
);
169199
}
170200

171-
async invokeRemoteAgent(title: string, body: string, autoPushAndCommit = true): Promise<RemoteAgentResult> {
201+
async invokeRemoteAgent(prompt: string, problemContext: string, autoPushAndCommit = true): Promise<RemoteAgentResult> {
172202
// TODO: Check that the user has a valid copilot subscription
173203
const capiClient = await this.copilotApi;
174204
if (!capiClient) {
@@ -197,6 +227,7 @@ export class CopilotRemoteAgentManager extends Disposable {
197227
await repository.add([]);
198228
if (repository.state.indexChanges.length > 0) {
199229
// TODO: there is an issue here if the user has GPG signing enabled.
230+
// https://github.com/microsoft/vscode/pull/252263
200231
await repository.commit('Checkpoint for Copilot Agent async session', { signCommit: false });
201232
}
202233
await repository.push(remote, asyncBranch, true);
@@ -221,11 +252,18 @@ export class CopilotRemoteAgentManager extends Disposable {
221252
}
222253
}
223254

255+
let title = prompt;
256+
const titleMatch = problemContext.match(/TITLE: \s*(.*)/i);
257+
if (titleMatch && titleMatch[1]) {
258+
title = titleMatch[1].trim();
259+
}
260+
261+
const problemStatement: string = `${prompt} ${problemContext ? `: ${problemContext}` : ''}`;
224262
const payload: RemoteAgentJobPayload = {
225-
problem_statement: title,
263+
problem_statement: problemStatement,
226264
pull_request: {
227-
title: title,
228-
body_placeholder: body,
265+
title,
266+
body_placeholder: problemContext,
229267
base_ref: ref,
230268
}
231269
};

0 commit comments

Comments
 (0)