Override Gemini CLI trust with VScode workspace trust when in IDE (#7433)

This commit is contained in:
shrutip90
2025-09-03 11:44:26 -07:00
committed by GitHub
parent 5ccf46b5a0
commit 7c667e100e
16 changed files with 248 additions and 30 deletions

View File

@@ -0,0 +1,47 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { useCallback, useEffect, useState, useSyncExternalStore } from 'react';
import type { Config } from '@google/gemini-cli-core';
import { ideContext } from '@google/gemini-cli-core';
/**
* This hook listens for trust status updates from the IDE companion extension.
* It provides the current trust status from the IDE and a flag indicating
* if a restart is needed because the trust state has changed.
*/
export function useIdeTrustListener(config: Config) {
const subscribe = useCallback(
(onStoreChange: () => void) => {
const ideClient = config.getIdeClient();
ideClient.addTrustChangeListener(onStoreChange);
return () => {
ideClient.removeTrustChangeListener(onStoreChange);
};
},
[config],
);
const getSnapshot = () =>
ideContext.getIdeContext()?.workspaceState?.isTrusted;
const isIdeTrusted = useSyncExternalStore(subscribe, getSnapshot);
const [needsRestart, setNeedsRestart] = useState(false);
const [initialTrustValue] = useState(isIdeTrusted);
useEffect(() => {
if (
!needsRestart &&
initialTrustValue !== undefined &&
initialTrustValue !== isIdeTrusted
) {
setNeedsRestart(true);
}
}, [isIdeTrusted, initialTrustValue, needsRestart]);
return { isIdeTrusted, needsRestart };
}