Coverage for aceflow_mcp_server\core\template_manager.py: 93%

27 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2025-08-03 13:42 +0800

1"""Template Manager for AceFlow templates.""" 

2 

3from typing import Dict, Any, List 

4from pathlib import Path 

5import json 

6 

7 

8class TemplateManager: 

9 """Manages AceFlow templates.""" 

10 

11 def __init__(self): 

12 self.current_dir = Path.cwd() 

13 self.available_templates = ["minimal", "standard", "complete", "smart"] 

14 

15 def list_templates(self) -> Dict[str, Any]: 

16 """List available templates.""" 

17 return { 

18 "available": self.available_templates, 

19 "current": self.get_current_template() 

20 } 

21 

22 def get_current_template(self) -> str: 

23 """Get current template.""" 

24 # Check project state for current template 

25 state_file = self.current_dir / ".aceflow" / "current_state.json" 

26 if state_file.exists(): 

27 try: 

28 with open(state_file, 'r', encoding='utf-8') as f: 

29 state = json.load(f) 

30 return state.get("project", {}).get("mode", "unknown").lower() 

31 except: 

32 pass 

33 return "unknown" 

34 

35 def apply_template(self, template: str) -> Dict[str, Any]: 

36 """Apply a template.""" 

37 if template not in self.available_templates: 

38 raise ValueError(f"Template '{template}' not available") 

39 

40 # Mock implementation 

41 return { 

42 "template": template, 

43 "applied": True, 

44 "message": f"Template '{template}' applied successfully" 

45 } 

46 

47 def validate_current_template(self) -> Dict[str, Any]: 

48 """Validate current template.""" 

49 current = self.get_current_template() 

50 is_valid = current in self.available_templates 

51 

52 return { 

53 "template": current, 

54 "valid": is_valid, 

55 "message": "Template is valid" if is_valid else f"Template '{current}' is not recognized" 

56 }