Path: blob/main/extensions/copilot/src/extension/chatSessions/common/chatSessionWorktreeService.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type * as vscode from 'vscode';6import { RepoContext } from '../../../platform/git/common/gitService';7import { createServiceIdentifier } from '../../../util/common/services';89export interface ChatSessionWorktreeFile {10readonly filePath: string;11readonly originalFilePath: string | undefined;12readonly modifiedFilePath: string | undefined;13readonly statistics: {14readonly additions: number;15readonly deletions: number;16};17}1819export interface ChatSessionWorktreeData {20readonly data: string;21readonly version: number;22}2324interface ChatSessionWorktreeBaseProperties {25readonly baseCommit: string;26readonly branchName: string;27readonly repositoryPath: string;28readonly worktreePath: string;29readonly changes?: readonly ChatSessionWorktreeFile[] | undefined;30}3132export interface ChatSessionWorktreePropertiesV1 extends ChatSessionWorktreeBaseProperties {33readonly version: 1;34readonly autoCommit: boolean;35}3637export interface ChatSessionWorktreePropertiesV2 extends ChatSessionWorktreeBaseProperties {38readonly version: 2;39readonly autoCommit?: boolean;40readonly baseBranchName: string;41readonly baseBranchProtected?: boolean;42readonly upstreamBranchName?: string;43readonly mergeBaseCommit?: string;44readonly pullRequestUrl?: string;45readonly pullRequestState?: string;46readonly firstCheckpointRef?: string;47readonly baseCheckpointRef?: string;48readonly lastCheckpointRef?: string;49readonly hasGitHubRemote?: boolean;50readonly incomingChanges?: number;51readonly outgoingChanges?: number;52readonly uncommittedChanges?: number;53}5455export type ChatSessionWorktreeProperties = ChatSessionWorktreePropertiesV1 | ChatSessionWorktreePropertiesV2;5657export const IChatSessionWorktreeService = createServiceIdentifier<IChatSessionWorktreeService>('IChatSessionWorktreeService');5859export interface IChatSessionWorktreeService {60readonly _serviceBrand: undefined;61/**62* Triggered when cached worktree changes for a session are invalidated and should be refreshed.63*64* This event does not guarantee that the underlying set of changes was updated directly; callers65* should re-query {@link getWorktreeChanges} when it fires.66*/67onDidChangeWorktreeChanges: vscode.Event<{ sessionId: string }>;6869createWorktree(repositoryPath: vscode.Uri, stream?: vscode.ChatResponseStream, baseBranch?: string, branchName?: string): Promise<ChatSessionWorktreeProperties | undefined>;7071getWorktreeProperties(sessionId: string): Promise<ChatSessionWorktreeProperties | undefined>;72setWorktreeProperties(sessionId: string, properties: string | ChatSessionWorktreeProperties): Promise<void>;7374getWorktreeRepository(sessionId: string): Promise<RepoContext | undefined>;75getWorktreePath(sessionId: string): Promise<vscode.Uri | undefined>;7677applyWorktreeChanges(sessionId: string): Promise<void>;7879getWorktreeChanges(sessionId: string): Promise<readonly vscode.ChatSessionChangedFile[] | undefined>;8081hasCachedChanges(sessionId: string): Promise<boolean>;8283handleRequestCompleted(sessionId: string): Promise<void>;8485/** Get worktree properties for all additional workspaces in a session. */86getAdditionalWorktreeProperties(sessionId: string): Promise<ChatSessionWorktreeProperties[]>;8788/** Store worktree properties for additional workspaces in a session. */89setAdditionalWorktreeProperties(sessionId: string, properties: ChatSessionWorktreeProperties[]): Promise<void>;9091/** Commit changes in a specific worktree, identified by its properties directly. */92handleRequestCompletedForWorktree(worktreeProperties: ChatSessionWorktreeProperties): Promise<void>;9394/**95* Attempts to clean up a worktree when a session is archived.96* If auto-commit is enabled and there are uncommitted changes, commits them first.97* Returns whether the worktree was successfully deleted.98*/99cleanupWorktreeOnArchive(sessionId: string): Promise<{ cleaned: boolean; reason?: string }>;100101/**102* Recreates a worktree from the session branch when a session is unarchived.103* The branch must still exist (it is preserved during archive cleanup).104* Returns whether the worktree was successfully recreated.105*/106recreateWorktreeOnUnarchive(sessionId: string): Promise<{ recreated: boolean; reason?: string }>;107}108109110