Coverage for src / moai_adk / cli / commands / status.py: 22.50%

40 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-11-20 20:52 +0900

1"""MoAI-ADK status command 

2 

3Project status display: 

4- Read project information from config.json 

5- Show the number of SPEC documents 

6- Summarize the Git status 

7 

8## Skill Invocation Guide (English-Only) 

9 

10### Related Skills 

11 

12- **moai-foundation-trust**: For comprehensive TRUST 4-principles verification 

13 - Trigger: After status shows SPECs exist, to validate code quality 

14 - Invocation: `Skill("moai-foundation-trust")` to verify all quality gates 

15 

16- **moai-foundation-git**: For detailed Git workflow information 

17 - Trigger: When Git status shows "Modified" and you need workflow guidance 

18 - Invocation: `Skill("moai-foundation-git")` for GitFlow automation details 

19 

20### When to Invoke Skills in Related Workflows 

211. **Before starting new SPEC creation**: 

22 - Check the SPEC count from status command 

23 

242. **After modifications to code/docs**: 

25 - If status shows "Modified", run `Skill("moai-foundation-git")` for commit strategy 

26 - Follow up with `Skill("moai-foundation-trust")` to validate code quality 

27 

283. **Periodic health checks**: 

29 - Run status command regularly 

30 - When SPEC count grows, verify with `Skill("moai-foundation-trust")` 

31""" 

32 

33import json 

34from pathlib import Path 

35 

36import click 

37from rich.console import Console 

38from rich.panel import Panel 

39from rich.table import Table 

40 

41console = Console() 

42 

43 

44@click.command() 

45def status() -> None: 

46 """Show current project status 

47 

48 Displays: 

49 - Project mode (personal/team) 

50 - Locale setting 

51 - Number of SPEC documents 

52 - Git branch and status 

53 """ 

54 try: 

55 # Read config.json 

56 config_path = Path.cwd() / ".moai" / "config" / "config.json" 

57 if not config_path.exists(): 

58 console.print("[yellow]⚠ No .moai/config/config.json found[/yellow]") 

59 console.print( 

60 "[dim]Run [cyan]python -m moai_adk init .[/cyan] to initialize the project[/dim]" 

61 ) 

62 raise click.Abort() 

63 

64 with open(config_path) as f: 

65 config = json.load(f) 

66 

67 # Count SPEC documents 

68 specs_dir = Path.cwd() / ".moai" / "specs" 

69 spec_count = ( 

70 len(list(specs_dir.glob("SPEC-*/spec.md"))) if specs_dir.exists() else 0 

71 ) 

72 

73 # Build the status table 

74 table = Table(show_header=False, box=None, padding=(0, 2)) 

75 table.add_column("Key", style="cyan") 

76 table.add_column("Value", style="bold") 

77 

78 # Read from project section (with legacy fallback) 

79 project = config.get("project", {}) 

80 table.add_row("Mode", project.get("mode") or config.get("mode", "unknown")) 

81 table.add_row( 

82 "Locale", project.get("locale") or config.get("locale", "unknown") 

83 ) 

84 table.add_row("SPECs", str(spec_count)) 

85 

86 # Optionally include Git information 

87 try: 

88 from git import Repo 

89 

90 repo = Repo(Path.cwd()) 

91 table.add_row("Branch", repo.active_branch.name) 

92 table.add_row("Git Status", "Clean" if not repo.is_dirty() else "Modified") 

93 except Exception: 

94 pass 

95 

96 # Render as a panel 

97 panel = Panel( 

98 table, 

99 title="[bold]Project Status[/bold]", 

100 border_style="cyan", 

101 expand=False, 

102 ) 

103 

104 console.print(panel) 

105 

106 except click.Abort: 

107 raise 

108 except Exception as e: 

109 console.print(f"[red]✗ Failed to get status: {e}[/red]") 

110 raise