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
« prev ^ index » next coverage.py v7.10.1, created at 2025-08-03 13:42 +0800
1"""Template Manager for AceFlow templates."""
3from typing import Dict, Any, List
4from pathlib import Path
5import json
8class TemplateManager:
9 """Manages AceFlow templates."""
11 def __init__(self):
12 self.current_dir = Path.cwd()
13 self.available_templates = ["minimal", "standard", "complete", "smart"]
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 }
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"
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")
40 # Mock implementation
41 return {
42 "template": template,
43 "applied": True,
44 "message": f"Template '{template}' applied successfully"
45 }
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
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 }