feat(ui): reduce home directory warning noise and add opt-out setting (#16229)

This commit is contained in:
N. Taylor Mullen
2026-01-09 11:56:22 -08:00
committed by GitHub
parent ca48661423
commit 14f0cb4538
6 changed files with 95 additions and 12 deletions

View File

@@ -8,16 +8,25 @@ import fs from 'node:fs/promises';
import path from 'node:path';
import process from 'node:process';
import { homedir } from '@google/gemini-cli-core';
import type { Settings } from '../config/settingsSchema.js';
import {
isFolderTrustEnabled,
isWorkspaceTrusted,
} from '../config/trustedFolders.js';
type WarningCheck = {
id: string;
check: (workspaceRoot: string) => Promise<string | null>;
check: (workspaceRoot: string, settings: Settings) => Promise<string | null>;
};
// Individual warning checks
const homeDirectoryCheck: WarningCheck = {
id: 'home-directory',
check: async (workspaceRoot: string) => {
check: async (workspaceRoot: string, settings: Settings) => {
if (settings.ui?.showHomeDirectoryWarning === false) {
return null;
}
try {
const [workspaceRealPath, homeRealPath] = await Promise.all([
fs.realpath(workspaceRoot),
@@ -25,7 +34,15 @@ const homeDirectoryCheck: WarningCheck = {
]);
if (workspaceRealPath === homeRealPath) {
return 'You are running Gemini CLI in your home directory. It is recommended to run in a project-specific directory.';
// If folder trust is enabled and the user trusts the home directory, don't show the warning.
if (
isFolderTrustEnabled(settings) &&
isWorkspaceTrusted(settings).isTrusted
) {
return null;
}
return 'Warning you are running Gemini CLI in your home directory.\nThis warning can be disabled in /settings';
}
return null;
} catch (_err: unknown) {
@@ -36,7 +53,7 @@ const homeDirectoryCheck: WarningCheck = {
const rootDirectoryCheck: WarningCheck = {
id: 'root-directory',
check: async (workspaceRoot: string) => {
check: async (workspaceRoot: string, _settings: Settings) => {
try {
const workspaceRealPath = await fs.realpath(workspaceRoot);
const errorMessage =
@@ -61,10 +78,11 @@ const WARNING_CHECKS: readonly WarningCheck[] = [
];
export async function getUserStartupWarnings(
settings: Settings,
workspaceRoot: string = process.cwd(),
): Promise<string[]> {
const results = await Promise.all(
WARNING_CHECKS.map((check) => check.check(workspaceRoot)),
WARNING_CHECKS.map((check) => check.check(workspaceRoot, settings)),
);
return results.filter((msg) => msg !== null);
}