Skip to content

fix(cli): prompt for folder trust before auth#27845

Closed
Alvin0412 wants to merge 1 commit into
google-gemini:mainfrom
Alvin0412:fix/folder-trust-before-auth
Closed

fix(cli): prompt for folder trust before auth#27845
Alvin0412 wants to merge 1 commit into
google-gemini:mainfrom
Alvin0412:fix/folder-trust-before-auth

Conversation

@Alvin0412

Copy link
Copy Markdown

Fixes #27844

Summary

  • Add an early folder-trust prompt for interactive launches when the workspace trust state is unknown.
  • Save the selected trust level before auth starts; relaunch when the user chooses to trust the folder so workspace settings and local configuration are loaded under the new trust state.
  • Use the real stdout proxy for the early prompt so it remains visible after stdio is patched.
  • Add focused tests for the trust prompt behavior and for the startup ordering before refreshAuth().

Test plan

  • npm run test --workspace @google/gemini-cli -- folderTrustPrompt.test.ts gemini.test.tsx --testNamePattern "maybePromptForFolderTrust|should resolve folder trust before refreshing auth"
  • npm run typecheck --workspace @google/gemini-cli
  • npm run lint --workspace @google/gemini-cli
  • Smoke test with a temporary GEMINI_CLI_HOME and temporary workspace using packages/cli/dist/index.js; the folder trust prompt appeared before auth/UI startup (PROMPT_MS=1609).

@Alvin0412 Alvin0412 requested a review from a team as a code owner June 11, 2026 05:55
@google-cla

google-cla Bot commented Jun 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the size/l A large sized PR label Jun 11, 2026
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 358
  • Additions: +358
  • Deletions: -0
  • Files changed: 4

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 improves the security and configuration lifecycle of the Gemini CLI by enforcing a folder trust check during the initial startup phase. By prompting users to trust their workspace folder before authentication, the CLI ensures that subsequent operations, such as loading workspace settings or MCP servers, are performed in a secure and consistent environment. The implementation includes a robust relaunch mechanism to apply trust decisions immediately and provides focused tests to validate the startup ordering.

Highlights

  • Early Folder Trust Prompt: Introduced a mandatory folder-trust prompt for interactive CLI launches when the workspace trust state is unknown, ensuring security decisions are made before authentication.
  • Relaunch Mechanism: Implemented a relaunch flow upon folder trust approval to ensure workspace settings and local configurations are correctly loaded under the new trust state.
  • Testing and Reliability: Added comprehensive unit tests for the trust prompt behavior and verified the startup sequence to ensure the prompt executes before refreshAuth().
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a folder trust prompt mechanism (maybePromptForFolderTrust) to resolve unknown workspace trust states during CLI startup, ensuring it runs before slow operations like authentication. It also adds comprehensive unit tests for this flow. The review feedback suggests a high-severity improvement: when using the prompts library, both stdin and stdout streams from createWorkingStdio() should be passed as the second argument (options) to ensure interactive prompts correctly receive user input when patchStdio() is active.

Comment on lines +75 to +96
const { stdout } = createWorkingStdio();
const response = await prompts({
type: 'select',
name: 'trustLevel',
message: 'Do you want to trust this folder?',
choices: [
{
title: `Trust folder (${dirName})`,
value: TrustLevel.TRUST_FOLDER,
},
{
title: `Trust parent folder (${parentFolder})`,
value: TrustLevel.TRUST_PARENT,
},
{
title: "Don't trust",
value: TrustLevel.DO_NOT_TRUST,
},
],
initial: 0,
stdout,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When patchStdio() is active, process.stdin might be patched or intercepted. To ensure the interactive prompt correctly receives user input, you should pass the working stdin stream (obtained from createWorkingStdio()) to prompts as part of its options (the second argument). Passing stdout in the options object is also the standard and documented way to configure custom streams in prompts.

  const { stdin, stdout } = createWorkingStdio();
  const response = await prompts({
    type: 'select',
    name: 'trustLevel',
    message: 'Do you want to trust this folder?',
    choices: [
      {
        title: 'Trust folder (' + dirName + ')',
        value: TrustLevel.TRUST_FOLDER,
      },
      {
        title: 'Trust parent folder (' + parentFolder + ')',
        value: TrustLevel.TRUST_PARENT,
      },
      {
        title: "Don't trust",
        value: TrustLevel.DO_NOT_TRUST,
      },
    ],
    initial: 0,
  }, {
    stdin,
    stdout,
  });

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0273154. The prompt now explicitly passes stdin: process.stdin and the real stdout from createWorkingStdio(), with a test assertion covering both streams.

I kept the streams on the prompt object rather than the second prompts argument because this repository currently uses prompts@2.4.2; its implementation and TypeScript types pass stdin/stdout through the question object, while the second argument only handles submit/cancel callbacks. Also, createWorkingStdio() currently returns stdout/stderr proxies, not stdin, and patchStdio() only patches stdout/stderr.

@Alvin0412 Alvin0412 force-pushed the fix/folder-trust-before-auth branch from 0150eb2 to 0273154 Compare June 11, 2026 06:04
@Alvin0412

Copy link
Copy Markdown
Author

Updated in 0273154. I made the prompt explicitly pass both streams: stdin: process.stdin and the real stdout from createWorkingStdio(), and added a test assertion for both. I kept these on the prompt object rather than the second prompts argument because the current prompts implementation and TypeScript types pass stdin/stdout through the question object; the second argument only handles submit/cancel callbacks.

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Jun 11, 2026
@gemini-cli gemini-cli Bot added the priority/p2 Important but can be addressed in a future release. label Jun 11, 2026
@gemini-cli

gemini-cli Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@gemini-cli

gemini-cli Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p2 Important but can be addressed in a future release. size/l A large sized PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prompt for folder trust before slow startup auth

1 participant