@zeyue0329/xiaoma-cli 1.0.39 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/.idea/workspace.xml +1 -0
  2. package/.xiaoma-core/.coordinator-state.json +19 -0
  3. package/dist/agents/architect.txt +192 -0
  4. package/dist/agents/workflow-helper.txt +93 -0
  5. package/dist/teams/team-all.txt +245 -190
  6. package/dist/teams/team-fullstack-with-database.txt +2 -0
  7. package/dist/teams/team-fullstack.txt +2 -0
  8. package/dist/teams/team-no-ui.txt +2 -0
  9. package/docs/architecture/workflow-coordinator-implementation.md +1188 -0
  10. package/docs/prd/workflow-coordinator-prd.md +1214 -0
  11. package/package.json +1 -1
  12. package/tools/installer/package.json +1 -1
  13. package/tools/workflow-coordinator/README.md +38 -0
  14. package/tools/workflow-coordinator/USAGE.md +548 -0
  15. package/tools/workflow-coordinator/package-lock.json +4868 -0
  16. package/tools/workflow-coordinator/package.json +35 -0
  17. package/tools/workflow-coordinator/src/api/server.js +207 -0
  18. package/tools/workflow-coordinator/src/controller/workflow-controller.js +263 -0
  19. package/tools/workflow-coordinator/src/index.js +113 -0
  20. package/tools/workflow-coordinator/src/parser/workflow-parser.js +144 -0
  21. package/tools/workflow-coordinator/src/utils/state-manager.js +59 -0
  22. package/tools/workflow-coordinator/src/utils/validator.js +86 -0
  23. package/tools/workflow-coordinator/test/integration-test.js +266 -0
  24. package/tools/workflow-coordinator/test/quick-test.js +127 -0
  25. package/xiaoma-core/agents/architect.md +2 -0
  26. package/xiaoma-core/agents/workflow-helper.md +481 -0
  27. package/xiaoma-core/workflows/automated-requirements-analysis.yaml +11 -8
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@zeyue0329/xiaoma-cli",
4
- "version": "1.0.39",
4
+ "version": "1.0.41",
5
5
  "description": "XiaoMa Cli: Universal AI Agent Framework",
