Skip to content

Commit d4ffa89

Browse files
committed
Track copilot cli edits to files when auto approved
1 parent 6484cd7 commit d4ffa89

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/extension/agents/copilotcli/node/copilotcliSession.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,18 @@ export class CopilotCLISession extends DisposableStore implements ICopilotCLISes
258258
// TODO:@rebornix @lszomoru
259259
// If user is writing a file in the working directory configured for the session, AND the working directory is not a workspace folder,
260260
// auto-approve the write request. Currently we only set non-workspace working directories when using git worktrees.
261-
const data = Uri.file(permissionRequest.fileName);
261+
const editFile = Uri.file(permissionRequest.fileName);
262262

263-
if (!this.workspaceService.getWorkspaceFolder(Uri.file(workingDirectory)) && extUriBiasedIgnorePathCase.isEqualOrParent(data, Uri.file(workingDirectory))) {
263+
if (!this.workspaceService.getWorkspaceFolder(Uri.file(workingDirectory)) && extUriBiasedIgnorePathCase.isEqualOrParent(editFile, Uri.file(workingDirectory))) {
264264
this.logService.trace(`[CopilotCLISession] Auto Approving request to write file in working directory ${permissionRequest.fileName}`);
265+
const editKey = getEditKeyForFile(editFile);
266+
267+
// If we're editing a file, start tracking the edit & wait for core to acknowledge it.
268+
if (editKey && this._stream) {
269+
this.logService.trace(`[CopilotCLISession] Starting to track edit for toolCallId ${editKey} & file ${editFile.fsPath}`);
270+
await editTracker.trackEdit(editKey, [editFile], this._stream);
271+
}
272+
265273
return { kind: 'approved' };
266274
}
267275
}
@@ -273,10 +281,12 @@ export class CopilotCLISession extends DisposableStore implements ICopilotCLISes
273281
return { kind: 'denied-interactively-by-user' };
274282
}
275283

284+
// Check if we're editinga file.
285+
const editFile = permissionRequest.kind === 'write' ? Uri.file(permissionRequest.fileName) : undefined;
286+
const editKey = editFile ? getEditKeyForFile(editFile) : undefined;
287+
276288
if (await permissionHandler(permissionRequest, token)) {
277289
// If we're editing a file, start tracking the edit & wait for core to acknowledge it.
278-
const editFile = permissionRequest.kind === 'write' ? Uri.file(permissionRequest.fileName) : undefined;
279-
const editKey = editFile ? getEditKeyForFile(editFile) : undefined;
280290
if (editFile && editKey && this._stream) {
281291
this.logService.trace(`[CopilotCLISession] Starting to track edit for toolCallId ${editKey} & file ${editFile.fsPath}`);
282292
await editTracker.trackEdit(editKey, [editFile], this._stream);

0 commit comments

Comments
 (0)