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 @@ -35,12 +35,7 @@ export class CopilotCLIWorktreeManager {
constructor(
@IVSCodeExtensionContext private readonly extensionContext: IVSCodeExtensionContext) { }

async createWorktreeIfNeeded(sessionId: string, stream: vscode.ChatResponseStream): Promise<string | undefined> {
const isolationEnabled = this._sessionIsolation.get(sessionId) ?? false;
if (!isolationEnabled) {
return undefined;
}

async createWorktree(stream: vscode.ChatResponseStream): Promise<string | undefined> {
Copy link
Collaborator Author

@DonJayamanne DonJayamanne Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osortega
I think getting the caller to decide whether to call this method or not is an improvement, as opposed to giving more responsibility to this method.
Callers already have all of the information using the public methods in this class.

I believe that will also improve readability as sometimes we pass in untitled id and other cases we pass in the real session id (what confuses me is the fact that here we MUST pass in the old untitled id & not the real session id).

I'd like to remove that ambiguity from this class/code.

This comment was marked as resolved.

try {
const worktreePath = await vscode.commands.executeCommand('git.createWorktreeWithDefaults') as string | undefined;
if (worktreePath) {
Expand Down Expand Up @@ -323,20 +318,19 @@ export class CopilotCLIChatSessionParticipant {
// For existing sessions we cannot fall back, as the model info would be updated in _sessionModel
const modelId = this.copilotCLIModels.toModelProvider(preferredModel?.id || defaultModel.id);
const { prompt, attachments } = await this.promptResolver.resolvePrompt(request, token);
const isolationEnabled = this.worktreeManager.getIsolationPreference(id);

if (chatSessionContext.isUntitled) {
const untitledCopilotcliSessionId = SessionIdForCLI.parse(chatSessionContext.chatSessionItem.resource);
const workingDirectory = isolationEnabled ? await this.worktreeManager.createWorktree(stream) : undefined;
const session = await this.sessionService.createSession(prompt, modelId, token);
const workingDirectory = await this.worktreeManager.createWorktreeIfNeeded(untitledCopilotcliSessionId, stream);
if (workingDirectory) {
await this.worktreeManager.storeWorktreePath(session.sessionId, workingDirectory);
}

await session.handleRequest(prompt, attachments, request.toolInvocationToken, stream, modelId, workingDirectory, token);

this.sessionItemProvider.swap(chatSessionContext.chatSessionItem, { resource: SessionIdForCLI.getResource(session.sessionId), label: request.prompt ?? 'CopilotCLI' });

if (workingDirectory) {
await this.worktreeManager.storeWorktreePath(session.sessionId, workingDirectory);
}

return {};
}

Expand Down