| name | th-workflow-decision-engine |
| description | PRD驱动工作流的决策大脑 - 智能判断何时使用搜索、代码分析、多模型聚合。 作为子Skill被 th-prd-driven-dev-workflow 调用,负责工具选择和策略决策。 |
| triggers | ["工作流决策","智能工具选择","需要搜索吗","需要代码分析吗"] |
Workflow Decision Engine - 工作流决策大脑
智能决策何时使用搜索、GitNexus分析、多模型聚合
决策框架
决策输入
interface DecisionContext {
phase: number;
task: string;
context?: {
code?: string;
error?: string;
prd?: string;
files?: string[];
};
history?: string[];
}
决策输出
interface DecisionResult {
tools: string[];
priority: 'high' | 'medium' | 'low';
reasoning: string;
searchQuery?: string;
analysisTarget?: string;
}
决策规则
阶段1: 项目分析
| 场景 | 决策 | 工具 |
|---|
| 新技术/框架 | 搜索 + 多模型聚合 | unified-search, th-model-compare-search |
| 已有PRD | 直接分析 | Read |
| 需求模糊 | 搜索竞品 | unified-search |
阶段2: 多模型需求分析
自动触发 th-model-compare-search - 无需决策
阶段3: Kimi深度整合
自动触发 kimi-cli - 无需决策
阶段4: PRD更新
自动触发 requirement-to-prd - 无需决策
阶段5: 代码审查准备
function decideCodeReview(context) {
const tools = ['codebundle'];
if (context.files?.length > 5 || context.hasSharedCode) {
tools.push('th-gitnexus-assistant');
}
if (context.hasExternalDeps) {
tools.push('unified-search');
}
tools.push('th-model-compare-search');
return { tools, priority: 'high' };
}
阶段6: 代码开发
| 场景 | 决策 |
|---|
| Bug修复 | th-gitnexus-assistant (影响分析) → prd-to-code |
| 新功能 | unified-search (最佳实践) → prd-to-code |
| 复杂算法 | th-deep-coder2 → prd-to-code |
阶段7: 自动化测试
function decideOnTestFailure(error, context) {
const tools = [];
const errorMsg = error.toLowerCase();
if (errorMsg.includes('network') || errorMsg.includes('api') || errorMsg.includes('timeout')) {
tools.push('unified-search');
}
if (errorMsg.includes('undefined') || errorMsg.includes('null') || errorMsg.includes('type')) {
tools.push('th-gitnexus-assistant');
}
if (tools.length === 0 || errorMsg.includes('race') || errorMsg.includes('deadlock')) {
tools.push('th-model-compare-search');
}
return {
tools,
priority: 'high',
reasoning: '基于错误类型智能选择修复策略'
};
}
工具选择矩阵
| 问题类型 | 首选工具 | 备选工具 | 理由 |
|---|
| 需要最新信息 | unified-search | web-fetch | 联网获取最新文档 |
| 代码影响分析 | th-gitnexus-assistant | mcp__gitnexus__impact | 知识图谱分析 |
| 复杂问题诊断 | th-model-compare-search | th-deep-coder2 | 多模型聚合 |
| 代码实现 | prd-to-code | Agent | PRD驱动开发 |
| 安全审查 | th-gitnexus-assistant + security-reviewer | - | 代码图谱+专业审查 |
决策执行示例
示例1: 测试失败决策
const context = {
phase: 7,
task: "修复测试失败",
context: {
error: "WebSocket connection timeout",
stack: "...",
files: ["src/websocket/handler.ts"]
}
};
await Skill({
name: "th-workflow-decision-engine",
args: JSON.stringify(context)
});
{
tools: ['unified-search', 'th-model-compare-search'],
priority: 'high',
reasoning: 'WebSocket超时错误可能涉及网络配置或代码逻辑,先搜索最佳实践,再用多模型诊断',
searchQuery: 'WebSocket connection timeout Node.js 解决方案'
}
示例2: Bug修复决策
const context = {
phase: 6,
task: "修复竞态条件bug",
context: {
error: "connection already exists",
files: ["src/connection/manager.ts", "src/websocket/handler.ts"]
}
};
{
tools: ['th-gitnexus-assistant', 'th-deep-coder2', 'prd-to-code'],
priority: 'high',
reasoning: '竞态条件需要代码影响分析确定修复范围,再用深度代码分析找出根因',
analysisTarget: "connection manager race condition"
}
集成到 Workflow
在阶段5(代码审查)中调用
const reviewDecision = await Skill({
name: "th-workflow-decision-engine",
args: JSON.stringify({
phase: 5,
task: "代码审查",
context: { files: changedFiles }
})
});
if (reviewDecision.tools.includes('th-gitnexus-assistant')) {
await analyzeImpactWithGitNexus();
}
if (reviewDecision.tools.includes('unified-search')) {
await searchBestPractices();
}
await Skill({ name: "th-model-compare-search", ... });
在阶段7(自动化测试)中调用
if (!testPassed) {
const fixDecision = await Skill({
name: "th-workflow-decision-engine",
args: JSON.stringify({
phase: 7,
task: "修复测试失败",
context: { error: testError }
})
});
for (const tool of fixDecision.tools) {
await Skill({ name: tool, ... });
}
}
降级策略
| 工具失败 | 降级到 | 说明 |
|---|
th-gitnexus-assistant | Grep + Read | 手动代码搜索 |
unified-search | web-fetch | 单源搜索 |
th-model-compare-search | kimi-cli | 单模型分析 |
th-deep-coder2 | code-reviewer Agent | 代码审查Agent |
版本: v1.0 | 决策大脑 for th-prd-driven-dev-workflow