Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chatSessions/common/chatSessionWorktreeService.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type * as vscode from 'vscode';
7
import { RepoContext } from '../../../platform/git/common/gitService';
8
import { createServiceIdentifier } from '../../../util/common/services';
9
10
export interface ChatSessionWorktreeFile {
11
readonly filePath: string;
12
readonly originalFilePath: string | undefined;
13
readonly modifiedFilePath: string | undefined;
14
readonly statistics: {
15
readonly additions: number;
16
readonly deletions: number;
17
};
18
}
19
20
export interface ChatSessionWorktreeData {
21
readonly data: string;
22
readonly version: number;
23
}
24
25
interface ChatSessionWorktreeBaseProperties {
26
readonly baseCommit: string;
27
readonly branchName: string;
28
readonly repositoryPath: string;
29
readonly worktreePath: string;
30
readonly changes?: readonly ChatSessionWorktreeFile[] | undefined;
31
}
32
33
export interface ChatSessionWorktreePropertiesV1 extends ChatSessionWorktreeBaseProperties {
34
readonly version: 1;
35
readonly autoCommit: boolean;
36
}
37
38
export interface ChatSessionWorktreePropertiesV2 extends ChatSessionWorktreeBaseProperties {
39
readonly version: 2;
40
readonly autoCommit?: boolean;
41
readonly baseBranchName: string;
42
readonly baseBranchProtected?: boolean;
43
readonly upstreamBranchName?: string;
44
readonly mergeBaseCommit?: string;
45
readonly pullRequestUrl?: string;
46
readonly pullRequestState?: string;
47
readonly firstCheckpointRef?: string;
48
readonly baseCheckpointRef?: string;
49
readonly lastCheckpointRef?: string;
50
readonly hasGitHubRemote?: boolean;
51
readonly incomingChanges?: number;
52
readonly outgoingChanges?: number;
53
readonly uncommittedChanges?: number;
54
}
55
56
export type ChatSessionWorktreeProperties = ChatSessionWorktreePropertiesV1 | ChatSessionWorktreePropertiesV2;
57
58
export const IChatSessionWorktreeService = createServiceIdentifier<IChatSessionWorktreeService>('IChatSessionWorktreeService');
59
60
export interface IChatSessionWorktreeService {
61
readonly _serviceBrand: undefined;
62
/**
63
* Triggered when cached worktree changes for a session are invalidated and should be refreshed.
64
*
65
* This event does not guarantee that the underlying set of changes was updated directly; callers
66
* should re-query {@link getWorktreeChanges} when it fires.
67
*/
68
onDidChangeWorktreeChanges: vscode.Event<{ sessionId: string }>;
69
70
createWorktree(repositoryPath: vscode.Uri, stream?: vscode.ChatResponseStream, baseBranch?: string, branchName?: string): Promise<ChatSessionWorktreeProperties | undefined>;
71
72
getWorktreeProperties(sessionId: string): Promise<ChatSessionWorktreeProperties | undefined>;
73
setWorktreeProperties(sessionId: string, properties: string | ChatSessionWorktreeProperties): Promise<void>;
74
75
getWorktreeRepository(sessionId: string): Promise<RepoContext | undefined>;
76
getWorktreePath(sessionId: string): Promise<vscode.Uri | undefined>;
77
78
applyWorktreeChanges(sessionId: string): Promise<void>;
79
80
getWorktreeChanges(sessionId: string): Promise<readonly vscode.ChatSessionChangedFile[] | undefined>;
81
82
hasCachedChanges(sessionId: string): Promise<boolean>;
83
84
handleRequestCompleted(sessionId: string): Promise<void>;
85
86
/** Get worktree properties for all additional workspaces in a session. */
87
getAdditionalWorktreeProperties(sessionId: string): Promise<ChatSessionWorktreeProperties[]>;
88
89
/** Store worktree properties for additional workspaces in a session. */
90
setAdditionalWorktreeProperties(sessionId: string, properties: ChatSessionWorktreeProperties[]): Promise<void>;
91
92
/** Commit changes in a specific worktree, identified by its properties directly. */
93
handleRequestCompletedForWorktree(worktreeProperties: ChatSessionWorktreeProperties): Promise<void>;
94
95
/**
96
* Attempts to clean up a worktree when a session is archived.
97
* If auto-commit is enabled and there are uncommitted changes, commits them first.
98
* Returns whether the worktree was successfully deleted.
99
*/
100
cleanupWorktreeOnArchive(sessionId: string): Promise<{ cleaned: boolean; reason?: string }>;
101
102
/**
103
* Recreates a worktree from the session branch when a session is unarchived.
104
* The branch must still exist (it is preserved during archive cleanup).
105
* Returns whether the worktree was successfully recreated.
106
*/
107
recreateWorktreeOnUnarchive(sessionId: string): Promise<{ recreated: boolean; reason?: string }>;
108
}
109
110