Path: blob/main/extensions/copilot/src/extension/chronicle/common/sessionIndexingPreference.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 { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';6import picomatch from 'picomatch';78/**9* Session indexing levels for cloud sync.10* - 'local': keep on device only, no remote export11* - 'user': sync to cloud, visible only to the user12* - 'repo_and_user': sync to cloud, visible to repo collaborators13*/14export type SessionIndexingLevel = 'local' | 'user' | 'repo_and_user';1516/**17* Manages user preferences for session indexing via VS Code settings.18*/19export class SessionIndexingPreference {2021constructor(22private readonly _configService: IConfigurationService,23) { }2425/**26* Get the effective storage level for a given repo. *27* - If cloud sync is enabled and repo is not excluded → 'user'28* - Otherwise → 'local'29*/30getStorageLevel(repoNwo?: string): SessionIndexingLevel {31if (this.hasCloudConsent(repoNwo)) {32return 'user';33}34return 'local';35}3637/**38* Check if cloud sync is enabled for a given repo.39* Returns true if cloudSync.enabled is true AND the repo is not excluded.40*/41hasCloudConsent(repoNwo?: string): boolean {42if (!this._configService.getConfig(ConfigKey.TeamInternal.SessionSearchCloudSyncEnabled)) {43return false;44}4546if (repoNwo) {47const excludePatterns = this._configService.getConfig(ConfigKey.TeamInternal.SessionSearchCloudSyncExcludeRepositories);48if (excludePatterns && excludePatterns.length > 0) {49for (const pattern of excludePatterns) {50if (pattern === repoNwo || picomatch.isMatch(repoNwo, pattern)) {51return false;52}53}54}55}5657return true;58}59}606162