Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@
const WAIT_FOR_NEW_SESSION_TO_GET_USED = 5 * 60 * 1000; // 5 minutes

export class CopilotCLIChatSessionParticipant extends Disposable {
private CLI_INCLUDE_CHANGES = vscode.l10n.t('Include Changes');
private CLI_MOVE_CHANGES = vscode.l10n.t('Move Changes');
private CLI_COPY_CHANGES = vscode.l10n.t('Copy Changes');
private CLI_SKIP_CHANGES = vscode.l10n.t('Skip Changes');
private CLI_CANCEL = vscode.l10n.t('Cancel');

Expand Down Expand Up @@ -521,11 +522,10 @@
});

const confirmationResults = this.getAcceptedRejectedConfirmationData(request);
if (!chatSessionContext) {
// Invoked from a 'normal' chat or 'cloud button' without CLI session context
// Or cases such as delegating from Regular chat to CLI chat
// Handle confirmation data
return await this.handlePushConfirmationData(request, context, stream, token);
// Check if it was delegated from chat or cloud button or if it's the first iteration
const response = await this.generateConfirmationResponseIfNeeded(request, context, stream, token);
if (!chatSessionContext || chatSessionContext.isUntitled) {
return response || {};
}

const isUntitled = chatSessionContext.isUntitled;
Expand Down Expand Up @@ -725,7 +725,7 @@
}

// Get model from request.
const preferredModelInRequest = preferModelInRequest && request?.model.id ? await this.copilotCLIModels.resolveModel(request.model.id) : undefined;
const preferredModelInRequest = preferModelInRequest && request?.model?.id ? await this.copilotCLIModels.resolveModel(request.model.id) : undefined;
if (preferredModelInRequest) {
return preferredModelInRequest;
}
Expand Down Expand Up @@ -783,12 +783,12 @@
return {};
}

private async handlePushConfirmationData(
private async generateConfirmationResponseIfNeeded(
request: vscode.ChatRequest,
context: vscode.ChatContext,
stream: vscode.ChatResponseStream,
token: vscode.CancellationToken
): Promise<vscode.ChatResult | void> {
) {
// Check if this is a confirmation response
const confirmationResults = this.getAcceptedRejectedConfirmationData(request);
if (confirmationResults.length > 0) {
Expand All @@ -806,15 +806,25 @@
if (!hasUncommittedChanges) {
// No uncommitted changes, create worktree and proceed
return await this.createCLISessionAndSubmitRequest(request, undefined, request.references, context, undefined, true, stream, token);
} else {
return this.generateUncommittedChangesConfirmation(request, context, stream, token);
}
}

private generateUncommittedChangesConfirmation(
request: vscode.ChatRequest,
context: vscode.ChatContext,
stream: vscode.ChatResponseStream,
token: vscode.CancellationToken
): vscode.ChatResult | void {
const message =
vscode.l10n.t('Background Agent will work in an isolated worktree to implement your requested changes.')
+ '\n\n'
+ vscode.l10n.t('This workspace has uncommitted changes. Should these changes be included in the new worktree?');

const buttons = [
this.CLI_INCLUDE_CHANGES,
this.CLI_COPY_CHANGES,
this.CLI_MOVE_CHANGES,
this.CLI_SKIP_CHANGES,
this.CLI_CANCEL
];
Expand Down Expand Up @@ -856,10 +866,11 @@
return {};
}

const includeChanges = selection.includes(this.CLI_INCLUDE_CHANGES.toUpperCase());
const moveChanges = selection === this.CLI_MOVE_CHANGES.toUpperCase();
const copyChanges = selection === this.CLI_COPY_CHANGES.toUpperCase();
const prompt = uncommittedChangesData.metadata.prompt;

if (includeChanges && this.worktreeManager.isSupported()) {
if ((moveChanges || copyChanges) && this.worktreeManager.isSupported()) {
// Create worktree first
stream.progress(vscode.l10n.t('Creating worktree...'));
const worktreePathValue = await this.worktreeManager.createWorktree(stream);
Expand Down Expand Up @@ -901,7 +912,7 @@
} else {
await this.gitService.migrateChanges(worktreeRepo.rootUri, activeRepository.rootUri, {
confirmation: false,
deleteFromSource: true,
deleteFromSource: moveChanges,
untracked: true
});
stream.markdown(vscode.l10n.t('Changes migrated to worktree.'));
Expand All @@ -915,7 +926,7 @@
return await this.createCLISessionAndSubmitRequest(request, prompt, references, context, worktreePath, true, stream, token);
} else {
// Skip changes, just create worktree without migration
return await this.createCLISessionAndSubmitRequest(request, prompt, references, context, undefined, this.worktreeManager.isSupported(), stream, token);

Check failure on line 929 in src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

View workflow job for this annotation

GitHub Actions / Test (Linux)

src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts > CopilotCLIChatSessionParticipant.handleRequest > handleConfirmationData cancels when uncommitted-changes rejected

TypeError: this.worktreeManager.isSupported is not a function ❯ CopilotCLIChatSessionParticipant.handleWorktreeConfirmationResponse src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:929:125 ❯ CopilotCLIChatSessionParticipant.generateConfirmationResponseIfNeeded src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:795:22 ❯ CopilotCLIChatSessionParticipant.handleRequest src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:526:32 ❯ src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts:371:35

Check failure on line 929 in src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

View workflow job for this annotation

GitHub Actions / Test (Linux)

src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts > CopilotCLIChatSessionParticipant.handleRequest > handleConfirmationData accepts uncommitted-changes and records push

TypeError: this.worktreeManager.isSupported is not a function ❯ CopilotCLIChatSessionParticipant.handleWorktreeConfirmationResponse src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:929:125 ❯ CopilotCLIChatSessionParticipant.generateConfirmationResponseIfNeeded src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:795:22 ❯ CopilotCLIChatSessionParticipant.handleRequest src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:526:32 ❯ src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts:342:35

Check failure on line 929 in src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts > CopilotCLIChatSessionParticipant.handleRequest > handleConfirmationData cancels when uncommitted-changes rejected

TypeError: this.worktreeManager.isSupported is not a function ❯ CopilotCLIChatSessionParticipant.handleWorktreeConfirmationResponse src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:929:125 ❯ CopilotCLIChatSessionParticipant.generateConfirmationResponseIfNeeded src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:795:22 ❯ CopilotCLIChatSessionParticipant.handleRequest src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:526:32 ❯ src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts:371:35

Check failure on line 929 in src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts > CopilotCLIChatSessionParticipant.handleRequest > handleConfirmationData accepts uncommitted-changes and records push

TypeError: this.worktreeManager.isSupported is not a function ❯ CopilotCLIChatSessionParticipant.handleWorktreeConfirmationResponse src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:929:125 ❯ CopilotCLIChatSessionParticipant.generateConfirmationResponseIfNeeded src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:795:22 ❯ CopilotCLIChatSessionParticipant.handleRequest src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts:526:32 ❯ src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts:342:35
}
}

Expand Down
Loading