Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chronicle/common/sessionIndexingPreference.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 { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';
7
import picomatch from 'picomatch';
8
9
/**
10
* Session indexing levels for cloud sync.
11
* - 'local': keep on device only, no remote export
12
* - 'user': sync to cloud, visible only to the user
13
* - 'repo_and_user': sync to cloud, visible to repo collaborators
14
*/
15
export type SessionIndexingLevel = 'local' | 'user' | 'repo_and_user';
16
17
/**
18
* Manages user preferences for session indexing via VS Code settings.
19
*/
20
export class SessionIndexingPreference {
21
22
constructor(
23
private readonly _configService: IConfigurationService,
24
) { }
25
26
/**
27
* Get the effective storage level for a given repo. *
28
* - If cloud sync is enabled and repo is not excluded → 'user'
29
* - Otherwise → 'local'
30
*/
31
getStorageLevel(repoNwo?: string): SessionIndexingLevel {
32
if (this.hasCloudConsent(repoNwo)) {
33
return 'user';
34
}
35
return 'local';
36
}
37
38
/**
39
* Check if cloud sync is enabled for a given repo.
40
* Returns true if cloudSync.enabled is true AND the repo is not excluded.
41
*/
42
hasCloudConsent(repoNwo?: string): boolean {
43
if (!this._configService.getConfig(ConfigKey.TeamInternal.SessionSearchCloudSyncEnabled)) {
44
return false;
45
}
46
47
if (repoNwo) {
48
const excludePatterns = this._configService.getConfig(ConfigKey.TeamInternal.SessionSearchCloudSyncExcludeRepositories);
49
if (excludePatterns && excludePatterns.length > 0) {
50
for (const pattern of excludePatterns) {
51
if (pattern === repoNwo || picomatch.isMatch(repoNwo, pattern)) {
52
return false;
53
}
54
}
55
}
56
}
57
58
return true;
59
}
60
}
61
62