mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 19:44:30 -07:00
feat(cli): disable folder trust in headless mode (#18407)
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import process from 'node:process';
|
||||
|
||||
/**
|
||||
* Options for headless mode detection.
|
||||
*/
|
||||
export interface HeadlessModeOptions {
|
||||
/** Explicit prompt string or flag. */
|
||||
prompt?: string | boolean;
|
||||
/** Initial query positional argument. */
|
||||
query?: string | boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if the CLI is running in a "headless" (non-interactive) mode.
|
||||
*
|
||||
* Headless mode is triggered by:
|
||||
* 1. process.env.CI being set to 'true'.
|
||||
* 2. process.stdout not being a TTY.
|
||||
* 3. Presence of an explicit prompt flag.
|
||||
*
|
||||
* @param options - Optional flags and arguments from the CLI.
|
||||
* @returns true if the environment is considered headless.
|
||||
*/
|
||||
export function isHeadlessMode(options?: HeadlessModeOptions): boolean {
|
||||
if (process.env['GEMINI_CLI_INTEGRATION_TEST'] === 'true') {
|
||||
return (
|
||||
!!options?.prompt ||
|
||||
(!!process.stdin && !process.stdin.isTTY) ||
|
||||
(!!process.stdout && !process.stdout.isTTY)
|
||||
);
|
||||
}
|
||||
return (
|
||||
process.env['CI'] === 'true' ||
|
||||
process.env['GITHUB_ACTIONS'] === 'true' ||
|
||||
!!options?.prompt ||
|
||||
(!!process.stdin && !process.stdin.isTTY) ||
|
||||
(!!process.stdout && !process.stdout.isTTY)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user