Path: blob/main/extensions/copilot/src/extension/chatSessions/common/folderRepositoryManager.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 { createServiceIdentifier } from '../../../util/common/services';7import { IWorkspaceInfo } from './workspaceInfo';89/**10* The isolation mode for a chat session.11* - `worktree`: Creates an isolated git worktree for the session.12* - `workspace`: Works directly in the workspace directory without isolation.13* Do not change these values, they are stored in global storage.14*/15export enum IsolationMode {16Workspace = 'workspace',17Worktree = 'worktree',18}192021/**22* Options for initializing a folder/repository for a session.23*/24export interface InitializeFolderRepositoryOptions {25readonly branch?: string;26readonly folder: vscode.Uri | undefined;27readonly isolation?: IsolationMode;28readonly stream: vscode.ChatResponseStream;29readonly toolInvocationToken: vscode.ChatParticipantToolToken;30readonly newBranch?: Promise<string | undefined>;31}3233/**34* Result of folder/repository resolution for a chat session.35*/36export interface FolderRepositoryInfo extends IWorkspaceInfo {37/**38* Trust status of the folder/repository.39* - `true`: The folder/repository is trusted40* - `false`: Trust was requested but denied by user41* - `undefined`: Trust was not requested (options.promptForTrust was not set)42*/43readonly trusted: boolean | undefined;4445/**46* Whether the user cancelled the operation (e.g., cancelled uncommitted changes prompt).47*/48readonly cancelled?: boolean;49}5051/**52* Options for getting folder/repository information.53*/54export interface GetFolderRepositoryOptions {55/**56* If true, prompts the user for trust if the folder is not already trusted.57*/58readonly promptForTrust: true;5960readonly stream: vscode.ChatResponseStream;61}6263/**64* MRU (Most Recently Used) folder/repository entry.65*/66export interface FolderRepositoryMRUEntry {67/**68* The folder URI.69*/70readonly folder: vscode.Uri;7172/**73* The repository URI if this is a git repository, undefined for plain folders.74*/75readonly repository: vscode.Uri | undefined;7677/**78* Timestamp of last access (milliseconds since epoch).79*/80readonly lastAccessed: number;81}8283export const IFolderRepositoryManager = createServiceIdentifier<IFolderRepositoryManager>('IFolderRepositoryManager');8485export interface IFolderRepositoryManager {86readonly _serviceBrand: undefined;8788/**89* @deprecated90*/91setNewSessionFolder(sessionId: string, folderUri: vscode.Uri): void;9293/**94* Delete the tracked folder for an untitled session.95*/96deleteNewSessionFolder(sessionId: string): void;9798/**99* Get folder/repository/worktree/trust information for a session.100*101* This method resolves folder information using the following priority:102* 1. Worktree properties (if session has a worktree)103* 2. Session workspace folder (if tracked)104* 3. CLI session working directory (from session metadata)105*106* Trust checking is performed on the repository path (if git repo) or folder path107* (if plain folder). Worktree paths are NOT used for trust checking as they inherit108* trust from their parent repository.109*/110getFolderRepository(111sessionId: string,112options: GetFolderRepositoryOptions | undefined,113token: vscode.CancellationToken114): Promise<FolderRepositoryInfo>;115116/**117* Initialize folder/repository for a session, creating a worktree if applicable.118*119* This method should be called when starting a request for an untitled session.120* It will:121* 1. Get the selected folder from memory or workspace folder service122* 2. Check if the folder contains a git repository123* 3. Verify trust on the repository/folder124* 4. Check for uncommitted changes and prompt the user via the provided callback125* 5. Create a worktree if a git repo is found126* 6. Migrate uncommitted changes to worktree if requested127*/128initializeFolderRepository(129sessionId: string | undefined,130options: InitializeFolderRepositoryOptions,131token: vscode.CancellationToken132): Promise<FolderRepositoryInfo>;133134/**135* Initialize all folders for a multi-root session as a batch.136*137* Unlike calling `initializeFolderRepository` per folder, this method:138* 1. Resolves all folder/repo info in one pass139* 2. Verifies trust for all folders together140* 3. Collects uncommitted changes across ALL git repos141* 4. Shows ONE combined prompt listing all repos with uncommitted changes142* 5. Applies the same action (move/copy/skip/cancel) to all repos143* 6. Creates worktrees for all git repos in parallel144* 7. Migrates changes to all worktrees with the same action145*/146initializeMultiRootFolderRepositories(147sessionId: string,148primaryFolder: vscode.Uri,149additionalFolders: vscode.Uri[],150options: InitializeFolderRepositoryOptions,151token: vscode.CancellationToken152): Promise<{ primary: FolderRepositoryInfo; additional: FolderRepositoryInfo[] }>;153154/**155* Get repository information for a folder.156*157* Resolves whether the folder contains a git repository and returns158* the repository URI and HEAD branch name.159*160* @param folder The folder URI to check161* @param token Cancellation token162* @returns Repository URI and HEAD branch name163*/164getRepositoryInfo(165folder: vscode.Uri,166token: vscode.CancellationToken167): Promise<{ repository: vscode.Uri | undefined; headBranchName: string | undefined }>;168169/**170* @deprecated171* Get list of most recently used folders and repositories.172*173* This is used for empty workspaces to show a list of previously used174* folders/repos in the folder selection dropdown.175*176* @returns Array of MRU entries sorted by last accessed time (newest first),177* limited to 10 items, with non-existent paths filtered out178*/179getFolderMRU(): Promise<FolderRepositoryMRUEntry[]>;180}181182export interface IChatFolderMruService {183readonly _serviceBrand: undefined;184getRecentlyUsedFolders(token: vscode.CancellationToken): Promise<FolderRepositoryMRUEntry[]>;185deleteRecentlyUsedFolder(folder: vscode.Uri): Promise<void>;186}187export const IChatFolderMruService = createServiceIdentifier<IChatFolderMruService>('IChatFolderMruService');188189190