summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useFolderTrust.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/ui/hooks/useFolderTrust.ts')
-rw-r--r--packages/cli/src/ui/hooks/useFolderTrust.ts41
1 files changed, 28 insertions, 13 deletions
diff --git a/packages/cli/src/ui/hooks/useFolderTrust.ts b/packages/cli/src/ui/hooks/useFolderTrust.ts
index 90a69132..6458d4aa 100644
--- a/packages/cli/src/ui/hooks/useFolderTrust.ts
+++ b/packages/cli/src/ui/hooks/useFolderTrust.ts
@@ -5,24 +5,39 @@
*/
import { useState, useCallback } from 'react';
-import { LoadedSettings, SettingScope } from '../../config/settings.js';
+import { type Config } from '@google/gemini-cli-core';
+import { LoadedSettings } from '../../config/settings.js';
import { FolderTrustChoice } from '../components/FolderTrustDialog.js';
+import { loadTrustedFolders, TrustLevel } from '../../config/trustedFolders.js';
+import * as process from 'process';
-export const useFolderTrust = (settings: LoadedSettings) => {
+export const useFolderTrust = (settings: LoadedSettings, config: Config) => {
const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(
- !!settings.merged.folderTrustFeature &&
- // TODO: Update to avoid showing dialog for folders that are trusted.
- settings.merged.folderTrust === undefined,
+ config.isTrustedFolder() === undefined,
);
- const handleFolderTrustSelect = useCallback(
- (_choice: FolderTrustChoice) => {
- // TODO: Store folderPath in the trusted folders config file based on the choice.
- settings.setValue(SettingScope.User, 'folderTrust', true);
- setIsFolderTrustDialogOpen(false);
- },
- [settings],
- );
+ const handleFolderTrustSelect = useCallback((choice: FolderTrustChoice) => {
+ const trustedFolders = loadTrustedFolders();
+ const cwd = process.cwd();
+ let trustLevel: TrustLevel;
+
+ switch (choice) {
+ case FolderTrustChoice.TRUST_FOLDER:
+ trustLevel = TrustLevel.TRUST_FOLDER;
+ break;
+ case FolderTrustChoice.TRUST_PARENT:
+ trustLevel = TrustLevel.TRUST_PARENT;
+ break;
+ case FolderTrustChoice.DO_NOT_TRUST:
+ trustLevel = TrustLevel.DO_NOT_TRUST;
+ break;
+ default:
+ return;
+ }
+
+ trustedFolders.setValue(cwd, trustLevel);
+ setIsFolderTrustDialogOpen(false);
+ }, []);
return {
isFolderTrustDialogOpen,