1"""Project analysis utilities.

2

3 This module provides project structure and context analysis functions.

4 Extracted to break circular dependencies between server_core and quality_engine.

5"""

6

7 from __future__ import annotations

8

9 from typing import TYPE_CHECKING

10

11 if TYPE_CHECKING:

12 from pathlib import Path

13

14

15 async def analyze_project_context(project_dir: Path) -> dict[str, bool]:

16 """Analyze project structure and context with enhanced error handling.

17

18 Args:

19 project_dir: Path to the project directory to analyze

20

21 Returns:

22 Dictionary with boolean flags for various project characteristics:

23 - python_project: Has pyproject.toml

24 - git_repo: Has .git directory

25 - has_tests: Has test files or directories

26 - has_docs: Has README.md or docs directory

27 - has_requirements: Has requirements.txt

28 - has_uv_lock: Has uv.lock file

29 - has_mcp_config: Has .mcp.json file

30

31 """

32 try:

33 # Ensure project_dir exists and is accessible

34 if not project_dir.exists():

35 return {

36 "python_project": False,

37 "git_repo": False,

38 "has_tests": False,

39 "has_docs": False,

40 "has_requirements": False,

41 "has_uv_lock": False,

42 "has_mcp_config": False,

43 }

44

45 return {

46 "python_project": (project_dir / "pyproject.toml").exists(),

47 "git_repo": (project_dir / ".git").exists(),

48 "has_tests": any(project_dir.glob("test*"))

49 or any(project_dir.glob("**/test*")),

50 "has_docs": (project_dir / "README.md").exists()

51 or any(project_dir.glob("docs/**")),

52 "has_requirements": (project_dir / "requirements.txt").exists(),

53 "has_uv_lock": (project_dir / "uv.lock").exists(),

54 "has_mcp_config": (project_dir / ".mcp.json").exists(),

55 }

56 except (OSError, PermissionError):

57 # Return safe defaults on error

58 return {

59 "python_project": False,

60 "git_repo": False,

61 "has_tests": False,

62 "has_docs": False,

63 "has_requirements": False,

64 "has_uv_lock": False,

65 "has_mcp_config": False,

66 }