feat(cli): add warnings when gemini-cli is called in the root directory (#4542)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
Yuki Okita
2025-07-21 06:57:09 +09:00
committed by GitHub
parent 2a95c8287e
commit 0996d91f0b
2 changed files with 82 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
import fs from 'fs/promises';
import * as os from 'os';
import path from 'path';
type WarningCheck = {
id: string;
@@ -32,8 +33,31 @@ const homeDirectoryCheck: WarningCheck = {
},
};
const rootDirectoryCheck: WarningCheck = {
id: 'root-directory',
check: async (workspaceRoot: string) => {
try {
const workspaceRealPath = await fs.realpath(workspaceRoot);
const errorMessage =
'Warning: You are running Gemini CLI in the root directory. Your entire folder structure will be used for context. It is strongly recommended to run in a project-specific directory.';
// Check for Unix root directory
if (path.dirname(workspaceRealPath) === workspaceRealPath) {
return errorMessage;
}
return null;
} catch (_err: unknown) {
return 'Could not verify the current directory due to a file system error.';
}
},
};
// All warning checks
const WARNING_CHECKS: readonly WarningCheck[] = [homeDirectoryCheck];
const WARNING_CHECKS: readonly WarningCheck[] = [
homeDirectoryCheck,
rootDirectoryCheck,
];
export async function getUserStartupWarnings(
workspaceRoot: string,