第6篇:高级篇——自定义Workflow:封装你的规范OpenSpecSkills+Superpowers+Karpathy
打造属于你自己的AI开发流程
6.1 Workflow是什么?
在Antigravity中,Workflow是Skills的有序组合。
- Skill:单个能力(如写测试、代码审查)
- Workflow:多个Skill按顺序执行(如上5阶段流程)
Workflow定义在.agent/workflows/*.md文件中,Antigravity自动识别并注册为可调用的命令。
6.2 Workflow文件结构
一个完整的Workflow文件包含:
markdown
---
description: Workflow的简短描述
---
Workflow的详细说明
## Steps
### 1. 第一步名称
具体操作...
### 2. 第二步名称
具体操作...
6.3 完整版opsx-apply.md
这是我们今天改造的完整版本:
markdown
---
description: Implement tasks from an OpenSpec change with Karpathy principles + Superpowers TDD
---
Implement tasks from an OpenSpec change, automatically applying Karpathy coding principles and Superpowers development workflow.
## Steps
### 1. Select the change
If a name is provided, use it. Otherwise infer from context.
### 2. Check status
```bash
openspec status --change "<name>" --json
3. Get apply instructions
bash
openspec instructions apply --change "<name>" --json
4. Read context files
Read every file path listed under contextFiles.
5. Show current progress
Display progress and remaining tasks.
6. Implement tasks with 5-phase workflow
For each pending task:
Phase 0: Task Announcement
text
## 📋 Task N/M: <description>
Phase 1: Karpathy - Think Before Coding
Output:
text
【理解】...
【假设】...
【边界】...
【待确认】...
If 【待确认】 non-empty: PAUSE and wait.
Phase 2: Superpowers TDD (RED)
- Write failing test
- Run
pytestto confirm failure - Output:
🔴 RED: Test failed as expected
Phase 3: Minimal Implementation (GREEN)
- Write minimal code
- Run
pytestto confirm pass - Enforce: ≤50 lines, no abstraction
- Output:
🟢 GREEN: Implementation complete
Phase 4: Code Review
Check Karpathy 4 principles:
- Principle 1: Design documented?
- Principle 2: ≤50 lines?
- Principle 3: ≤3 files modified?
- Principle 4: Tests passed?
If FAIL: Return to Phase 3
Phase 5: Mark Complete
Update tasks.md: - [ ] → - [x]
Output: ✅ Task complete
7. On completion or pause, show status
If all done: suggest /opsx:archive
If paused: explain why and wait
text
## 6.4 如何自定义Workflow
### 场景1:添加“安全检查”阶段
在Phase 2之前插入:
```markdown
#### Phase 1.5: Security Check
**Check for:**
- Hardcoded secrets/API keys
- SQL injection risks
- Command injection vulnerabilities
**If found:** PAUSE and report
场景2:添加“性能评估”阶段
在Phase 4之后插入:
markdown
#### Phase 4.5: Performance Assessment
**For functions with loops or I/O:**
- Estimate time complexity
- Check for N+1 queries
- Suggest optimization if needed
**Output:**
⚡ Performance: O(n), acceptable for expected data size (<1000)
text
场景3:集成代码格式化
在Phase 5之前插入:
markdown
#### Phase 4.6: Format Code
```bash
black src/
isort src/
Requirement: Only format modified files, not entire project
text
## 6.5 Workflow调试技巧
### 查看注册的Workflows
在Antigravity中执行:
/list workflows
text
### 测试单个阶段
创建测试workflow `test-phase1.md`:
```markdown
---
description: Test Phase 1 only
---
## Steps
### 1. Test Karpathy thinking
Output your understanding of the current task, but do NOT proceed to implementation.
常见问题
| 问题 | 解决方案 |
|---|---|
| Workflow不被识别 | 检查frontmatter格式、文件位置、重启IDE |
| 阶段跳过 | 检查条件判断逻辑 |
| Skill调用失败 | 检查软链接路径 |
6.6 今天对话中的干货
Workflow vs 普通Prompt
问:为什么不直接在对话中说“按照5阶段执行”?
答:普通Prompt每次都要重复,Workflow封装后可复用、可共享、可版本控制。团队可以统一使用同一个Workflow文件。
Workflow的扩展性
问:能否创建非OpenSpec的Workflow?
答:可以。任何重复性任务都可以封装成Workflow。例如:
code-review.md:代码审查流程deploy-check.md:部署前检查清单docs-generate.md:文档生成流程
核心洞见
“Workflow的本质是把‘最佳实践’变成‘可执行的代码’。”——不是每次都要回想“该先做什么再做什么”,而是直接调用一个命令。这是Vibe Coding从“手工作坊”到“自动化流水线”的关键一步。