summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useFolderTrust.ts
diff options
context:
space:
mode:
authorshrutip90 <[email protected]>2025-08-14 11:15:48 -0700
committerGitHub <[email protected]>2025-08-14 18:15:48 +0000
commit69c55827239b5c937c177eef4b4fbcc2758ef23e (patch)
treef2dc2f1a55e64cd9a235bcf0e3d9caaa7f552b7c /packages/cli/src/ui/hooks/useFolderTrust.ts
parent69d666cfafe97e49a6cacb306df9a737d4aa9f20 (diff)
feat: Show untrusted status in the Footer (#6210)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/hooks/useFolderTrust.ts')
-rw-r--r--packages/cli/src/ui/hooks/useFolderTrust.ts82
1 files changed, 54 insertions, 28 deletions
diff --git a/packages/cli/src/ui/hooks/useFolderTrust.ts b/packages/cli/src/ui/hooks/useFolderTrust.ts
index 6458d4aa..28b82b30 100644
--- a/packages/cli/src/ui/hooks/useFolderTrust.ts
+++ b/packages/cli/src/ui/hooks/useFolderTrust.ts
@@ -4,42 +4,68 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import { useState, useCallback } from 'react';
-import { type Config } from '@google/gemini-cli-core';
-import { LoadedSettings } from '../../config/settings.js';
+import { useState, useCallback, useEffect } from 'react';
+import { Settings, LoadedSettings } from '../../config/settings.js';
import { FolderTrustChoice } from '../components/FolderTrustDialog.js';
-import { loadTrustedFolders, TrustLevel } from '../../config/trustedFolders.js';
+import {
+ loadTrustedFolders,
+ TrustLevel,
+ isWorkspaceTrusted,
+} from '../../config/trustedFolders.js';
import * as process from 'process';
-export const useFolderTrust = (settings: LoadedSettings, config: Config) => {
- const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(
- config.isTrustedFolder() === undefined,
- );
+export const useFolderTrust = (
+ settings: LoadedSettings,
+ onTrustChange: (isTrusted: boolean | undefined) => void,
+) => {
+ const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined);
+ const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false);
+
+ const { folderTrust, folderTrustFeature } = settings.merged;
+ useEffect(() => {
+ const trusted = isWorkspaceTrusted({
+ folderTrust,
+ folderTrustFeature,
+ } as Settings);
+ setIsTrusted(trusted);
+ setIsFolderTrustDialogOpen(trusted === undefined);
+ onTrustChange(trusted);
+ }, [onTrustChange, folderTrust, folderTrustFeature]);
- const handleFolderTrustSelect = useCallback((choice: FolderTrustChoice) => {
- const trustedFolders = loadTrustedFolders();
- const cwd = process.cwd();
- let trustLevel: TrustLevel;
+ 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;
- }
+ 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);
- }, []);
+ trustedFolders.setValue(cwd, trustLevel);
+ const trusted = isWorkspaceTrusted({
+ folderTrust,
+ folderTrustFeature,
+ } as Settings);
+ setIsTrusted(trusted);
+ setIsFolderTrustDialogOpen(false);
+ onTrustChange(trusted);
+ },
+ [onTrustChange, folderTrust, folderTrustFeature],
+ );
return {
+ isTrusted,
isFolderTrustDialogOpen,
handleFolderTrustSelect,
};