init.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env python3
  2. # .aceflow/scripts/init.py
  3. """
  4. AceFlow 初始化脚本
  5. 用于创建新的迭代环境。
  6. """
  7. import os
  8. import json
  9. import sys
  10. from datetime import datetime
  11. from pathlib import Path
  12. # --- 配置 ---
  13. BASE_RESULT_DIR = "aceflow_result"
  14. ACEFLOW_DIR = ".aceflow"
  15. STAGE_DIRS = [
  16. "S1_user_story", "S2_tasks", "S3_testcases", "S4_implementation",
  17. "S5_test_report", "S6_codereview", "S7_demo", "S7_feedback", "S8_summary"
  18. ]
  19. TEMPLATE_FILES = {
  20. "s1_user_story.md": "# 用户故事:{storyTitle}\n\n作为一名[角色],我希望[功能],以便[价值]。\n\n## 验收标准\n- [ ] 标准一\n- [ ] 标准二",
  21. "s2_tasks_main.md": "# 任务清单总览\n\n| 任务ID | 故事ID | 描述 | 类型 | 预估工时 | 优先级 |\n|---|---|---|---|---|---|",
  22. "s2_tasks_group.md": "# 分组任务清单: {groupName}\n\n| 任务ID | 描述 | 预估工时 | 优先级 |\n|---|---|---|---|",
  23. "s3_testcases.md": "# 测试用例: {caseTitle}\n\n- **关联故事**: US-{storyId}\n- **测试步骤**:\n 1. ...\n 2. ...\n- **预期结果**: ...",
  24. "s4_implementation_report.md": "# 任务实现报告: {taskId}\n\n- **实现概述**: ...\n- **文件变更**: ...",
  25. "s5_test_report.md": "# 测试报告: {taskId}\n\n- **通过率**: ...%\n- **覆盖率**: ...%\n- **失败项**: ...",
  26. "s6_code_review.md": "# 代码评审报告\n\n| ID | 文件 | 行号 | 问题描述 | 修复建议 |\n|---|---|---|---|---|",
  27. "s7_demo_script.md": "# 功能演示脚本\n\n## 场景1: ...\n\n- **步骤**: ...\n- **预期**: ...",
  28. "s8_summary_report.md": "# 迭代总结报告: {iterationId}\n\n## 完成情况\n...\n\n## 经验教训\n...",
  29. "s8_learning_summary.md": "# 经验教训总结\n\n## 做的好的\n- ...\n\n## 需要改进的\n- ..."
  30. }
  31. # --- 核心函数 ---
  32. def create_directory_structure(iteration_id: str):
  33. """创建迭代目录结构"""
  34. base_path = Path(BASE_RESULT_DIR) / iteration_id
  35. for dir_name in STAGE_DIRS:
  36. dir_path = base_path / dir_name
  37. dir_path.mkdir(parents=True, exist_ok=True)
  38. (dir_path / "README.md").write_text(f"# {dir_name}\n\n此目录用于存放{dir_name}阶段的产出物。\n", encoding='utf-8')
  39. print(f"✅ 创建迭代目录结构: {base_path}")
  40. def initialize_state(iteration_id: str):
  41. """初始化状态文件"""
  42. state = {
  43. "iteration_id": iteration_id,
  44. "current_stage": "S1",
  45. "status": "not_started",
  46. "progress": 0,
  47. "created_at": datetime.now().isoformat(),
  48. "updated_at": datetime.now().isoformat(),
  49. "memory_refs": [],
  50. "completed_stages": [],
  51. "current_task": None,
  52. "metrics": {
  53. "total_tasks": 0,
  54. "completed_tasks": 0,
  55. "failed_tests": 0,
  56. "code_coverage": 0
  57. }
  58. }
  59. state_path = Path(ACEFLOW_DIR) / "state.json"
  60. state_path.parent.mkdir(exist_ok=True)
  61. state_path.write_text(json.dumps(state, indent=2, ensure_ascii=False), encoding='utf-8')
  62. print(f"✅ 初始化状态文件: {state_path}")
  63. def create_config_template():
  64. """创建配置文件模板"""
  65. config_path = Path(ACEFLOW_DIR) / "config.yaml"
  66. if config_path.exists():
  67. print(f"ℹ️ 配置文件已存在: {config_path}")
  68. return
  69. config_content = """# AceFlow 项目配置文件
  70. project:
  71. name: "新项目"
  72. version: "0.1.0"
  73. tech_stack:
  74. language: "python"
  75. framework: "fastapi"
  76. execution:
  77. max_task_hours: 8
  78. min_test_coverage: 80
  79. task_organization:
  80. auto_split_threshold: 10
  81. group_by: ["story", "type"]
  82. """
  83. config_path.write_text(config_content, encoding='utf-8')
  84. print(f"✅ 创建配置文件模板: {config_path}")
  85. def create_templates():
  86. """创建模板文件"""
  87. template_dir = Path(ACEFLOW_DIR) / "templates"
  88. template_dir.mkdir(exist_ok=True)
  89. for filename, content in TEMPLATE_FILES.items():
  90. (template_dir / filename).write_text(content, encoding='utf-8')
  91. print(f"✅ 创建所有报告模板于: {template_dir}")
  92. def create_essential_dirs():
  93. """创建其他必要的目录"""
  94. dirs = ["memory", "logs"]
  95. for d in dirs:
  96. (Path(ACEFLOW_DIR) / d).mkdir(exist_ok=True)
  97. print(f"✅ 创建 memory 和 logs 目录。")
  98. # --- 主程序 ---
  99. def main():
  100. """主函数"""
  101. if len(sys.argv) > 1:
  102. iteration_id = sys.argv[1]
  103. else:
  104. iteration_id = f"iteration_{datetime.now().strftime('%Y%m%d_%H%M')}"
  105. print(f"\n🚀 初始化 AceFlow 迭代: {iteration_id}\n")
  106. create_directory_structure(iteration_id)
  107. initialize_state(iteration_id)
  108. create_config_template()
  109. create_templates()
  110. create_essential_dirs()
  111. print("\n✅ 初始化完成!")
  112. print("\n下一步:")
  113. print("1. 编辑 .aceflow/config.yaml 配置项目信息。")
  114. print("2. 在VSCode中使用Code Agent开始S1阶段。")
  115. if __name__ == "__main__":
  116. main()