diff --git a/.planning/ROADMAP.md b/.planning/ROADMAP.md index c819861..7796a95 100644 --- a/.planning/ROADMAP.md +++ b/.planning/ROADMAP.md @@ -261,7 +261,9 @@ | 8 | ✓ Completed | 1/1 | 1/1 | | 9 | ✓ Completed | 1/1 | 1/1 | | 10 | ✓ Completed | 1/1 | 1/1 | -| 11 | Not Started | 0/1 | 0/1 | +| 11 | ✓ Completed | 1/1 | 1/1 | + +**Status: MILESTONE COMPLETE ✓** --- *Last updated: 2026-03-09* diff --git a/.planning/STATE.md b/.planning/STATE.md index 2c05779..4f19af6 100644 --- a/.planning/STATE.md +++ b/.planning/STATE.md @@ -1,10 +1,12 @@ --- -phase: 10 +phase: 11 stage: completed milestone: v1.0 started: 2026-03-09T18:52:00+08:00 -updated: 2026-03-09T19:10:00+08:00 +updated: 2026-03-09T19:15:00+08:00 +completed: 2026-03-09T19:15:00+08:00 retry_count: 0 +status: milestone_complete --- # dev-workflow - State diff --git a/README.md b/README.md index 1047262..5e84803 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,12 @@ OpenClaw 知识库工作流技能集合,用于内容采集、处理与分析 | [kb-deep-analyzer](kb-deep-analyzer/) | AI 驱动深度内容分析 | | [kb-workflow](kb-workflow/) | 知识库工作流编排(入口技能) | +### 🚀 开发类 + +| 技能 | 描述 | +|------|------| +| [dev-workflow](dev-workflow/) | 多代理协作开发编排,9阶段流程解决单Agent开发问题 | + ## 快速开始 每个技能目录下都有 `SKILL.md` 说明文档,包含: diff --git a/dev-workflow/INTEGRATION_TEST.md b/dev-workflow/INTEGRATION_TEST.md new file mode 100644 index 0000000..da62280 --- /dev/null +++ b/dev-workflow/INTEGRATION_TEST.md @@ -0,0 +1,198 @@ +# dev-workflow 集成测试指南 + +## 测试场景 + +### 场景1: 开发简单CLI工具(通用项目) + +**目标**: 使用 dev-workflow 开发一个简单的待办事项CLI工具 + +**测试步骤**: + +```bash +# 1. 初始化工作流 +cd ~/work/kb-skills/dev-workflow +python3 orchestrator.py --init "开始开发一个简单的待办事项CLI工具,支持添加、列出、完成任务" --project-name "todo-cli" + +# 2. 模拟头脑风暴(Phase 1) +# 主Agent应进入问答循环,收集需求 + +# 3. 方案设计(Phase 2) +# 应启动3个子代理设计方案 + +# 4-9. 后续阶段 +# 按流程完成各阶段 +``` + +**验收标准**: +- [ ] 生成可运行的 todo.py +- [ ] 支持 add/list/done 命令 +- [ ] 有单元测试 +- [ ] 代码通过审查 + +--- + +### 场景2: 开发新kb-skill(技能项目) + +**目标**: 使用 dev-workflow 开发一个简单的 kb-hello 技能 + +**测试步骤**: + +```bash +# 1. 初始化工作流 +cd ~/work/kb-skills +python3 dev-workflow/orchestrator.py --init "开始开发一个新的kb-skill,名称为kb-hello,功能是向用户问好" --project-name "kb-hello" + +# 2-9. 按流程完成 +``` + +**验收标准**: +- [ ] 创建 kb-hello/SKILL.md +- [ ] SKILL.md 符合规范 +- [ ] 有示例使用说明 +- [ ] 文档完整 + +--- + +## 快速验证脚本 + +```bash +#!/bin/bash +# quick_test.sh - 快速验证dev-workflow基本功能 + +set -e + +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " DEV-WORKFLOW 快速验证" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + +# 1. 检查文件结构 +echo "" +echo "1. 检查文件结构..." +required_files=( + "SKILL.md" + "state_manager.py" + "orchestrator.py" + "prompts/brainstorming.md" + "prompts/solution-design.md" + "prompts/solution-review.md" + "prompts/solution-report.md" + "prompts/spec-planning.md" + "prompts/parallel-development.md" + "prompts/testing.md" + "prompts/code-review.md" + "prompts/fix-verification.md" +) + +all_found=true +for file in "${required_files[@]}"; do + if [ -f "$file" ]; then + echo " ✓ $file" + else + echo " ✗ $file (缺失)" + all_found=false + fi +done + +if [ "$all_found" = false ]; then + echo "❌ 文件检查失败" + exit 1 +fi + +# 2. 运行单元测试 +echo "" +echo "2. 运行单元测试..." +python3 test_dev_workflow.py + +# 3. 测试状态管理 +echo "" +echo "3. 测试状态管理..." +python3 -c " +from state_manager import init_state, load_state, set_phase, complete_phase + +# 初始化 +state = init_state('测试项目', '测试消息') +print(f' ✓ 初始化状态: Phase {state[\"current_phase\"]}') + +# 设置阶段 +set_phase(3) +state = load_state() +print(f' ✓ 设置阶段: Phase {state[\"current_phase\"]}') + +# 完成阶段 +complete_phase(3) +state = load_state() +print(f' ✓ 完成阶段: Phase 3, 当前 Phase {state[\"current_phase\"]}') +" + +# 4. 测试编排器 +echo "" +echo "4. 测试编排器..." +python3 -c " +from orchestrator import DevWorkflowOrchestrator +import tempfile +import os + +with tempfile.TemporaryDirectory() as tmpdir: + os.chdir(tmpdir) + + orch = DevWorkflowOrchestrator() + orch.initialize('测试消息', '测试项目') + print(' ✓ 编排器初始化成功') + + # 检查阶段方法 + for i in range(1, 10): + method = f'run_phase_{i}' + if hasattr(orch, method): + print(f' ✓ {method} 存在') + else: + print(f' ✗ {method} 缺失') +" + +echo "" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " ✅ 快速验证通过" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +``` + +--- + +## 手动测试清单 + +### 基础功能 + +- [ ] SKILL.md 触发词正确定义 +- [ ] 状态文件正确初始化 +- [ ] 阶段转换正确工作 +- [ ] 重试逻辑正确(最多3次) +- [ ] 状态恢复正确工作 + +### Prompt模板 + +- [ ] 头脑风暴prompt包含问答策略 +- [ ] 方案设计prompt包含3种类型 +- [ ] 方案审核prompt包含交叉审核逻辑 +- [ ] Spec编排prompt包含依赖分析 +- [ ] 代码审查prompt包含完整维度 + +### 子代理集成 + +- [ ] 可以启动子代理(sessions_spawn) +- [ ] 子代理结果正确收集 +- [ ] 并行执行正确工作 +- [ ] 失败重试正确触发 + +--- + +## 已知限制 + +1. **子代理集成**: 当前代码提供了子代理启动框架,但实际需要与 OpenClaw sessions_spawn 集成 +2. **实际执行**: 完整的9阶段流程需要实际运行环境 +3. **测试覆盖**: 单元测试覆盖了核心逻辑,端到端测试需要手动执行 + +--- + +## 下一步 + +1. **实际测试**: 在真实项目中使用 dev-workflow +2. **优化prompt**: 根据实际效果调整各阶段prompt +3. **收集反馈**: 记录使用中的问题和改进点 diff --git a/dev-workflow/quick_test.sh b/dev-workflow/quick_test.sh new file mode 100755 index 0000000..af97b09 --- /dev/null +++ b/dev-workflow/quick_test.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# quick_test.sh - 快速验证dev-workflow基本功能 + +set -e + +cd "$(dirname "$0")" + +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " DEV-WORKFLOW 快速验证" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + +# 1. 检查核心文件 +echo "" +echo "1. 检查核心文件..." +core_files=( + "SKILL.md" + "state_manager.py" + "orchestrator.py" + "test_dev_workflow.py" +) + +for file in "${core_files[@]}"; do + if [ -f "$file" ]; then + echo " ✓ $file" + else + echo " ✗ $file (缺失)" + exit 1 + fi +done + +# 2. 检查prompt模板 +echo "" +echo "2. 检查prompt模板..." +prompt_files=$(ls prompts/*.md 2>/dev/null | wc -l) +if [ "$prompt_files" -ge 9 ]; then + echo " ✓ 找到 $prompt_files 个prompt模板" + ls prompts/*.md | while read f; do echo " - $(basename $f)"; done +else + echo " ✗ prompt模板数量不足: $prompt_files < 9" + exit 1 +fi + +# 3. 运行单元测试 +echo "" +echo "3. 运行单元测试..." +python3 test_dev_workflow.py 2>&1 | tail -5 + +# 4. 检查SKILL.md内容 +echo "" +echo "4. 检查SKILL.md内容..." +if grep -q "name: dev-workflow" SKILL.md; then + echo " ✓ 技能名称正确" +else + echo " ✗ 技能名称错误" +fi + +if grep -q "开始开发" SKILL.md; then + echo " ✓ 触发词正确" +else + echo " ✗ 触发词错误" +fi + +echo "" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " ✅ 快速验证通过" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" diff --git a/dev-workflow/test_dev_workflow.py b/dev-workflow/test_dev_workflow.py new file mode 100644 index 0000000..3abf1c1 --- /dev/null +++ b/dev-workflow/test_dev_workflow.py @@ -0,0 +1,189 @@ +#!/usr/bin/env python3 +""" +dev-workflow 单元测试 + +测试状态管理和编排器的基本功能。 +""" + +import json +import os +import sys +import tempfile +import unittest +from pathlib import Path + +# 添加模块路径 +sys.path.insert(0, str(Path(__file__).parent)) + +from state_manager import ( + init_state, + load_state, + save_state, + set_phase, + complete_phase, + update_phase_data, + increment_retry, + reset_retry +) + + +class TestStateManager(unittest.TestCase): + """测试状态管理器""" + + def setUp(self): + """设置测试环境""" + self.temp_dir = tempfile.mkdtemp() + self.state_file = Path(self.temp_dir) / ".planning" / "dev-workflow" / "state.json" + self.state_file.parent.mkdir(parents=True, exist_ok=True) + + # 切换到临时目录 + self.original_cwd = os.getcwd() + os.chdir(self.temp_dir) + + def tearDown(self): + """清理测试环境""" + os.chdir(self.original_cwd) + import shutil + shutil.rmtree(self.temp_dir) + + def test_init_state(self): + """测试初始化状态""" + state = init_state( + project_name="测试项目", + trigger_message="开始开发测试功能" + ) + + self.assertEqual(state["project_name"], "测试项目") + self.assertEqual(state["current_phase"], 1) + self.assertEqual(state["current_stage"], "头脑风暴") + self.assertEqual(state["phases"]["1"]["status"], "in_progress") + self.assertIn("trigger_message", state["context"]) + + def test_set_phase(self): + """测试设置阶段""" + init_state("测试项目", "测试") + + set_phase(3) + state = load_state() + + self.assertEqual(state["current_phase"], 3) + self.assertEqual(state["current_stage"], "方案审核") + self.assertEqual(state["phases"]["3"]["status"], "in_progress") + self.assertEqual(state["phases"]["1"]["status"], "completed") + + def test_complete_phase(self): + """测试完成阶段""" + init_state("测试项目", "测试") + + complete_phase(1) + state = load_state() + + self.assertEqual(state["phases"]["1"]["status"], "completed") + self.assertIn("completed_at", state["phases"]["1"]) + self.assertEqual(state["current_phase"], 2) + + def test_update_phase_data(self): + """测试更新阶段数据""" + init_state("测试项目", "测试") + + update_phase_data(1, {"questions_asked": 5, "collected": True}) + state = load_state() + + self.assertEqual(state["phases"]["1"]["data"]["questions_asked"], 5) + self.assertEqual(state["phases"]["1"]["data"]["collected"], True) + + def test_retry_logic(self): + """测试重试逻辑""" + init_state("测试项目", "测试") + + # 第一次重试 + can_retry = increment_retry() + self.assertTrue(can_retry) + state = load_state() + self.assertEqual(state["retry_count"], 1) + + # 重置 + reset_retry() + state = load_state() + self.assertEqual(state["retry_count"], 0) + + def test_max_retries(self): + """测试最大重试次数""" + init_state("测试项目", "测试") + + # 连续重试 + for i in range(3): + can_retry = increment_retry() + if i < 2: + self.assertTrue(can_retry) + else: + self.assertFalse(can_retry) + + +class TestOrchestrator(unittest.TestCase): + """测试编排器""" + + def setUp(self): + """设置测试环境""" + self.temp_dir = tempfile.mkdtemp() + self.original_cwd = os.getcwd() + os.chdir(self.temp_dir) + + def tearDown(self): + """清理测试环境""" + os.chdir(self.original_cwd) + import shutil + shutil.rmtree(self.temp_dir) + + def test_orchestrator_init(self): + """测试编排器初始化""" + from orchestrator import DevWorkflowOrchestrator + + orchestrator = DevWorkflowOrchestrator() + orchestrator.initialize("开始开发测试功能", "测试项目") + + # 检查目录结构 + planning_dir = Path(".planning/dev-workflow") + self.assertTrue(planning_dir.exists()) + self.assertTrue((planning_dir / "solutions").exists()) + self.assertTrue((planning_dir / "reviews").exists()) + self.assertTrue((planning_dir / "development").exists()) + self.assertTrue((planning_dir / "code-review").exists()) + + def test_phase_transitions(self): + """测试阶段转换""" + from orchestrator import DevWorkflowOrchestrator + + orchestrator = DevWorkflowOrchestrator() + orchestrator.initialize("开始开发测试功能", "测试项目") + + # 测试各阶段方法存在 + self.assertTrue(hasattr(orchestrator, 'run_phase_1')) + self.assertTrue(hasattr(orchestrator, 'run_phase_2')) + self.assertTrue(hasattr(orchestrator, 'run_phase_9')) + + +class TestSKILLDocumentation(unittest.TestCase): + """测试SKILL.md文档""" + + def test_skill_md_exists(self): + """测试SKILL.md存在""" + skill_md = Path(__file__).parent / "SKILL.md" + self.assertTrue(skill_md.exists(), "SKILL.md should exist") + + def test_skill_md_content(self): + """测试SKILL.md内容""" + skill_md = Path(__file__).parent / "SKILL.md" + content = skill_md.read_text() + + # 检查必要内容 + self.assertIn("name: dev-workflow", content) + self.assertIn("开始开发", content) + self.assertIn("9阶段", content) + self.assertIn("头脑风暴", content) + self.assertIn("方案设计", content) + self.assertIn("代码审查", content) + + +if __name__ == "__main__": + unittest.main(verbosity=2)