Changesets · Branches · Tags · Compare
| Changeset | 85f086de04b129a9bb65904e9346224cb30fa8528657f15922aa93fce1dc5c2f |
|---|---|
| Author | uinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-09-04 20:21 +05:30 |
| Committer | uinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-09-04 20:21 +05:30 |
| Parents | 889a2b6d9e98 |
3 files changed
modified extensions/cli/src/ui/IntroMessage.tsx +4 −16
| @@ -1,12 +1,10 @@ | ||
| 1 | -import * as os from "node:os"; | |
| 2 | -import * as path from "node:path"; | |
| 3 | - | |
| 4 | 1 | import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 5 | 2 | import { Box, Text } from "ink"; |
| 6 | 3 | import React, { useMemo } from "react"; |
| 7 | 4 | |
| 8 | 5 | import { getDisplayableAsciiArt } from "../asciiArt.js"; |
| 9 | 6 | import { MCPService } from "../services/MCPService.js"; |
| 7 | +import { isInHomeDirectory } from "../util/isInHomeDirectory.js"; | |
| 10 | 8 | import { isModelCapable } from "../utils/modelCapability.js"; |
| 11 | 9 | |
| 12 | 10 | import { ModelCapabilityWarning } from "./ModelCapabilityWarning.js"; |
| @@ -29,6 +27,8 @@ | ||
| 29 | 27 | ); |
| 30 | 28 | }; |
| 31 | 29 | |
| 30 | +const userInHomeDirectory = isInHomeDirectory(); | |
| 31 | + | |
| 32 | 32 | const IntroMessage: React.FC<IntroMessageProps> = ({ |
| 33 | 33 | config, |
| 34 | 34 | model, |
| @@ -40,18 +40,6 @@ | ||
| 40 | 40 | // Determine if we should show a tip (1 in 5 chance) - computed once on mount |
| 41 | 41 | const showTip = useMemo(() => shouldShowTip(), []); |
| 42 | 42 | |
| 43 | - // Check if current working directory is the home directory | |
| 44 | - const isInHomeDirectory = useMemo(() => { | |
| 45 | - const cwd = process.cwd(); | |
| 46 | - const homedir = os.homedir(); | |
| 47 | - const resolvedCwd = path.resolve(cwd); | |
| 48 | - const resolvedHome = path.resolve(homedir); | |
| 49 | - if (process.platform === "win32") { | |
| 50 | - return resolvedCwd.toLowerCase() === resolvedHome.toLowerCase(); | |
| 51 | - } | |
| 52 | - return resolvedCwd === resolvedHome; | |
| 53 | - }, []); | |
| 54 | - | |
| 55 | 43 | // Memoize expensive operations to avoid running on every resize |
| 56 | 44 | const { allRules, modelCapable } = useMemo(() => { |
| 57 | 45 | const allRules = extractRuleNames(config?.rules); |
| @@ -153,7 +141,7 @@ | ||
| 153 | 141 | {renderMcpServers()} |
| 154 | 142 | |
| 155 | 143 | {/* Home directory warning */} |
| 156 | - {isInHomeDirectory && ( | |
| 144 | + {userInHomeDirectory && ( | |
| 157 | 145 | <> |
| 158 | 146 | <Text color="yellow">{HOME_DIRECTORY_WARNING}</Text> |
| 159 | 147 | <Text> </Text> |
added extensions/cli/src/util/isInHomeDirectory.test.ts +85 −0
| @@ -0,0 +1,85 @@ | ||
| 1 | +// eslint-disable-next-line import/order | |
| 2 | +import { vi } from "vitest"; | |
| 3 | + | |
| 4 | +vi.mock("node:os", () => ({ | |
| 5 | + default: { | |
| 6 | + homedir: vi.fn(), | |
| 7 | + }, | |
| 8 | +})); | |
| 9 | + | |
| 10 | +vi.mock("node:path", () => ({ | |
| 11 | + default: { | |
| 12 | + resolve: vi.fn(), | |
| 13 | + }, | |
| 14 | +})); | |
| 15 | + | |
| 16 | +import os from "node:os"; | |
| 17 | +import path from "node:path"; | |
| 18 | + | |
| 19 | +import { isInHomeDirectory } from "./isInHomeDirectory.js"; | |
| 20 | + | |
| 21 | +describe("isInHomeDirectory", () => { | |
| 22 | + const originalCwd = process.cwd; | |
| 23 | + const originalPlatform = process.platform; | |
| 24 | + | |
| 25 | + beforeEach(() => { | |
| 26 | + vi.clearAllMocks(); | |
| 27 | + process.cwd = vi.fn(); | |
| 28 | + }); | |
| 29 | + | |
| 30 | + afterEach(() => { | |
| 31 | + process.cwd = originalCwd; | |
| 32 | + Object.defineProperty(process, "platform", { | |
| 33 | + value: originalPlatform, | |
| 34 | + writable: true, | |
| 35 | + }); | |
| 36 | + }); | |
| 37 | + | |
| 38 | + it("should return true when current directory is home directory on Unix", () => { | |
| 39 | + Object.defineProperty(process, "platform", { | |
| 40 | + value: "linux", | |
| 41 | + writable: true, | |
| 42 | + }); | |
| 43 | + | |
| 44 | + const mockCwd = "/home/user"; | |
| 45 | + const mockHome = "/home/user"; | |
| 46 | + | |
| 47 | + vi.mocked(process.cwd).mockReturnValue(mockCwd); | |
| 48 | + vi.mocked(os.homedir).mockReturnValue(mockHome); | |
| 49 | + vi.mocked(path.resolve).mockImplementation((p: string) => p); | |
| 50 | + | |
| 51 | + expect(isInHomeDirectory()).toBe(true); | |
| 52 | + }); | |
| 53 | + | |
| 54 | + it("should return false when current directory is not home directory on Unix", () => { | |
| 55 | + Object.defineProperty(process, "platform", { | |
| 56 | + value: "linux", | |
| 57 | + writable: true, | |
| 58 | + }); | |
| 59 | + | |
| 60 | + const mockCwd = "/home/user/projects"; | |
| 61 | + const mockHome = "/home/user"; | |
| 62 | + | |
| 63 | + vi.mocked(process.cwd).mockReturnValue(mockCwd); | |
| 64 | + vi.mocked(os.homedir).mockReturnValue(mockHome); | |
| 65 | + vi.mocked(path.resolve).mockImplementation((p: string) => p); | |
| 66 | + | |
| 67 | + expect(isInHomeDirectory()).toBe(false); | |
| 68 | + }); | |
| 69 | + | |
| 70 | + it("should return true when current directory is home directory on Windows (case insensitive)", () => { | |
| 71 | + Object.defineProperty(process, "platform", { | |
| 72 | + value: "win32", | |
| 73 | + writable: true, | |
| 74 | + }); | |
| 75 | + | |
| 76 | + const mockCwd = "C:\\Users\\User"; | |
| 77 | + const mockHome = "c:\\users\\user"; | |
| 78 | + | |
| 79 | + vi.mocked(process.cwd).mockReturnValue(mockCwd); | |
| 80 | + vi.mocked(os.homedir).mockReturnValue(mockHome); | |
| 81 | + vi.mocked(path.resolve).mockImplementation((p: string) => p); | |
| 82 | + | |
| 83 | + expect(isInHomeDirectory()).toBe(true); | |
| 84 | + }); | |
| 85 | +}); |
added extensions/cli/src/util/isInHomeDirectory.ts +13 −0
| @@ -0,0 +1,13 @@ | ||
| 1 | +import os from "node:os"; | |
| 2 | +import path from "node:path"; | |
| 3 | + | |
| 4 | +export function isInHomeDirectory(): boolean { | |
| 5 | + const cwd = process.cwd(); | |
| 6 | + const homedir = os.homedir(); | |
| 7 | + const resolvedCwd = path.resolve(cwd); | |
| 8 | + const resolvedHome = path.resolve(homedir); | |
| 9 | + if (process.platform === "win32") { | |
| 10 | + return resolvedCwd.toLowerCase() === resolvedHome.toLowerCase(); | |
| 11 | + } | |
| 12 | + return resolvedCwd === resolvedHome; | |
| 13 | +} |