2025-07-05 23:27:00 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import fs from 'fs/promises';
|
|
|
|
|
import * as os from 'os';
|
|
|
|
|
|
|
|
|
|
type WarningCheck = {
|
|
|
|
|
id: string;
|
|
|
|
|
check: (workspaceRoot: string) => Promise<string | null>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Individual warning checks
|
|
|
|
|
const homeDirectoryCheck: WarningCheck = {
|
|
|
|
|
id: 'home-directory',
|
|
|
|
|
check: async (workspaceRoot: string) => {
|
|
|
|
|
try {
|
|
|
|
|
const [workspaceRealPath, homeRealPath] = await Promise.all([
|
|
|
|
|
fs.realpath(workspaceRoot),
|
|
|
|
|
fs.realpath(os.homedir()),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if (workspaceRealPath === homeRealPath) {
|
|
|
|
|
return 'You are running Gemini CLI in your home directory. It is recommended to run in a project-specific directory.';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
} catch (_err: unknown) {
|
|
|
|
|
return 'Could not verify the current directory due to a file system error.';
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// All warning checks
|
2025-07-15 20:42:27 +02:00
|
|
|
const WARNING_CHECKS: readonly WarningCheck[] = [homeDirectoryCheck];
|
2025-07-05 23:27:00 -07:00
|
|
|
|
|
|
|
|
export async function getUserStartupWarnings(
|
|
|
|
|
workspaceRoot: string,
|
|
|
|
|
): Promise<string[]> {
|
|
|
|
|
const results = await Promise.all(
|
|
|
|
|
WARNING_CHECKS.map((check) => check.check(workspaceRoot)),
|
|
|
|
|
);
|
|
|
|
|
return results.filter((msg) => msg !== null);
|
|
|
|
|
}
|