summaryrefslogtreecommitdiff
path: root/packages/cli/src/utils/userStartupWarnings.ts
diff options
context:
space:
mode:
authorPyush Sinha <[email protected]>2025-07-05 23:27:00 -0700
committerGitHub <[email protected]>2025-07-06 06:27:00 +0000
commit39e8509452b359774cc363a7e98810e48ec516a4 (patch)
tree84807b28a1be51bfd89212114244559c241f5d64 /packages/cli/src/utils/userStartupWarnings.ts
parentda9b1baa6e64ac9c83c988b580d45423ce7d574d (diff)
feat: add user startup warnings, add home directory check (#3056)
Diffstat (limited to 'packages/cli/src/utils/userStartupWarnings.ts')
-rw-r--r--packages/cli/src/utils/userStartupWarnings.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/cli/src/utils/userStartupWarnings.ts b/packages/cli/src/utils/userStartupWarnings.ts
new file mode 100644
index 00000000..3d76a6e1
--- /dev/null
+++ b/packages/cli/src/utils/userStartupWarnings.ts
@@ -0,0 +1,45 @@
+/**
+ * @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
+const WARNING_CHECKS: readonly WarningCheck[] = [homeDirectoryCheck];
+
+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);
+}