6
6
  "keywords": [
7
7
  "agile",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaoma-cli",
3
- "version": "1.0.29",
3
+ "version": "1.0.41",
4
4
  "description": "XiaoMa-Cli installer - AI-powered Agile development framework",
5
5
  "keywords": [
6
6
  "bmad",
@@ -0,0 +1,38 @@
1
+ # XiaoMa 工作流协调器
2
+
3
+ 工作流协调器是一个外部进程,负责驱动Claude Code中的工作流自动执行。
4
+
5
+ ## 快速开始
6
+
7
+ ```bash
8
+ # 1. 安装依赖
9
+ npm install
10
+
11
+ # 2. 启动协调器
12
+ npm start start requirements-analysis
13
+
14
+ # 3. 在Claude Code中执行
15
+ # /workflow-helper
16
+ # *start-workflow requirements-analysis
17
+ ```
18
+
19
+ ## 架构
20
+
21
+ ```
22
+ 协调器 (Node.js进程)
23
+ ↕️ HTTP API
24
+ Claude Code (执行智能体)
25
+ ```
26
+
27
+ ## 功能
28
+
29
+ - ✅ 解析工作流YAML定义
30
+ - ✅ HTTP服务器接收Claude Code回调
31
+ - ✅ 步骤流程控制和决策
32
+ - ✅ 状态持久化和恢复
33
+ - ✅ 质量门控验证
34
+
35
+ ## 相关文档
36
+
37
+ - [PRD文档](../../docs/prd/workflow-coordinator-prd.md)
38
+ - [实现指南](../../docs/architecture/workflow-coordinator-implementation.md)
@@ -0,0 +1,548 @@
1
+ # 工作流协调器使用指南
2
+
3
+ ## 概述
4
+
5
+ 工作流协调器是一个独立的Node.js程序,用于驱动XiaoMa-CLI工作流的完全自动化执行,消除AI决策延迟和人工确认步骤。
6
+
7
+ ### 核心特点
8
+
9
+ - ✅ **程序化流程控制**:基于YAML定义的确定性执行流程
10
+ - ✅ **HTTP API通信**:与Claude Code通过RESTful API交互
11
+ - ✅ **质量门控**:自动验证每个步骤的输出文件
12
+ - ✅ **状态持久化**:支持从中断点恢复执行
13
+ - ✅ **失败重试**:可配置的自动重试机制
14
+ - ✅ **实时监控**:彩色日志输出,清晰展示执行进度
15
+
16
+ ## 快速开始
17
+
18
+ ### 1. 安装依赖
19
+
20
+ ```bash
21
+ cd tools/workflow-coordinator
22
+ npm install
23
+ ```
24
+
25
+ ### 2. 启动协调器
26
+
27
+ ```bash
28
+ # 启动协调器并加载指定工作流
29
+ node src/index.js start automated-requirements-analysis
30
+
31
+ # 或使用环境变量设置端口
32
+ COORDINATOR_PORT=3002 node src/index.js start automated-requirements-analysis
33
+ ```
34
+
35
+ **输出示例**:
36
+ ```
37
+ ╔════════════════════════════════════════╗
38
+ ║ XiaoMa 工作流协调器 ║
39
+ ╚════════════════════════════════════════╝
40
+
41
+ 📋 解析工作流: automated-requirements-analysis
42
+ ✅ 工作流解析完成
43
+ 名称: 自动化需求分析和架构设计流程
44
+ 步骤数: 7
45
+ 类型: automated-requirements-analysis
46
+
47
+ 🌐 启动HTTP服务...
48
+ ✅ HTTP服务已启动: http://localhost:3001
49
+
50
+ ⏳ 等待Claude Code连接...
51
+
52
+ 提示: 在Claude Code中执行以下命令启动工作流:
53
+
54
+ /workflow-helper
55
+ *start-workflow automated-requirements-analysis
56
+
57
+ 按 Ctrl+C 停止协调器
58
+ ```
59
+
60
+ ### 3. 在Claude Code中启动工作流
61
+
62
+ 在Claude Code命令行中执行:
63
+
64
+ ```
65
+ /workflow-helper
66
+ *start-workflow automated-requirements-analysis
67
+ ```
68
+
69
+ 工作流将自动执行,无需人工干预。
70
+
71
+ ## 架构说明
72
+
73
+ ### 组件关系
74
+
75
+ ```
76
+ ┌─────────────────────────────────────────────────────────────┐
77
+ │ 工作流协调器 (Workflow Coordinator) │
78
+ │ - 位置: tools/workflow-coordinator │
79
+ │ - 端口: http://localhost:3001 │
80
+ │ - 职责: 流程控制、状态管理、质量验证 │
81
+ └─────────────────────────────────────────────────────────────┘
82
+ ↕ HTTP API
83
+ ┌─────────────────────────────────────────────────────────────┐
84
+ │ Claude Code + workflow-helper Agent │
85
+ │ - 智能体: xiaoma-core/agents/workflow-helper.md │
86
+ │ - 职责: 执行命令、生成文档、报告结果 │
87
+ └─────────────────────────────────────────────────────────────┘
88
+ ```
89
+
90
+ ### 执行流程
91
+
92
+ 1. **启动阶段**:
93
+ - 协调器解析YAML工作流定义
94
+ - 启动HTTP服务器监听API请求
95
+ - workflow-helper发送`/workflow/start`请求
96
+ - 协调器返回第一步执行指令
97
+
98
+ 2. **执行循环**:
99
+ - workflow-helper切换智能体(如`/po`, `/architect`)
100
+ - 执行智能体命令(如`*create-prd`, `*design-architecture`)
101
+ - 生成文档和代码
102
+ - 发送`/workflow/step-complete`报告完成
103
+ - 协调器验证输出质量
104
+ - 返回下一步指令或完成状态
105
+
106
+ 3. **失败处理**:
107
+ - workflow-helper发送`/workflow/step-failed`报告错误
108
+ - 协调器判断是否可以重试
109
+ - 返回重试指令或中止流程
110
+
111
+ 4. **完成阶段**:
112
+ - 所有步骤完成后返回工作流摘要
113
+ - 显示总耗时、生成的文档列表
114
+ - 状态保存到`.xiaoma-core/.coordinator-state.json`
115
+
116
+ ## API 端点
117
+
118
+ ### POST /workflow/start
119
+
120
+ 启动工作流执行。
121
+
122
+ **请求**:
123
+ ```json
124
+ {
125
+ "workflowId": "automated-requirements-analysis-1699887766123",
126
+ "context": {
127
+ "userRequirement": "用户需求描述"
128
+ }
129
+ }
130
+ ```
131
+
132
+ **响应**:
133
+ ```json
134
+ {
135
+ "success": true,
136
+ "workflowId": "automated-requirements-analysis-1699887766123",
137
+ "workflowName": "自动化需求分析和架构设计流程",
138
+ "totalSteps": 7,
139
+ "firstStep": {
140
+ "stepId": "需求分析",
141
+ "agent": "po",
142
+ "switchCommand": "/po",
143
+ "executeCommand": "*create-prd",
144
+ "prompt": "基于{{user_requirement}},创建详细的PRD文档...",
145
+ "inputFiles": [],
146
+ "expectedOutputs": ["docs/prd/prd.md"],
147
+ "estimatedDuration": "10-15分钟"
148
+ }
149
+ }
150
+ ```
151
+
152
+ ### POST /workflow/step-complete
153
+
154
+ 报告步骤完成,获取下一步指令。
155
+
156
+ **请求**:
157
+ ```json
158
+ {
159
+ "workflowId": "automated-requirements-analysis-1699887766123",
160
+ "stepId": "需求分析",
161
+ "status": "completed",
162
+ "outputs": [
163
+ {
164
+ "file": "docs/prd/prd.md",
165
+ "exists": true,
166
+ "size": 15234
167
+ }
168
+ ],
169
+ "duration": 450000
170
+ }
171
+ ```
172
+
173
+ **响应(有下一步)**:
174
+ ```json
175
+ {
176
+ "success": true,
177
+ "hasNextStep": true,
178
+ "nextStep": {
179
+ "stepId": "架构设计",
180
+ "agent": "architect",
181
+ "switchCommand": "/architect",
182
+ "executeCommand": "*design-architecture",
183
+ ...
184
+ },
185
+ "progress": {
186
+ "currentStepIndex": 2,
187
+ "totalSteps": 7,
188
+ "percentComplete": 29
189
+ }
190
+ }
191
+ ```
192
+
193
+ **响应(工作流完成)**:
194
+ ```json
195
+ {
196
+ "success": true,
197
+ "hasNextStep": false,
198
+ "message": "🎉 工作流执行完成!",
199
+ "summary": {
200
+ "workflowId": "automated-requirements-analysis-1699887766123",
201
+ "workflowName": "自动化需求分析和架构设计流程",
202
+ "status": "completed",
203
+ "totalDuration": 2730000,
204
+ "totalDurationFormatted": "45分钟30秒",
205
+ "totalSteps": 7,
206
+ "outputs": [
207
+ "docs/prd/prd.md",
208
+ "docs/architecture/architecture.md",
209
+ ...
210
+ ],
211
+ "errors": 0
212
+ }
213
+ }
214
+ ```
215
+
216
+ **响应(验证失败)**:
217
+ ```json
218
+ {
219
+ "success": false,
220
+ "action": "fix_quality",
221
+ "issues": [
222
+ {
223
+ "level": "error",
224
+ "message": "输出文件不存在: docs/prd/prd.md"
225
+ }
226
+ ],
227
+ "message": "步骤输出质量验证失败,请修复问题后重试"
228
+ }
229
+ ```
230
+
231
+ ### POST /workflow/step-failed
232
+
233
+ 报告步骤失败。
234
+
235
+ **请求**:
236
+ ```json
237
+ {
238
+ "workflowId": "automated-requirements-analysis-1699887766123",
239
+ "stepId": "架构设计",
240
+ "error": "模板文件未找到",
241
+ "errorDetails": {
242
+ "missingFile": "templates/architecture.md"
243
+ }
244
+ }
245
+ ```
246
+
247
+ **响应(重试)**:
248
+ ```json
249
+ {
250
+ "success": true,
251
+ "action": "retry",
252
+ "retryCount": 1,
253
+ "maxRetries": 3,
254
+ "retryStep": { ... },
255
+ "message": "将进行第 1 次重试"
256
+ }
257
+ ```
258
+
259
+ **响应(中止)**:
260
+ ```json
261
+ {
262
+ "success": false,
263
+ "action": "abort",
264
+ "message": "步骤 \"架构设计\" 执行失败,已达最大重试次数",
265
+ "escalation": "需要人工介入:请检查架构模板完整性"
266
+ }
267
+ ```
268
+
269
+ ### GET /workflow/status
270
+
271
+ 查询当前工作流状态。
272
+
273
+ **响应**:
274
+ ```json
275
+ {
276
+ "workflowId": "automated-requirements-analysis-1699887766123",
277
+ "workflowName": "自动化需求分析和架构设计流程",
278
+ "status": "in_progress",
279
+ "currentStepIndex": 3,
280
+ "totalSteps": 7,
281
+ "completedSteps": ["需求分析", "架构设计"],
282
+ "currentStep": "详细模块设计",
283
+ "errors": 0,
284
+ "startTime": "2023-11-13T10:22:46.123Z"
285
+ }
286
+ ```
287
+
288
+ ### POST /workflow/abort
289
+
290
+ 中止工作流执行。
291
+
292
+ **请求**:
293
+ ```json
294
+ {
295
+ "workflowId": "automated-requirements-analysis-1699887766123",
296
+ "reason": "用户取消"
297
+ }
298
+ ```
299
+
300
+ **响应**:
301
+ ```json
302
+ {
303
+ "success": true,
304
+ "message": "工作流已中止,状态已保存"
305
+ }
306
+ ```
307
+
308
+ ### GET /health
309
+
310
+ 健康检查端点。
311
+
312
+ **响应**:
313
+ ```json
314
+ {
315
+ "status": "ok",
316
+ "timestamp": "2025-11-13T15:30:00.000Z"
317
+ }
318
+ ```
319
+
320
+ ## 目录结构
321
+
322
+ ```
323
+ tools/workflow-coordinator/
324
+ ├── src/
325
+ │ ├── index.js # 主入口,CLI接口
326
+ │ ├── api/
327
+ │ │ └── server.js # HTTP服务器,API端点实现
328
+ │ ├── controller/
329
+ │ │ └── workflow-controller.js # 工作流控制器,核心逻辑
330
+ │ ├── parser/
331
+ │ │ └── workflow-parser.js # YAML工作流解析器
332
+ │ └── utils/
333
+ │ ├── state-manager.js # 状态持久化管理
334
+ │ └── validator.js # 输出质量验证
335
+ ├── test/
336
+ │ ├── integration-test.js # 集成测试
337
+ │ └── quick-test.js # 快速测试
338
+ ├── package.json # 项目配置
339
+ ├── .env.example # 环境变量示例
340
+ ├── README.md # 项目说明
341
+ └── USAGE.md # 使用指南(本文档)
342
+ ```
343
+
344
+ ## 配置
345
+
346
+ ### 环境变量
347
+
348
+ 创建`.env`文件:
349
+
350
+ ```bash
351
+ # 协调器HTTP服务器端口
352
+ COORDINATOR_PORT=3001
353
+ ```
354
+
355
+ ### 工作流定义
356
+
357
+ 工作流定义文件位于`xiaoma-core/workflows/`,使用YAML格式。
358
+
359
+ **示例**:
360
+ ```yaml
361
+ workflow:
362
+ id: automated-requirements-analysis
363
+ name: "自动化需求分析和架构设计流程"
364
+ type: automated-requirements-analysis
365
+
366
+ sequence:
367
+ - step: requirements_analysis
368
+ agent: po
369
+ duration: "10-15分钟"
370
+ detailed_steps:
371
+ - command: "/po"
372
+ description: "切换到产品经理智能体"
373
+ - command: "*create-prd"
374
+ description: "创建PRD文档"
375
+ validation_criteria:
376
+ - file_created: "docs/prd/prd.md"
377
+ on_failure:
378
+ max_retries: 3
379
+ escalation: "请检查PRD模板完整性"
380
+
381
+ - step: architecture_design
382
+ agent: architect
383
+ duration: "15-20分钟"
384
+ ...
385
+ ```
386
+
387
+ ## 测试
388
+
389
+ ### 运行快速测试
390
+
391
+ ```bash
392
+ # 先启动协调器
393
+ node src/index.js start automated-requirements-analysis
394
+
395
+ # 在另一个终端运行测试
396
+ npm test
397
+ # 或
398
+ node test/quick-test.js
399
+ ```
400
+
401
+ **测试输出示例**:
402
+ ```
403
+ ╔════════════════════════════════════════╗
404
+ ║ 工作流协调器快速测试 ║
405
+ ╚════════════════════════════════════════╝
406
+
407
+ 1. 健康检查...
408
+ ✓ 状态: ok
409
+
410
+ 2. 启动工作流...
411
+ ✓ 工作流: 自动化需求分析和架构设计流程
412
+ - ID: test-1763048289115
413
+ - 总步骤: 7
414
+ - 第一步: pre_workflow_validation
415
+
416
+ 3. 查询初始状态...
417
+ ✓ 状态: in_progress
418
+ - 当前步骤: pre_workflow_validation
419
+ - 进度: 1/7
420
+
421
+ 4. 模拟完成所有步骤...
422
+ 步骤 1: pre_workflow_validation
423
+ ✓ 完成 (进度: 14%)
424
+ 步骤 2: requirements_analysis_and_elicitation
425
+ ✓ 完成 (进度: 29%)
426
+ ...
427
+
428
+ ╔════════════════════════════════════════╗
429
+ ║ 测试全部通过! ✓ ║
430
+ ╚════════════════════════════════════════╝
431
+ ```
432
+
433
+ ### API测试模式
434
+
435
+ 启动简单的测试服务器:
436
+
437
+ ```bash
438
+ node src/index.js test-api
439
+ ```
440
+
441
+ 使用curl测试:
442
+
443
+ ```bash
444
+ curl -X POST http://localhost:3001/workflow/start \
445
+ -H "Content-Type: application/json" \
446
+ -d '{"workflowId":"test"}'
447
+ ```
448
+
449
+ ## 故障排查
450
+
451
+ ### 协调器无法启动
452
+
453
+ **问题**: 端口被占用
454
+
455
+ ```
456
+ Error: listen EADDRINUSE: address already in use :::3001
457
+ ```
458
+
459
+ **解决**:
460
+ ```bash
461
+ # 查找占用端口的进程
462
+ lsof -i :3001
463
+
464
+ # 杀死进程
465
+ kill -9 <PID>
466
+
467
+ # 或更换端口
468
+ COORDINATOR_PORT=3002 node src/index.js start automated-requirements-analysis
469
+ ```
470
+
471
+ ### 工作流文件未找到
472
+
473
+ **问题**:
474
+ ```
475
+ ❌ 启动失败
476
+ 错误: 工作流文件未找到: automated-requirements-analysis
477
+ ```
478
+
479
+ **解决**:
480
+ - 确认工作流文件存在于`xiaoma-core/workflows/`
481
+ - 检查文件名是否正确
482
+ - 支持的文件格式: `.yaml`, `.yml`
483
+
484
+ ### 质量验证失败
485
+
486
+ **问题**:
487
+ ```
488
+ ❌ 步骤输出质量验证失败
489
+
490
+ 问题:
491
+ - [错误] 输出文件不存在: docs/prd/prd.md
492
+ ```
493
+
494
+ **解决**:
495
+ - 检查智能体是否正确生成了文件
496
+ - 确认文件路径与工作流定义一致
497
+ - 查看Claude Code日志了解生成失败原因
498
+
499
+ ### Claude Code连接失败
500
+
501
+ **问题**: workflow-helper无法连接到协调器
502
+
503
+ ```
504
+ ❌ 无法连接到协调器
505
+ 请确认协调器已启动: http://localhost:3001
506
+ ```
507
+
508
+ **解决**:
509
+ - 确认协调器正在运行
510
+ - 检查端口是否正确
511
+ - 确认防火墙设置
512
+
513
+ ## 与workflow-executor的对比
514
+
515
+ | 特性 | workflow-executor (旧) | workflow-helper + Coordinator (新) |
516
+ |------|----------------------|-----------------------------------|
517
+ | 控制方式 | AI驱动决策 | 程序化流程控制 |
518
+ | 人工干预 | 需要确认 | 完全自动化 |
519
+ | 执行速度 | 较慢(AI思考时间) | 更快(确定性流程) |
520
+ | 可恢复性 | 不支持 | 支持状态持久化 |
521
+ | 质量验证 | 依赖AI判断 | 程序化验证规则 |
522
+ | 监控能力 | 基础 | 详细日志和进度追踪 |
523
+ | 错误处理 | 手动 | 自动重试机制 |
524
+
525
+ ## 最佳实践
526
+
527
+ 1. **先测试后生产**:在测试环境验证工作流定义
528
+ 2. **保留日志**:协调器日志对问题诊断很有帮助
529
+ 3. **定期备份状态**:`.xiaoma-core/.coordinator-state.json`文件很重要
530
+ 4. **合理设置重试次数**:避免无限重试
531
+ 5. **监控执行时间**:长时间卡住可能表示有问题
532
+ 6. **验证输出质量**:在工作流定义中添加详细的validation_criteria
533
+
534
+ ## 未来增强
535
+
536
+ - [ ] 支持并行执行多个步骤
537
+ - [ ] 添加Web UI监控面板
538
+ - [ ] 集成通知系统(邮件/Slack)
539
+ - [ ] 支持工作流版本管理
540
+ - [ ] 添加性能指标收集
541
+ - [ ] 支持条件分支(if/else)
542
+ - [ ] 支持循环步骤(for/while)
543
+
544
+ ## 技术支持
545
+
546
+ - GitHub Issues: https://github.com/anthropics/xiaoma-cli/issues
547
+ - 文档: docs/architecture/workflow-coordinator-implementation.md
548
+ - PRD: docs/prd/workflow-coordinator-prd.md