第十章:工作流程详解
本章详细介绍 OpenMatrix 的完整工作流程。
10.1 完整执行流程
graph TD
A[用户指令] --> B[初始化]
B --> C[任务规划]
C --> D[调度执行]
D --> E[质量验证]
E --> F[最终审查]
F --> G[完成交付]
10.2 端到端完整案例:用户认证系统
下面是一个从 /om:start 到最终报告的完整运行实录,展示 strict 模式下的全流程。
第 1 步:启动
$ /om:start
╔══════════════════════════════════════════════════════════════╗
║ OpenMatrix v0.1.98 ║
╠══════════════════════════════════════════════════════════════╣
║ ║
║ No existing state found. Starting fresh execution. ║
║ ║
║ Step 1/4: Select Quality Level ║
║ ║
║ > strict — Full TDD, >80% coverage, strict lint ║
║ balanced — No TDD, >60% coverage, standard lint ║
║ fast — No quality gates ║
║ ║
║ Your choice: strict ║
║ ║
║ Step 2/4: Select Execution Mode ║
║ ║
║ > semi-auto — Confirm critical points ║
║ interactive — Confirm every step ║
║ full-auto — No interruptions ║
║ ║
║ Your choice: semi-auto ║
║ ║
║ Step 3/4: Enable E2E Tests? ║
║ > No ║
║ ║
║ Step 4/4: Enter Task Instruction ║
║ ║
║ > 实现用户认证系统: ║
║ 1. 用户注册(邮箱 + 密码) ║
║ 2. 用户登录(JWT token,7天有效期) ║
║ 3. 密码使用 bcrypt 加密 ║
║ 4. 登录 API 响应时间 < 200ms ║
║ ║
╚══════════════════════════════════════════════════════════════╝
第 2 步:AI 分析与任务规划
╔══════════════════════════════════════════════════════════════╗
║ Task Planning ║
╠══════════════════════════════════════════════════════════════╣
║ ║
║ Analyzing project context... ║
║ - Framework: Express.js + TypeScript ║
║ - Test: Vitest ║
║ - Lint: ESLint ║
║ ║
║ Generated Task Plan: ║
║ ║
║ ┌──────────┬────────────────────────┬──────┬──────┬────┐ ║
║ │ ID │ Title │ Pri │ Deps │ Cx │ ║
║ ├──────────┼────────────────────────┼──────┼──────┼────┤ ║
║ │ TASK-001 │ Create User model │ 10 │ - │ L │ ║
║ │ TASK-002 │ Implement bcrypt util │ 9 │ - │ L │ ║
║ │ TASK-003 │ Implement auth API │ 8 │ 1,2 │ M │ ║
║ │ TASK-004 │ Add input validation │ 6 │ 1 │ L │ ║
║ │ TASK-005 │ Add auth middleware │ 7 │ 3 │ M │ ║
║ └──────────┴────────────────────────┴──────┴──────┴────┘ ║
║ ║
║ Pri = Priority (1-10) Deps = Dependencies Cx = Complexity║
║ ║
║ Approve this plan? [Y/n] Y ║
║ ║
╚══════════════════════════════════════════════════════════════╝
第 3 步:执行 TASK-001(TDD → Develop → Verify → Accept)
════════════════════════════════════════════════════════════════
TASK-001: Create User model [priority: 10]
Phase: TDD (RED) [agent: tester]
════════════════════════════════════════════════════════════════
Running Tester Agent...
Creating test file: tests/models/user.test.ts
Test cases written:
✓ "should create user with valid email"
✓ "should reject invalid email"
✓ "should hash password on create"
✓ "should validate password length >= 8"
✓ "should not store plain text password"
Running tests...
Tests: 5 failed (RED) ✓
Duration: 0.8s
TDD Phase PASSED — Tests are failing as expected (RED)
──────────────────────────────────────────────────────────────
Phase: Develop (GREEN) [agent: coder]
──────────────────────────────────────────────────────────────
Running Coder Agent...
Reading test files...
Analyzing test requirements...
Creating implementation: src/models/user.ts
Files created:
- src/models/user.ts (82 lines)
Running tests...
Tests: 5 passed (GREEN) ✓
Duration: 1.2s
Develop Phase PASSED — All tests passing (GREEN)
──────────────────────────────────────────────────────────────
Phase: Verify (Quality Gates) [agent: executor]
──────────────────────────────────────────────────────────────
Running quality gates (strict mode)...
[1/7] Build Check ✓ PASS (12.5s, 0 errors)
[2/7] Test Run ✓ PASS (3.5s, 5/5 passed)
[3/7] Coverage ✓ PASS (line: 92%, threshold: 80%)
[4/7] Lint ✓ PASS (0 errors, 1 warning)
[5/7] Security ✓ PASS (0 vulnerabilities)
[6/7] E2E ○ SKIP (not configured)
[7/7] Acceptance ✓ PASS (4/4 criteria met)
Quality Score: 92/100
Verify Phase PASSED — All quality gates passed
──────────────────────────────────────────────────────────────
Phase: Accept (AI Review) [agent: reviewer]
──────────────────────────────────────────────────────────────
Running Reviewer Agent...
Review Scores:
Code Quality: 9/10 (well-structured model)
Best Practices: 8/10 (proper encapsulation)
Security: 8/10 (bcrypt hashing)
Documentation: 7/10 (add JSDoc for public methods)
Overall Score: 8.0/10 — APPROVED ✓
Accept Phase PASSED
Git commit:
feat(TASK-001): Create User model with validation
- Define IUser interface with email, password fields
- Add bcrypt password hashing on create
- Add email and password validation
Impact scope: Models
Files changed: src/models/user.ts, tests/models/user.test.ts
Co-Authored-By: OpenMatrix https://github.com/bigfish1913/openmatrix
TASK-001 COMPLETED ✓
════════════════════════════════════════════════════════════════
第 4 步:执行 TASK-002(并行,无依赖)
════════════════════════════════════════════════════════════════
TASK-002: Implement bcrypt util [priority: 9]
Phase: TDD → Develop → Verify → Accept
════════════════════════════════════════════════════════════════
TDD: 3 tests written, 3 failing (RED) ✓
Develop: src/utils/crypto.ts created, 3 tests passing (GREEN) ✓
Verify: Build ✓, Test ✓, Coverage 95% ✓, Lint ✓, Security ✓
Accept: Score 8.5/10 — APPROVED ✓
Git commit: feat(TASK-002): Add bcrypt password utility
TASK-002 COMPLETED ✓
════════════════════════════════════════════════════════════════
第 5 步:执行 TASK-003(依赖 TASK-001 + TASK-002,遇到 Meeting)
════════════════════════════════════════════════════════════════
TASK-003: Implement auth API [priority: 8]
════════════════════════════════════════════════════════════════
TDD Phase...
Running Tester Agent...
Creating test file: tests/api/auth.test.ts
⚠ BLOCKED: Need to determine API structure
Meeting MEETING-001 created:
┌──────────────────────────────────────────────────────────┐
│ Type: decision │
│ Question: Which API structure to use? │
│ │
│ Options: │
│ 1. RESTful (/api/auth/register, /api/auth/login) │
│ 2. GraphQL (mutation { register }, mutation { login }) │
│ 3. tRPC (router procedure style) │
│ │
│ Impact: Affects all API design decisions │
└──────────────────────────────────────────────────────────┘
TASK-003 status → waiting
Continuing with other independent tasks...
════════════════════════════════════════════════════════════════
第 6 步:执行 TASK-004(独立任务,不依赖 TASK-003)
════════════════════════════════════════════════════════════════
TASK-004: Add input validation [priority: 6]
════════════════════════════════════════════════════════════════
TDD: 4 tests written (RED) ✓
Develop: src/utils/validators.ts created (GREEN) ✓
Verify: All gates passed ✓
Accept: Score 7.5/10 — APPROVED ✓
Git commit: feat(TASK-004): Add input validation utilities
TASK-004 COMPLETED ✓
════════════════════════════════════════════════════════════════
All independent tasks completed. 1 meeting pending.
$ /om:meeting
Meeting MEETING-001: Which API structure to use?
Your choice [1-3]: 1
Meeting resolved → TASK-003 status → scheduled
Resuming TASK-003 execution...
第 7 步:恢复 TASK-003 并完成
════════════════════════════════════════════════════════════════
TASK-003: Implement auth API [priority: 8]
════════════════════════════════════════════════════════════════
TDD: 8 tests written (RED) ✓
Develop: src/api/auth.ts, src/routes/auth.ts created ✓
Verify:
[1/7] Build ✓ PASS (15.2s)
[2/7] Test ✓ PASS (5.1s, 8/8 passed)
[3/7] Coverage ✓ PASS (line: 88%)
[4/7] Lint ✗ FAIL (2 errors)
Verify FAILED — Fixing lint errors...
Auto-fix applied:
- Removed unused variable 'temp' at auth.ts:45
- Added return type annotation at auth.ts:80
Re-running Verify...
[4/7] Lint ✓ PASS (0 errors)
[5/7] Security ✓ PASS
[7/7] Acceptance ✓ PASS (4/4 criteria)
Quality Score: 85/100
Accept: Score 7.5/10 — APPROVED ✓
Git commit: feat(TASK-003): Implement RESTful auth API
TASK-003 COMPLETED ✓
════════════════════════════════════════════════════════════════
第 8 步:执行 TASK-005(依赖 TASK-003)
════════════════════════════════════════════════════════════════
TASK-005: Add auth middleware [priority: 7]
════════════════════════════════════════════════════════════════
TDD: 5 tests written ✓
Develop: src/middleware/auth.ts created ✓
Verify: All gates passed, Coverage 91% ✓
Accept: Score 8.0/10 — APPROVED ✓
TASK-005 COMPLETED ✓
════════════════════════════════════════════════════════════════
最终报告
$ /om:report
╔══════════════════════════════════════════════════════════════╗
║ OpenMatrix Execution Report ║
║ Run ID: run-2024-04-06-001 ║
╠══════════════════════════════════════════════════════════════╣
║ ║
║ Configuration ║
║ Quality: strict Mode: semi-auto ║
║ Started: 2024-04-06 14:32:15 ║
║ Finished: 2024-04-06 16:45:22 ║
║ Duration: 2h 13m 7s ║
║ ║
║ Task Statistics ║
║ ┌──────────────────────────────────────┐ ║
║ │ Total Tasks 5 │ ║
║ │ Completed 5 (100%) │ ║
║ │ Failed 0 │ ║
║ │ Blocked 1 (resolved) │ ║
║ └──────────────────────────────────────┘ ║
║ ║
║ Quality Metrics ║
║ ┌──────────────────────────────────────┐ ║
║ │ Avg Coverage 90.2% │ ║
║ │ Avg Review 7.9/10 │ ║
║ │ Lint Errors 0 (2 auto-fixed) │ ║
║ │ Security 0 vulnerabilities │ ║
║ └──────────────────────────────────────┘ ║
║ ║
║ Task Timeline ║
║ ┌──────────┬──────────────────────┬────────┬─────────┐ ║
║ │ Task │ Title │ Score │ Time │ ║
║ ├──────────┼──────────────────────┼────────┼─────────┤ ║
║ │ TASK-001 │ Create User model │ 92/100 │ 25 min │ ║
║ │ TASK-002 │ Implement bcrypt │ 95/100 │ 18 min │ ║
║ │ TASK-003 │ Implement auth API │ 85/100 │ 42 min │ ║
║ │ TASK-004 │ Add validation │ 88/100 │ 20 min │ ║
║ │ TASK-005 │ Add auth middleware │ 91/100 │ 28 min │ ║
║ └──────────┴──────────────────────┴────────┴─────────┘ ║
║ ║
║ Git Commits ║
║ abc1234 feat(TASK-001): Create User model ║
║ def5678 feat(TASK-002): Add bcrypt password utility ║
║ ghi9012 feat(TASK-003): Implement RESTful auth API ║
║ jkl3456 feat(TASK-004): Add input validation ║
║ mno7890 feat(TASK-005): Add auth middleware ║
║ ║
║ Meetings Resolved ║
║ MEETING-001: API structure → RESTful (user decided) ║
║ ║
║ OVERALL: ✓ SUCCESS ║
║ Quality Score: 90/100 ║
║ ║
╚══════════════════════════════════════════════════════════════╝
10.3 交互模式对比
| 特性 | interactive | semi-auto | full-auto |
|---|---|---|---|
| 每步确认 | ✓ | ✗ | ✗ |
| 计划审批 | ✓ | ✓ | 自动 |
| 关键决策 | ✓ | ✓ | Meeting |
| Meeting 创建 | ✓ | ✓ | ✓ |
| 用户交互频率 | 高 | 中 | 无 |
| 适用场景 | 学习 | 生产 | CI/CD |
10.4 状态持久化
step/complete 循环
# 获取下一个任务
openmatrix step --json
# 输出:
# {
# "taskId": "TASK-003",
# "phase": "develop",
# "agentType": "coder",
# "prompt": "...",
# "timeout": 600000,
# "context": "..."
# }
# Agent 执行...
# 完成任务
openmatrix complete TASK-003 --success \
--summary "Implemented auth API with JWT" \
--artifacts "src/api/auth.ts,src/routes/auth.ts"
状态恢复
# Context 压缩后恢复
/om:resume
# 从指定任务恢复
/om:resume --task TASK-004 --phase develop
10.5 Git 自动提交
Commit 格式
<type>(TASK-XXX): <subject>
<body>
Impact scope: Module name
Files changed: file1, file2
Co-Authored-By: OpenMatrix https://github.com/bigfish1913/openmatrix
Type 规范:feat, fix, test, refactor, docs, chore
下一章将介绍 最佳实践。