openmatrix 0.1.42 → 0.1.44
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.
- package/dist/orchestrator/task-planner.d.ts +8 -51
- package/dist/orchestrator/task-planner.js +109 -384
- package/package.json +2 -1
- package/skills/brainstorm.md +429 -429
- package/skills/start.md +86 -474
|
@@ -8,7 +8,6 @@ export interface TaskBreakdown {
|
|
|
8
8
|
estimatedComplexity: 'low' | 'medium' | 'high';
|
|
9
9
|
assignedAgent: 'planner' | 'coder' | 'tester' | 'reviewer' | 'researcher' | 'executor';
|
|
10
10
|
acceptanceCriteria?: string[];
|
|
11
|
-
testTaskId?: string;
|
|
12
11
|
phase: 'design' | 'develop' | 'verify' | 'accept';
|
|
13
12
|
}
|
|
14
13
|
export interface UserAnswers {
|
|
@@ -17,71 +16,29 @@ export interface UserAnswers {
|
|
|
17
16
|
testCoverage?: string;
|
|
18
17
|
documentationLevel?: string;
|
|
19
18
|
additionalContext?: Record<string, string>;
|
|
20
|
-
/** 是否启用 E2E 测试 */
|
|
21
|
-
e2eTests?: boolean;
|
|
22
|
-
/** E2E 测试类型 (web/mobile/gui) */
|
|
23
|
-
e2eType?: 'web' | 'mobile' | 'gui';
|
|
24
19
|
}
|
|
25
20
|
/**
|
|
26
21
|
* TaskPlanner - 任务拆解器
|
|
27
22
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* 2. 测试任务配对 (每个开发任务自动生成对应测试任务)
|
|
31
|
-
* 3. 验收标准注入 (从用户回答中提取)
|
|
32
|
-
* 4. 用户上下文注入 (将用户回答注入任务描述)
|
|
33
|
-
* 5. 依赖关系分析 (自动分析任务间依赖)
|
|
23
|
+
* 始终基于整体内容拆解,不依赖 goals 提取
|
|
24
|
+
* 流程: 规划(AI输出PLAN.md) → 开发(基于PLAN.md) → 验证
|
|
34
25
|
*/
|
|
35
26
|
export declare class TaskPlanner {
|
|
36
|
-
private userAnswers;
|
|
37
|
-
constructor(userAnswers?: UserAnswers);
|
|
38
|
-
/**
|
|
39
|
-
* 设置用户回答
|
|
40
|
-
*/
|
|
41
|
-
setUserAnswers(answers: UserAnswers): void;
|
|
42
27
|
/**
|
|
43
28
|
* Break down a parsed task into sub-tasks
|
|
44
29
|
*
|
|
45
|
-
*
|
|
30
|
+
* 始终基于整体内容拆解: 规划→开发→验证
|
|
46
31
|
*/
|
|
47
32
|
breakdown(parsedTask: ParsedTask, answers: Record<string, string>): TaskBreakdown[];
|
|
48
33
|
/**
|
|
49
|
-
*
|
|
34
|
+
* 基于 Plan 的任务序列
|
|
35
|
+
* 规划(AI分析需求→输出PLAN.md) → 开发(基于PLAN.md实现) → 验证
|
|
50
36
|
*/
|
|
51
|
-
private
|
|
37
|
+
private createPlanBasedTasks;
|
|
52
38
|
/**
|
|
53
|
-
*
|
|
39
|
+
* 提取用户上下文
|
|
54
40
|
*/
|
|
41
|
+
private extractUserContext;
|
|
55
42
|
private parseArrayAnswer;
|
|
56
|
-
/**
|
|
57
|
-
* 构建任务描述 (注入用户上下文)
|
|
58
|
-
*/
|
|
59
|
-
private buildTaskDescription;
|
|
60
|
-
/**
|
|
61
|
-
* 构建测试任务描述
|
|
62
|
-
*/
|
|
63
|
-
private buildTestDescription;
|
|
64
|
-
/**
|
|
65
|
-
* 构建 E2E 测试任务描述
|
|
66
|
-
*/
|
|
67
|
-
private buildE2ETestDescription;
|
|
68
|
-
/**
|
|
69
|
-
* 获取 E2E 测试类型配置
|
|
70
|
-
*/
|
|
71
|
-
private getE2ETypeConfig;
|
|
72
|
-
/**
|
|
73
|
-
* 生成用户流程测试用例
|
|
74
|
-
*/
|
|
75
|
-
private generateUserFlows;
|
|
76
|
-
/**
|
|
77
|
-
* 解析覆盖率数值
|
|
78
|
-
*/
|
|
79
|
-
private parseCoverage;
|
|
80
|
-
/**
|
|
81
|
-
* 生成验收标准
|
|
82
|
-
*/
|
|
83
|
-
private generateAcceptanceCriteria;
|
|
84
43
|
private generateTaskId;
|
|
85
|
-
private determinePriority;
|
|
86
|
-
private estimateComplexity;
|
|
87
44
|
}
|
|
@@ -4,441 +4,166 @@ exports.TaskPlanner = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* TaskPlanner - 任务拆解器
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* 2. 测试任务配对 (每个开发任务自动生成对应测试任务)
|
|
10
|
-
* 3. 验收标准注入 (从用户回答中提取)
|
|
11
|
-
* 4. 用户上下文注入 (将用户回答注入任务描述)
|
|
12
|
-
* 5. 依赖关系分析 (自动分析任务间依赖)
|
|
7
|
+
* 始终基于整体内容拆解,不依赖 goals 提取
|
|
8
|
+
* 流程: 规划(AI输出PLAN.md) → 开发(基于PLAN.md) → 验证
|
|
13
9
|
*/
|
|
14
10
|
class TaskPlanner {
|
|
15
|
-
userAnswers;
|
|
16
|
-
constructor(userAnswers) {
|
|
17
|
-
this.userAnswers = userAnswers || {};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* 设置用户回答
|
|
21
|
-
*/
|
|
22
|
-
setUserAnswers(answers) {
|
|
23
|
-
this.userAnswers = answers;
|
|
24
|
-
}
|
|
25
11
|
/**
|
|
26
12
|
* Break down a parsed task into sub-tasks
|
|
27
13
|
*
|
|
28
|
-
*
|
|
14
|
+
* 始终基于整体内容拆解: 规划→开发→验证
|
|
29
15
|
*/
|
|
30
16
|
breakdown(parsedTask, answers) {
|
|
31
|
-
const breakdowns = [];
|
|
32
|
-
const seenTitles = new Set();
|
|
33
17
|
const userContext = this.extractUserContext(answers);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
18
|
+
return this.createPlanBasedTasks(parsedTask, userContext, answers);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 基于 Plan 的任务序列
|
|
22
|
+
* 规划(AI分析需求→输出PLAN.md) → 开发(基于PLAN.md实现) → 验证
|
|
23
|
+
*/
|
|
24
|
+
createPlanBasedTasks(parsedTask, userContext, answers) {
|
|
25
|
+
const planTaskId = this.generateTaskId();
|
|
26
|
+
const devTaskId = this.generateTaskId();
|
|
27
|
+
const testTaskId = this.generateTaskId();
|
|
28
|
+
// 组装完整上下文
|
|
29
|
+
const contextParts = [];
|
|
30
|
+
contextParts.push(`## 原始需求\n${parsedTask.rawContent || parsedTask.description || parsedTask.title}`);
|
|
31
|
+
if (parsedTask.goals.length)
|
|
32
|
+
contextParts.push(`## 明确目标\n${parsedTask.goals.map(g => `- ${g}`).join('\n')}`);
|
|
33
|
+
if (userContext.objective)
|
|
34
|
+
contextParts.push(`## 核心目标\n${userContext.objective}`);
|
|
35
|
+
if (userContext.techStack?.length)
|
|
36
|
+
contextParts.push(`## 技术栈\n${userContext.techStack.join(', ')}`);
|
|
37
|
+
if (parsedTask.constraints.length)
|
|
38
|
+
contextParts.push(`## 约束\n${parsedTask.constraints.map(c => `- ${c}`).join('\n')}`);
|
|
39
|
+
// brainstorm 答案
|
|
40
|
+
const brainstormKeys = ['brainstormAnswers', 'insights', 'designNotes'];
|
|
41
|
+
for (const key of brainstormKeys) {
|
|
42
|
+
if (answers[key])
|
|
43
|
+
contextParts.push(`## ${key}\n${answers[key]}`);
|
|
44
|
+
}
|
|
45
|
+
const fullContext = contextParts.join('\n\n');
|
|
46
|
+
return [
|
|
47
|
+
// 1. 规划任务
|
|
48
|
+
{
|
|
49
|
+
taskId: planTaskId,
|
|
50
|
+
title: `${parsedTask.title} - 需求分析与规划`,
|
|
51
|
+
description: `分析需求并制定实现计划。
|
|
52
|
+
|
|
53
|
+
${fullContext}
|
|
54
|
+
|
|
55
|
+
## 你的任务
|
|
56
|
+
1. 深入理解需求
|
|
57
|
+
2. 设计实现方案
|
|
58
|
+
3. 将需求拆解为具体步骤
|
|
59
|
+
|
|
60
|
+
## 输出: PLAN.md
|
|
61
|
+
在项目根目录创建 PLAN.md,格式如下:
|
|
62
|
+
|
|
63
|
+
# 实现计划
|
|
64
|
+
|
|
65
|
+
## 架构设计
|
|
66
|
+
(整体方案描述)
|
|
67
|
+
|
|
68
|
+
## 实现步骤
|
|
69
|
+
### 步骤 1: (标题)
|
|
70
|
+
- 描述: (具体做什么)
|
|
71
|
+
- 文件: (涉及哪些文件)
|
|
72
|
+
- 验收: (怎么判断完成)
|
|
73
|
+
|
|
74
|
+
### 步骤 2: (标题)
|
|
75
|
+
- 描述: ...
|
|
76
|
+
- 文件: ...
|
|
77
|
+
- 验收: ...
|
|
78
|
+
|
|
79
|
+
## 注意事项
|
|
80
|
+
- (风险、约束等)`,
|
|
51
81
|
priority: 'P0',
|
|
52
82
|
dependencies: [],
|
|
53
83
|
estimatedComplexity: 'high',
|
|
54
84
|
assignedAgent: 'planner',
|
|
55
85
|
phase: 'design',
|
|
56
86
|
acceptanceCriteria: [
|
|
57
|
-
'
|
|
58
|
-
'
|
|
59
|
-
'
|
|
60
|
-
'技术方案可行'
|
|
87
|
+
'PLAN.md 已创建',
|
|
88
|
+
'实现步骤清晰可执行',
|
|
89
|
+
'每步有明确的文件和验收标准'
|
|
61
90
|
]
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const devTaskIds = [];
|
|
66
|
-
for (let i = 0; i < parsedTask.goals.length; i++) {
|
|
67
|
-
const goal = parsedTask.goals[i];
|
|
68
|
-
// 跳过重复项
|
|
69
|
-
if (seenTitles.has(goal)) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
seenTitles.add(goal);
|
|
73
|
-
// 创建开发任务
|
|
74
|
-
const devTaskId = this.generateTaskId();
|
|
75
|
-
devTaskIds.push(devTaskId);
|
|
76
|
-
const acceptanceCriteria = this.generateAcceptanceCriteria(goal, userContext);
|
|
77
|
-
breakdowns.push({
|
|
91
|
+
},
|
|
92
|
+
// 2. 开发任务
|
|
93
|
+
{
|
|
78
94
|
taskId: devTaskId,
|
|
79
|
-
title:
|
|
80
|
-
description:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
? [breakdowns[0].taskId] // 依赖设计任务
|
|
84
|
-
: (i > 0 ? [devTaskIds[i - 1]] : []), // 依赖前一个开发任务
|
|
85
|
-
estimatedComplexity: this.estimateComplexity(goal),
|
|
86
|
-
assignedAgent: 'coder',
|
|
87
|
-
phase: 'develop',
|
|
88
|
-
acceptanceCriteria,
|
|
89
|
-
testTaskId: undefined // 稍后关联
|
|
90
|
-
});
|
|
91
|
-
// 为每个开发任务创建配对的测试任务
|
|
92
|
-
const testTaskId = this.generateTaskId();
|
|
93
|
-
breakdowns.push({
|
|
94
|
-
taskId: testTaskId,
|
|
95
|
-
title: `测试: ${goal}`,
|
|
96
|
-
description: this.buildTestDescription(goal, devTaskId, userContext),
|
|
97
|
-
priority: this.determinePriority(i),
|
|
98
|
-
dependencies: [devTaskId], // 测试依赖开发任务
|
|
99
|
-
estimatedComplexity: 'medium',
|
|
100
|
-
assignedAgent: 'tester',
|
|
101
|
-
phase: 'verify',
|
|
102
|
-
acceptanceCriteria: [
|
|
103
|
-
`单元测试覆盖率 >= ${userContext.testCoverage || '60%'}`,
|
|
104
|
-
'边界情况已测试',
|
|
105
|
-
'异常处理已验证',
|
|
106
|
-
'所有测试通过'
|
|
107
|
-
]
|
|
108
|
-
});
|
|
109
|
-
// 关联测试任务 ID
|
|
110
|
-
breakdowns[breakdowns.length - 2].testTaskId = testTaskId;
|
|
111
|
-
}
|
|
112
|
-
// 2. 代码审查任务 (仅在有开发任务时创建)
|
|
113
|
-
if (devTaskIds.length > 0) {
|
|
114
|
-
breakdowns.push({
|
|
115
|
-
taskId: this.generateTaskId(),
|
|
116
|
-
title: '代码审查',
|
|
117
|
-
description: `对所有开发任务进行代码审查
|
|
95
|
+
title: `${parsedTask.title} - 开发实现`,
|
|
96
|
+
description: `根据 PLAN.md 实现功能。
|
|
97
|
+
|
|
98
|
+
${fullContext}
|
|
118
99
|
|
|
119
|
-
##
|
|
120
|
-
|
|
100
|
+
## 执行方式
|
|
101
|
+
1. 先读取项目根目录的 PLAN.md
|
|
102
|
+
2. 按照步骤逐一实现
|
|
103
|
+
3. 每完成一个步骤,验证对应的验收标准
|
|
121
104
|
|
|
122
|
-
##
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
- 性能
|
|
126
|
-
- 最佳实践`,
|
|
105
|
+
## 输出
|
|
106
|
+
- 完整的功能代码
|
|
107
|
+
- 必要的配置文件`,
|
|
127
108
|
priority: 'P1',
|
|
128
|
-
dependencies:
|
|
129
|
-
estimatedComplexity: '
|
|
130
|
-
assignedAgent: '
|
|
131
|
-
phase: '
|
|
109
|
+
dependencies: [planTaskId],
|
|
110
|
+
estimatedComplexity: 'high',
|
|
111
|
+
assignedAgent: 'coder',
|
|
112
|
+
phase: 'develop',
|
|
132
113
|
acceptanceCriteria: [
|
|
133
|
-
'
|
|
134
|
-
'
|
|
135
|
-
'
|
|
136
|
-
'审查报告已生成'
|
|
114
|
+
'PLAN.md 中所有步骤已实现',
|
|
115
|
+
'代码可编译运行',
|
|
116
|
+
'无严重 bug'
|
|
137
117
|
]
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
title: '集成测试',
|
|
145
|
-
description: `验证所有交付物正确集成
|
|
118
|
+
},
|
|
119
|
+
// 3. 验证任务
|
|
120
|
+
{
|
|
121
|
+
taskId: testTaskId,
|
|
122
|
+
title: `${parsedTask.title} - 验证`,
|
|
123
|
+
description: `验证实现是否满足需求。
|
|
146
124
|
|
|
147
|
-
##
|
|
148
|
-
${parsedTask.
|
|
125
|
+
## 原始需求
|
|
126
|
+
${parsedTask.rawContent || parsedTask.title}
|
|
149
127
|
|
|
150
|
-
##
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
128
|
+
## 验证方式
|
|
129
|
+
1. 读取 PLAN.md 中的验收标准
|
|
130
|
+
2. 逐一验证每个步骤
|
|
131
|
+
3. 运行测试(如有)
|
|
132
|
+
4. 检查代码质量`,
|
|
154
133
|
priority: 'P1',
|
|
155
|
-
dependencies:
|
|
134
|
+
dependencies: [devTaskId],
|
|
156
135
|
estimatedComplexity: 'medium',
|
|
157
136
|
assignedAgent: 'tester',
|
|
158
137
|
phase: 'verify',
|
|
159
138
|
acceptanceCriteria: [
|
|
160
|
-
'
|
|
161
|
-
'
|
|
162
|
-
'
|
|
163
|
-
'集成测试报告完整'
|
|
164
|
-
]
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
// 4. E2E 测试任务 (如果启用,作为 verify 阶段的一部分)
|
|
168
|
-
if (userContext.e2eTests) {
|
|
169
|
-
const e2eTaskId = this.generateTaskId();
|
|
170
|
-
const e2eType = userContext.e2eType || 'web';
|
|
171
|
-
// E2E 测试依赖所有开发任务和单元测试任务
|
|
172
|
-
const allTestDependencies = [...devTaskIds];
|
|
173
|
-
breakdowns.forEach(b => {
|
|
174
|
-
if (b.phase === 'verify' && b.title.startsWith('测试:')) {
|
|
175
|
-
allTestDependencies.push(b.taskId);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
breakdowns.push({
|
|
179
|
-
taskId: e2eTaskId,
|
|
180
|
-
title: '端到端(E2E)测试',
|
|
181
|
-
description: this.buildE2ETestDescription(e2eType, parsedTask, userContext),
|
|
182
|
-
priority: 'P0', // E2E 测试是关键任务
|
|
183
|
-
dependencies: allTestDependencies, // 依赖所有开发任务和单元测试
|
|
184
|
-
estimatedComplexity: 'high',
|
|
185
|
-
assignedAgent: 'tester',
|
|
186
|
-
phase: 'verify',
|
|
187
|
-
acceptanceCriteria: [
|
|
188
|
-
'所有 E2E 测试用例通过',
|
|
189
|
-
'关键用户流程验证完成',
|
|
190
|
-
'跨浏览器/设备兼容性验证',
|
|
191
|
-
'E2E 测试报告已生成',
|
|
192
|
-
'无阻塞级别的缺陷'
|
|
193
|
-
]
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
// 5. 文档任务 (如果需要)
|
|
197
|
-
if (userContext.documentationLevel && userContext.documentationLevel !== '无需文档') {
|
|
198
|
-
breakdowns.push({
|
|
199
|
-
taskId: this.generateTaskId(),
|
|
200
|
-
title: '文档编写',
|
|
201
|
-
description: `编写项目文档
|
|
202
|
-
|
|
203
|
-
## 文档级别
|
|
204
|
-
${userContext.documentationLevel}
|
|
205
|
-
|
|
206
|
-
## 文档内容
|
|
207
|
-
- README 更新
|
|
208
|
-
- API 文档
|
|
209
|
-
- 使用说明`,
|
|
210
|
-
priority: 'P2',
|
|
211
|
-
dependencies: devTaskIds,
|
|
212
|
-
estimatedComplexity: 'low',
|
|
213
|
-
assignedAgent: 'executor',
|
|
214
|
-
phase: 'accept',
|
|
215
|
-
acceptanceCriteria: [
|
|
216
|
-
'README 已更新',
|
|
217
|
-
'API 文档完整',
|
|
218
|
-
'使用说明清晰'
|
|
139
|
+
'所有功能正常运行',
|
|
140
|
+
'PLAN.md 中验收标准全部通过',
|
|
141
|
+
'无严重代码问题'
|
|
219
142
|
]
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return breakdowns;
|
|
143
|
+
}
|
|
144
|
+
];
|
|
223
145
|
}
|
|
224
146
|
/**
|
|
225
147
|
* 提取用户上下文
|
|
226
148
|
*/
|
|
227
149
|
extractUserContext(answers) {
|
|
228
|
-
const e2eAnswer = answers['E2E测试'] || answers['e2eTests'] || answers['e2e'];
|
|
229
|
-
const e2eTypeAnswer = answers['E2E类型'] || answers['e2eType'];
|
|
230
150
|
return {
|
|
231
151
|
objective: answers['目标'] || answers['objective'],
|
|
232
152
|
techStack: this.parseArrayAnswer(answers['技术栈'] || answers['techStack']),
|
|
233
153
|
testCoverage: answers['测试'] || answers['testCoverage'],
|
|
234
154
|
documentationLevel: answers['文档'] || answers['documentationLevel'],
|
|
235
|
-
e2eTests: e2eAnswer === 'true' || e2eAnswer === '✅ 启用 E2E 测试' || e2eAnswer === '是',
|
|
236
|
-
e2eType: e2eTypeAnswer || 'web',
|
|
237
155
|
additionalContext: answers
|
|
238
156
|
};
|
|
239
157
|
}
|
|
240
|
-
/**
|
|
241
|
-
* 解析数组类型的回答
|
|
242
|
-
*/
|
|
243
158
|
parseArrayAnswer(answer) {
|
|
244
159
|
if (!answer)
|
|
245
160
|
return [];
|
|
246
|
-
// 处理逗号分隔或换行分隔的答案
|
|
247
161
|
return answer.split(/[,,\n]/).map(s => s.trim()).filter(Boolean);
|
|
248
162
|
}
|
|
249
|
-
/**
|
|
250
|
-
* 构建任务描述 (注入用户上下文)
|
|
251
|
-
*/
|
|
252
|
-
buildTaskDescription(goal, userContext, answers) {
|
|
253
|
-
const parts = [];
|
|
254
|
-
parts.push(`## 任务目标\n${goal}\n`);
|
|
255
|
-
if (userContext.objective) {
|
|
256
|
-
parts.push(`## 整体目标\n${userContext.objective}\n`);
|
|
257
|
-
}
|
|
258
|
-
if (userContext.techStack && userContext.techStack.length > 0) {
|
|
259
|
-
parts.push(`## 技术栈要求\n${userContext.techStack.map(t => `- ${t}`).join('\n')}\n`);
|
|
260
|
-
}
|
|
261
|
-
// 注入所有用户回答
|
|
262
|
-
const relevantAnswers = Object.entries(answers).filter(([key]) => !['目标', '技术栈', '测试', '文档', 'objective', 'techStack', 'testCoverage', 'documentationLevel'].includes(key));
|
|
263
|
-
if (relevantAnswers.length > 0) {
|
|
264
|
-
parts.push(`## 其他要求\n${relevantAnswers.map(([k, v]) => `- ${k}: ${v}`).join('\n')}\n`);
|
|
265
|
-
}
|
|
266
|
-
parts.push(`## 输出要求
|
|
267
|
-
- 完成功能实现
|
|
268
|
-
- 代码可编译
|
|
269
|
-
- 遵循项目规范
|
|
270
|
-
- 添加必要注释`);
|
|
271
|
-
return parts.join('\n');
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* 构建测试任务描述
|
|
275
|
-
*/
|
|
276
|
-
buildTestDescription(goal, devTaskId, userContext) {
|
|
277
|
-
const coverage = this.parseCoverage(userContext.testCoverage || '60%');
|
|
278
|
-
return `## 测试目标
|
|
279
|
-
为 "${goal}" 编写测试用例
|
|
280
|
-
|
|
281
|
-
## 关联开发任务
|
|
282
|
-
${devTaskId}
|
|
283
|
-
|
|
284
|
-
## 测试要求
|
|
285
|
-
- 单元测试覆盖率 >= ${coverage}%
|
|
286
|
-
- 测试正常流程
|
|
287
|
-
- 测试边界情况
|
|
288
|
-
- 测试异常处理
|
|
289
|
-
|
|
290
|
-
## 测试文件
|
|
291
|
-
- 创建 \`.test.ts\` 或 \`.spec.ts\` 文件
|
|
292
|
-
- 放置在与源文件相同目录或 \`tests/\` 目录
|
|
293
|
-
|
|
294
|
-
## 输出
|
|
295
|
-
- 测试文件
|
|
296
|
-
- 测试报告
|
|
297
|
-
- 覆盖率报告`;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* 构建 E2E 测试任务描述
|
|
301
|
-
*/
|
|
302
|
-
buildE2ETestDescription(e2eType, parsedTask, userContext) {
|
|
303
|
-
const typeConfig = this.getE2ETypeConfig(e2eType);
|
|
304
|
-
return `## E2E 测试目标
|
|
305
|
-
执行完整的端到端测试,验证关键用户流程
|
|
306
|
-
|
|
307
|
-
## 应用类型
|
|
308
|
-
${typeConfig.description}
|
|
309
|
-
|
|
310
|
-
## 测试框架
|
|
311
|
-
${typeConfig.frameworks.map(f => `- ${f}`).join('\n')}
|
|
312
|
-
|
|
313
|
-
## 测试范围
|
|
314
|
-
${parsedTask.goals.map((g, i) => `${i + 1}. ${g}`).join('\n')}
|
|
315
|
-
|
|
316
|
-
## 关键用户流程
|
|
317
|
-
根据应用功能,测试以下流程:
|
|
318
|
-
${this.generateUserFlows(parsedTask, e2eType)}
|
|
319
|
-
|
|
320
|
-
## 测试环境
|
|
321
|
-
${typeConfig.environments.map(e => `- ${e}`).join('\n')}
|
|
322
|
-
|
|
323
|
-
## 测试要求
|
|
324
|
-
1. **关键路径覆盖**: 所有核心用户流程必须有 E2E 测试
|
|
325
|
-
2. **断言完整**: 每个测试步骤必须有明确的断言
|
|
326
|
-
3. **等待策略**: 使用合理的等待机制,避免硬编码延迟
|
|
327
|
-
4. **数据隔离**: 测试数据独立,不影响其他测试
|
|
328
|
-
5. **清理机制**: 测试后清理创建的数据
|
|
329
|
-
|
|
330
|
-
## 输出要求
|
|
331
|
-
- E2E 测试文件 (tests/e2e/*.spec.ts)
|
|
332
|
-
- 测试执行报告
|
|
333
|
-
- 截图/录像 (失败时)
|
|
334
|
-
- 测试覆盖率报告 (如有)
|
|
335
|
-
|
|
336
|
-
## 运行命令
|
|
337
|
-
\`\`\`bash
|
|
338
|
-
${typeConfig.runCommand}
|
|
339
|
-
\`\`\`
|
|
340
|
-
|
|
341
|
-
## 验收标准
|
|
342
|
-
- [ ] 所有 E2E 测试用例通过
|
|
343
|
-
- [ ] 关键用户流程验证完成
|
|
344
|
-
- [ ] 跨浏览器/设备兼容性验证
|
|
345
|
-
- [ ] E2E 测试报告已生成
|
|
346
|
-
- [ ] 无阻塞级别的缺陷`;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* 获取 E2E 测试类型配置
|
|
350
|
-
*/
|
|
351
|
-
getE2ETypeConfig(type) {
|
|
352
|
-
const configs = {
|
|
353
|
-
web: {
|
|
354
|
-
description: 'Web 应用 (浏览器)',
|
|
355
|
-
frameworks: ['Playwright (推荐)', 'Cypress', 'Selenium WebDriver', 'Puppeteer'],
|
|
356
|
-
environments: ['Chrome', 'Firefox', 'Safari', 'Edge', 'Mobile Viewports'],
|
|
357
|
-
runCommand: 'npx playwright test --reporter=html'
|
|
358
|
-
},
|
|
359
|
-
mobile: {
|
|
360
|
-
description: '移动应用 (iOS/Android)',
|
|
361
|
-
frameworks: ['Appium', 'Detox (React Native)', 'XCUITest (iOS)', 'Espresso (Android)'],
|
|
362
|
-
environments: ['iOS Simulator', 'Android Emulator', 'Real Devices'],
|
|
363
|
-
runCommand: 'npx appium --base-path /wd/hub && npm run test:e2e'
|
|
364
|
-
},
|
|
365
|
-
gui: {
|
|
366
|
-
description: 'GUI 桌面应用 (Electron/Native)',
|
|
367
|
-
frameworks: ['Playwright for Electron', 'Spectron (Electron)', 'Robot Framework', 'PyAutoGUI'],
|
|
368
|
-
environments: ['Windows', 'macOS', 'Linux'],
|
|
369
|
-
runCommand: 'npm run test:e2e'
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
return configs[type];
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* 生成用户流程测试用例
|
|
376
|
-
*/
|
|
377
|
-
generateUserFlows(parsedTask, type) {
|
|
378
|
-
const flows = [];
|
|
379
|
-
const goals = parsedTask.goals;
|
|
380
|
-
// 根据目标生成用户流程
|
|
381
|
-
goals.forEach((goal, i) => {
|
|
382
|
-
flows.push(`\n### 流程 ${i + 1}: ${goal}`);
|
|
383
|
-
flows.push('```gherkin');
|
|
384
|
-
flows.push(`Feature: ${goal}`);
|
|
385
|
-
flows.push('');
|
|
386
|
-
flows.push(' Scenario: 正常流程');
|
|
387
|
-
flows.push(` Given 用户已启动应用`);
|
|
388
|
-
flows.push(` When 用户执行 "${goal}" 操作`);
|
|
389
|
-
flows.push(` Then 操作成功完成`);
|
|
390
|
-
flows.push('```');
|
|
391
|
-
});
|
|
392
|
-
return flows.join('\n');
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* 解析覆盖率数值
|
|
396
|
-
*/
|
|
397
|
-
parseCoverage(coverageStr) {
|
|
398
|
-
const match = coverageStr.match(/(\d+)/);
|
|
399
|
-
return match ? parseInt(match[1], 10) : 60;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* 生成验收标准
|
|
403
|
-
*/
|
|
404
|
-
generateAcceptanceCriteria(goal, userContext) {
|
|
405
|
-
const criteria = [
|
|
406
|
-
`功能 "${goal}" 已实现`,
|
|
407
|
-
'代码可编译,无错误',
|
|
408
|
-
'代码符合项目规范',
|
|
409
|
-
'必要的注释已添加'
|
|
410
|
-
];
|
|
411
|
-
if (userContext.testCoverage) {
|
|
412
|
-
criteria.push(`测试覆盖率 >= ${userContext.testCoverage}`);
|
|
413
|
-
}
|
|
414
|
-
if (userContext.techStack?.length) {
|
|
415
|
-
criteria.push(`使用指定技术栈: ${userContext.techStack.join(', ')}`);
|
|
416
|
-
}
|
|
417
|
-
criteria.push('无安全隐患');
|
|
418
|
-
criteria.push('边界情况已处理');
|
|
419
|
-
return criteria;
|
|
420
|
-
}
|
|
421
163
|
generateTaskId() {
|
|
422
164
|
const timestamp = Date.now().toString(36).toUpperCase();
|
|
423
165
|
const rand = Math.random().toString(36).slice(2, 4).toUpperCase();
|
|
424
166
|
return `TASK-${timestamp}${rand}`;
|
|
425
167
|
}
|
|
426
|
-
determinePriority(goalIndex) {
|
|
427
|
-
// First goal is highest priority
|
|
428
|
-
if (goalIndex === 0)
|
|
429
|
-
return 'P1';
|
|
430
|
-
return 'P2';
|
|
431
|
-
}
|
|
432
|
-
estimateComplexity(goal) {
|
|
433
|
-
if (goal.includes('测试'))
|
|
434
|
-
return 'medium';
|
|
435
|
-
if (goal.includes('实现') || goal.includes('开发'))
|
|
436
|
-
return 'medium';
|
|
437
|
-
if (goal.includes('设计') || goal.includes('研究'))
|
|
438
|
-
return 'high';
|
|
439
|
-
if (goal.includes('文档') || goal.includes('说明'))
|
|
440
|
-
return 'low';
|
|
441
|
-
return 'medium';
|
|
442
|
-
}
|
|
443
168
|
}
|
|
444
169
|
exports.TaskPlanner = TaskPlanner;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openmatrix",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
4
4
|
"description": "AI Agent task orchestration system with Claude Code Skills integration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"chalk": "^5.6.2",
|
|
44
44
|
"chokidar": "^5.0.0",
|
|
45
45
|
"commander": "^14.0.3",
|
|
46
|
+
"openmatrix": "^0.1.42",
|
|
46
47
|
"typescript": "^5.3.3",
|
|
47
48
|
"winston": "^3.19.0"
|
|
48
49
|
},
|