-
Notifications
You must be signed in to change notification settings - Fork 39.3k
Expand file tree
/
Copy pathsessionIndexingPreference.ts
More file actions
68 lines (60 loc) · 2.28 KB
/
sessionIndexingPreference.ts
File metadata and controls
68 lines (60 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';
import picomatch from 'picomatch';
/**
* Session indexing levels for cloud sync.
* - 'local': keep on device only, no remote export
* - 'user': sync to cloud, visible only to the user
* - 'repo_and_user': sync to cloud, visible to repo collaborators
*/
export type SessionIndexingLevel = 'local' | 'user' | 'repo_and_user';
/**
* Manages user preferences for session indexing via VS Code settings.
*
* Two settings control behavior:
* - `chat.sessionSearch.localIndex.enabled` (team-internal, ExP) — enables local
* SQLite tracking and /chronicle commands
* - `chat.sessionSearch.cloudSync.enabled` — enables
* cloud upload to cloud
* - `chat.sessionSearch.cloudSync.excludeRepositories` — repo patterns
* to exclude from cloud sync
*/
export class SessionIndexingPreference {
constructor(
private readonly _configService: IConfigurationService,
) { }
/**
* Get the effective storage level for a given repo. *
* - If cloud sync is enabled and repo is not excluded → 'user'
* - Otherwise → 'local'
*/
getStorageLevel(repoNwo?: string): SessionIndexingLevel {
if (this.hasCloudConsent(repoNwo)) {
return 'user';
}
return 'local';
}
/**
* Check if cloud sync is enabled for a given repo.
* Returns true if cloudSync.enabled is true AND the repo is not excluded.
*/
hasCloudConsent(repoNwo?: string): boolean {
if (!this._configService.getConfig(ConfigKey.TeamInternal.SessionSearchCloudSyncEnabled)) {
return false;
}
if (repoNwo) {
const excludePatterns = this._configService.getConfig(ConfigKey.TeamInternal.SessionSearchCloudSyncExcludeRepositories);
if (excludePatterns && excludePatterns.length > 0) {
for (const pattern of excludePatterns) {
if (pattern === repoNwo || picomatch.isMatch(repoNwo, pattern)) {
return false;
}
}
}
}
return true;
}
}