Loading...
Loading...
CX Workflow - Task Execution and Contract Validation. Triggered when users mention phrases such as "execute task", "start development", "implement feature", "write code", "continue working", "next task". It follows a 5-step process: Read Task → Implementation → Contract Validation → Testing → Submission. It uses local task-{n}.md and status.json files to automatically verify whether the implementation conforms to the contract. cx-summary will be automatically triggered after all tasks are completed.
npx skill4agent add m19803261706/cx-workflow cx-exec/cx-exec # 执行下一个待执行任务
/cx-exec #1 # 执行指定任务编号
/cx-exec 1-5 # 批量执行任务 1 到 5
/cx-exec --phase 1 # 执行 Phase 1 的所有任务
/cx-exec --all # 执行所有待执行任务(并行)PROJECT_ROOT=$(git rev-parse --show-toplevel)
DEVELOPER_ID=$(jq -r '.developer_id' "$PROJECT_ROOT/.claude/cx/config.json" 2>/dev/null || echo "cx")
CONFIG="$PROJECT_ROOT/.claude/cx/config.json"
FEATURE_DIR="$PROJECT_ROOT/.claude/cx/features/${DEVELOPER_ID}-{feature_slug}"# 读取本地状态
STATUS_FILE="$FEATURE_DIR/status.json"
TASK_NUMBER=$(jq -r '.tasks[] | select(.status == "pending") | .number' "$STATUS_FILE" | head -1)
# 读取任务详情
TASK_FILE="$FEATURE_DIR/tasks/task-${TASK_NUMBER}.md"depends_onin_progress[ -f pyproject.toml ] && uv run pytest
[ -f package.json ] && npm test
[ -f pom.xml ] && mvn test1. 接口路径一致性
比对:Controller @RequestMapping vs Task 中的契约路径
不一致 → 自动修正
2. DTO/VO 字段一致性
比对:DTO 类字段 vs Task 中的字段映射表
不一致 → 自动修正
3. 状态枚举一致性
比对:枚举类/常量 vs Task 中的状态枚举对照表
不一致 → 自动修正
4. 请求/响应结构一致性
比对:Controller 方法签名 vs Task 中的 Request/Response JSON
不一致 → 自动修正契约校验通过
接口路径: 3/3 一致
字段映射: 12/12 一致
状态枚举: 4/4 一致
→ 继续提交契约校验发现不一致,自动修正中...
❌ 接口路径: POST /api/v1/certifications → 实际为 /certification
→ 已修正 @PostMapping 路径
❌ 字段名: rejectReason → 实际为 rejectMsg
→ 已修正 DTO 字段名和前端 interface
❌ 状态枚举: REJECTED → 实际为 REJECT
→ 已修正前端枚举常量
修正完成,重新运行测试...契约校验失败,无法自动修正
问题: {具体问题}
建议: {修复建议}
需要人工介入git add {相关文件}
git commit -m "{type}({scope}): {description} (task #{task_number})"# 更新任务状态为 completed
jq ".tasks[] |= if .number == $TASK_NUMBER then .status = \"completed\" else . end" "$STATUS_FILE" > "$STATUS_FILE.tmp"
mv "$STATUS_FILE.tmp" "$STATUS_FILE"
# 解锁依赖该任务的 pending 任务
for dependent in $(jq -r ".tasks[] | select(.depends_on[]? == $TASK_NUMBER) | .number" "$STATUS_FILE"); do
jq ".tasks[] |= if .number == $dependent then .status = \"pending\" else . end" "$STATUS_FILE" > "$STATUS_FILE.tmp"
mv "$STATUS_FILE.tmp" "$STATUS_FILE"
doneTOTAL=$(jq '.tasks | length' "$STATUS_FILE")
COMPLETED=$(jq '[.tasks[] | select(.status == "completed")] | length' "$STATUS_FILE")
if [ "$COMPLETED" -eq "$TOTAL" ]; then
# === 所有任务完成,触发闭环 ===
echo "所有任务已完成,启动汇总..."
# 自动触发 cx-summary
# 如果 config.code_review = true,先启动代码审查流程
ficase "$ARGUMENTS" in
*-*)
# 范围: 1-5
RANGE=$(echo "$ARGUMENTS" | tr '-' ' ')
TARGETS=$(jq -r ".execution_order[] | select(. >= $START and . <= $END)" "$STATUS_FILE")
;;
--phase*)
# Phase: --phase 1
PHASE=$(echo "$ARGUMENTS" | grep -oE '[0-9]+')
TARGETS=$(jq -r ".phases[] | select(.number == $PHASE) | .tasks[]" "$STATUS_FILE")
;;
--all)
# 所有 pending 任务
TARGETS=$(jq -r '.tasks[] | select(.status == "pending") | .number' "$STATUS_FILE")
;;
esacparallel_groupparallel_group# 并行组 p1-a (task 1, 2 可并行)
Task agent: task-1.md → Step 1-5
Task agent: task-2.md → Step 1-5
↓ 全部完成后
# 并行组 p2-a (task 3, 4 可并行)
Task agent: task-3.md → Step 1-5
Task agent: task-4.md → Step 1-5
↓ 全部完成后
# 并行组 p3-a (task 5 串行)
Task agent: task-5.md → Step 1-5Task tool 参数:
subagent_type: "task-executor"
prompt: |
项目根目录: $PROJECT_ROOT
任务: $FEATURE_DIR/tasks/task-{n}.md
请按 5 步流程完成:
1. 读取 task-{n}.md 中的任务描述和 API 契约片段
2. 按契约实现代码(路径、字段、枚举一致)
3. 运行项目测试和检查
4. 执行契约校验(对比实现 vs task-{n}.md 中的契约)
5. 校验通过后 git add + commit
commit message 格式: {type}({scope}): {desc} (task #{n})任务执行遇到问题
错误: {具体错误}
已完成: {部分进度}
已恢复任务为 pending 状态,需要人工介入pending契约校验失败
不一致项:
{具体问题}
建议: 检查 Task 中的契约定义是否需要调整
或检查 Design Doc 中的相应章节任务 #103 依赖未满足
依赖: #101 (状态: pending)
建议: 先执行 /cx-exec #101execution_order当前进度:
功能: cx-payment
Phase 1: 2/2 completed
Phase 2: 1/3 in_progress (Task #103)
下一个: Task #104