feat(ui): show authenticated account and plan on startup - #17413
feat(ui): show authenticated account and plan on startup#17413keithguerin wants to merge 1 commit into
Conversation
Summary of ChangesHello @keithguerin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the user experience of the Gemini CLI by providing immediate feedback on the authenticated user's identity and plan upon application launch. By integrating this information directly into the chat history, users can quickly confirm their session context, while also offering a new configuration option to tailor this behavior to individual preferences. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
@sehoon38 Can you take this from here please? |
There was a problem hiding this comment.
Code Review
This pull request introduces a feature to display the authenticated user's account and plan on startup, which is a nice addition for user context. The implementation is mostly sound, with a new configuration option to control this behavior. However, I've identified a significant performance issue related to synchronous file I/O that blocks the main thread during startup. My review includes a high-severity comment with a suggested refactoring to address this by using asynchronous operations, which will improve the application's responsiveness.
| const initialHistoryItems = useMemo(() => { | ||
| const items: HistoryItem[] = []; | ||
| if (resumedSessionData) return items; | ||
|
|
||
| // Check if the user has disabled showing auth on startup | ||
| if (settings.merged.ui.showAuthOnStartup === false) return items; | ||
|
|
||
| // We can't use authState here because it's initialized in useAuthCommand which is called later. | ||
| // However, we can check config directly since we know startup just finished. | ||
| const authType = config.getContentGeneratorConfig()?.authType; | ||
| if ( | ||
| authType === AuthType.LOGIN_WITH_GOOGLE || | ||
| authType === AuthType.COMPUTE_ADC | ||
| ) { | ||
| try { | ||
| const userAccountManager = new UserAccountManager(); | ||
| const email = userAccountManager.getCachedGoogleAccount(); | ||
| const tier = config.getUserTier(); | ||
|
|
||
| if (email) { | ||
| let message = `Authenticated as: ${email}`; | ||
| if (tier) { | ||
| message += ` (Plan: ${tier})`; | ||
| } | ||
| items.push({ | ||
| id: Date.now(), // Use timestamp as ID for initial item | ||
| type: MessageType.INFO, | ||
| text: message, | ||
| }); | ||
| } | ||
| } catch (_e) { | ||
| // Ignore errors during initial auth check | ||
| } | ||
| } | ||
| return items; | ||
| }, [config, resumedSessionData, settings.merged.ui.showAuthOnStartup]); | ||
|
|
||
| const historyManager = useHistory({ | ||
| chatRecordingService: config.getGeminiClient()?.getChatRecordingService(), | ||
| initialItems: initialHistoryItems, | ||
| }); |
There was a problem hiding this comment.
The useMemo hook for initialHistoryItems performs synchronous file I/O via userAccountManager.getCachedGoogleAccount(), which can block the event loop. This is a performance concern and goes against the project's guideline of using asynchronous file operations.
This logic should be moved into a useEffect hook to handle it asynchronously. This would also allow you to use historyManager.addItem(), which correctly generates unique IDs for history items, avoiding the use of Date.now() as a React key.
I'm providing a code suggestion to refactor this. I've added a TODO comment to highlight that the synchronous call still needs to be addressed, ideally by adding an async method to UserAccountManager.
const historyManager = useHistory({
chatRecordingService: config.getGeminiClient()?.getChatRecordingService(),
});
const { addItem } = historyManager;
useEffect(() => {
if (resumedSessionData || settings.merged.ui.showAuthOnStartup === false) {
return;
}
const authType = config.getContentGeneratorConfig()?.authType;
if (
authType !== AuthType.LOGIN_WITH_GOOGLE &&
authType !== AuthType.COMPUTE_ADC
) {
return;
}
try {
// TODO: This should be made asynchronous to avoid blocking the event loop.
const userAccountManager = new UserAccountManager();
const email = userAccountManager.getCachedGoogleAccount();
const tier = config.getUserTier();
if (email) {
let message = `Authenticated as: ${email}`;
if (tier) {
message += ` (Plan: ${tier})`;
}
addItem({
type: MessageType.INFO,
text: message,
});
}
} catch (_e) {
// Ignore errors during initial auth check
}
}, [config, resumedSessionData, settings.merged.ui.showAuthOnStartup, addItem]);
References
- When selecting an item from a list where simple IDs may not be unique, use a guaranteed unique identifier, such as an index or a composite key, to avoid ambiguity when retrieving the selected item with methods like
Array.prototype.find().
|
Hi there! Thank you for your contribution to Gemini CLI. To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md. This pull request is being closed because it is not currently linked to an issue. You can easily reopen this PR once you have linked it to an issue. How to link an issue: Thank you for your understanding and for being a part of our community! |
Summary
Displays the currently authenticated user's email and plan (tier) in the chat history when the Gemini CLI starts up. This provides users with immediate context about their session identity.
Details
AppContainer.tsxto check for authentication status on component mount.UserAccountManagerto retrieve the cached Google account email.config.getUserTier()to retrieve the user's plan.ui.showAuthOnStartupsetting (defaulttrue) to disable this feature.Related Issues
Fixes #17413
How to Validate
npm run buildnpm start"ui": { "showAuthOnStartup": false }to settings.Pre-Merge Checklist