918bbed0fc
- 修复 deps.py 中 get_vn_service 的引用错误 (vn_service.vn_service -> vn_service) - 移除登录页面上的明文密码提示 - 改进前端错误处理,避免数据加载失败导致登录显示错误
421 lines
9.2 KiB
JavaScript
421 lines
9.2 KiB
JavaScript
/**
|
|
* Superpowers 集成层
|
|
*
|
|
* 实现 Superpowers 五技能体系的调用集成
|
|
*/
|
|
|
|
/**
|
|
* Superpowers 五阶段枚举
|
|
*/
|
|
export const SuperpowersPhase = {
|
|
WRITING_PLANS: 'writing-plans',
|
|
EXECUTING_PLANS: 'executing-plans',
|
|
REQUESTING_CODE_REVIEW: 'requesting-code-review',
|
|
SYSTEMATIC_DEBUGGING: 'systematic-debugging',
|
|
FINISHING_DEVELOPMENT: 'finishing-a-development-branch'
|
|
}
|
|
|
|
/**
|
|
* Superpowers 集成类
|
|
*/
|
|
export class SuperpowersIntegration {
|
|
constructor() {
|
|
this.currentPhase = null
|
|
this.phaseHistory = []
|
|
}
|
|
|
|
/**
|
|
* 调用 writing-plans
|
|
*
|
|
* @param {Object} context - 上下文信息
|
|
* @returns {Promise<Object>} 规划结果
|
|
*/
|
|
async invokeWritingPlans(context) {
|
|
this.setPhase(SuperpowersPhase.WRITING_PLANS)
|
|
log('📝 调用 writing-plans...')
|
|
|
|
try {
|
|
const prompt = this.generateWritingPlansPrompt(context)
|
|
const plan = await this.callSkill('writing-plans', prompt, context)
|
|
|
|
log('✅ writing-plans 完成')
|
|
return plan
|
|
} catch (error) {
|
|
log(`❌ writing-plans 失败: ${error.message}`)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 调用 executing-plans
|
|
*
|
|
* @param {Object} plan - 执行计划
|
|
* @returns {Promise<Object>} 执行结果
|
|
*/
|
|
async invokeExecutingPlans(plan) {
|
|
this.setPhase(SuperpowersPhase.EXECUTING_PLANS)
|
|
log('⚡ 调用 executing-plans...')
|
|
|
|
try {
|
|
const prompt = this.generateExecutingPlansPrompt(plan)
|
|
const result = await this.callSkill('executing-plans', prompt, { plan })
|
|
|
|
log('✅ executing-plans 完成')
|
|
return result
|
|
} catch (error) {
|
|
log(`❌ executing-plans 失败: ${error.message}`)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 调用 requesting-code-review
|
|
*
|
|
* @param {Object} code - 代码信息
|
|
* @returns {Promise<Object>} 审查结果
|
|
*/
|
|
async invokeRequestingCodeReview(code) {
|
|
this.setPhase(SuperpowersPhase.REQUESTING_CODE_REVIEW)
|
|
log('🔍 调用 requesting-code-review...')
|
|
|
|
try {
|
|
const prompt = this.generateCodeReviewPrompt(code)
|
|
const review = await this.callSkill('requesting-code-review', prompt, { code })
|
|
|
|
log('✅ requesting-code-review 完成')
|
|
return review
|
|
} catch (error) {
|
|
log(`❌ requesting-code-review 失败: ${error.message}`)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 调用 systematic-debugging
|
|
*
|
|
* @param {Object} issue - 问题信息
|
|
* @returns {Promise<Object>} 调试结果
|
|
*/
|
|
async invokeSystematicDebugging(issue) {
|
|
this.setPhase(SuperpowersPhase.SYSTEMATIC_DEBUGGING)
|
|
log('🐛 调用 systematic-debugging...')
|
|
|
|
try {
|
|
const prompt = this.generateDebuggingPrompt(issue)
|
|
const result = await this.callSkill('systematic-debugging', prompt, { issue })
|
|
|
|
log('✅ systematic-debugging 完成')
|
|
return result
|
|
} catch (error) {
|
|
log(`❌ systematic-debugging 失败: ${error.message}`)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 调用 finishing-a-development-branch
|
|
*
|
|
* @param {Object} context - 上下文信息
|
|
* @returns {Promise<Object>} 完成结果
|
|
*/
|
|
async invokeFinishingDevelopment(context) {
|
|
this.setPhase(SuperpowersPhase.FINISHING_DEVELOPMENT)
|
|
log('🏁 调用 finishing-a-development-branch...')
|
|
|
|
try {
|
|
const prompt = this.generateFinishingPrompt(context)
|
|
const result = await this.callSkill('finishing-a-development-branch', prompt, context)
|
|
|
|
log('✅ finishing-a-development-branch 完成')
|
|
return result
|
|
} catch (error) {
|
|
log(`❌ finishing-a-development-branch 失败: ${error.message}`)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 执行完整的五阶段工作流
|
|
*
|
|
* @param {Object} context - 初始上下文
|
|
* @returns {Promise<Object>} 完整工作流结果
|
|
*/
|
|
async runFullWorkflow(context) {
|
|
log('🚀 开始 Superpowers 五阶段工作流...')
|
|
|
|
const results = {}
|
|
|
|
try {
|
|
// 阶段 1: 规划
|
|
results.plan = await this.invokeWritingPlans(context)
|
|
|
|
// 阶段 2: 执行
|
|
results.execution = await this.invokeExecutingPlans(results.plan)
|
|
|
|
// 阶段 3: 审查
|
|
results.review = await this.invokeRequestingCodeReview(results.execution)
|
|
|
|
// 如果审查未通过,进入调试
|
|
if (results.review && !results.review.passed) {
|
|
log('⚠️ 审查未通过,进入调试阶段...')
|
|
results.debugging = await this.invokeSystematicDebugging({
|
|
review: results.review,
|
|
execution: results.execution
|
|
})
|
|
}
|
|
|
|
// 阶段 5: 完成
|
|
results.finishing = await this.invokeFinishingDevelopment({
|
|
...context,
|
|
...results
|
|
})
|
|
|
|
log('✅ Superpowers 五阶段工作流完成')
|
|
return results
|
|
} catch (error) {
|
|
log(`❌ 工作流中断: ${error.message}`)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 设置当前阶段
|
|
*/
|
|
setPhase(phase) {
|
|
if (this.currentPhase) {
|
|
this.phaseHistory.push(this.currentPhase)
|
|
}
|
|
this.currentPhase = phase
|
|
}
|
|
|
|
/**
|
|
* 获取当前阶段
|
|
*/
|
|
getPhase() {
|
|
return this.currentPhase
|
|
}
|
|
|
|
/**
|
|
* 获取阶段历史
|
|
*/
|
|
getPhaseHistory() {
|
|
return [...this.phaseHistory, this.currentPhase].filter(Boolean)
|
|
}
|
|
|
|
/**
|
|
* 生成 writing-plans 提示
|
|
*/
|
|
generateWritingPlansPrompt(context) {
|
|
return `
|
|
请编写一份综合实现计划,假设工程师对代码库零上下文。
|
|
|
|
## 上下文
|
|
${this.formatContext(context)}
|
|
|
|
## 要求
|
|
1. 任务背景和目标
|
|
2. 技术方案选择
|
|
3. 实施步骤
|
|
4. 验收标准
|
|
|
|
请提供详细的实现计划。
|
|
`
|
|
}
|
|
|
|
/**
|
|
* 生成 executing-plans 提示
|
|
*/
|
|
generateExecutingPlansPrompt(plan) {
|
|
return `
|
|
请执行以下实现计划:
|
|
|
|
## 计划
|
|
${this.formatContext(plan)}
|
|
|
|
## 要求
|
|
1. 按照计划实施
|
|
2. 编写完整的单元测试
|
|
3. 确保代码质量
|
|
4. 提供实施结果
|
|
|
|
请开始执行。
|
|
`
|
|
}
|
|
|
|
/**
|
|
* 生成代码审查提示
|
|
*/
|
|
generateCodeReviewPrompt(code) {
|
|
return `
|
|
请审查以下代码:
|
|
|
|
## 代码信息
|
|
${this.formatContext(code)}
|
|
|
|
## 审查维度
|
|
1. 逻辑正确性和边界情况
|
|
2. 安全漏洞
|
|
3. 性能影响
|
|
4. 测试覆盖率
|
|
5. 错误处理
|
|
|
|
请提供详细的审查结果。
|
|
`
|
|
}
|
|
|
|
/**
|
|
* 生成调试提示
|
|
*/
|
|
generateDebuggingPrompt(issue) {
|
|
return `
|
|
请系统化调试以下问题:
|
|
|
|
## 问题描述
|
|
${this.formatContext(issue)}
|
|
|
|
## 要求
|
|
1. 系统化定位问题(而非随机尝试)
|
|
2. 分析根本原因
|
|
3. 设计验证方案
|
|
4. 提供修复建议
|
|
|
|
请开始调试。
|
|
`
|
|
}
|
|
|
|
/**
|
|
* 生成完成提示
|
|
*/
|
|
generateFinishingPrompt(context) {
|
|
return `
|
|
请完成开发分支的收尾工作:
|
|
|
|
## 上下文
|
|
${this.formatContext(context)}
|
|
|
|
## 要求
|
|
1. 确认所有测试通过
|
|
2. 验证代码质量
|
|
3. 准备提交
|
|
4. 清理临时文件
|
|
|
|
请完成收尾工作。
|
|
`
|
|
}
|
|
|
|
/**
|
|
* 格式化上下文
|
|
*/
|
|
formatContext(context) {
|
|
if (typeof context === 'string') {
|
|
return context
|
|
}
|
|
return JSON.stringify(context, null, 2)
|
|
}
|
|
|
|
/**
|
|
* 调用 Skill
|
|
*/
|
|
async callSkill(skillName, prompt, context) {
|
|
try {
|
|
// 使用 Skill 工具调用
|
|
const result = await Skill({
|
|
skill: skillName,
|
|
args: JSON.stringify({ prompt, context })
|
|
})
|
|
|
|
return result
|
|
} catch (error) {
|
|
// 如果 Skill 工具不可用,使用 Agent 作为回退
|
|
log(`⚠️ Skill 工具不可用,使用 Agent 作为回退`)
|
|
return await this.fallbackToAgent(skillName, prompt, context)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 回退到 Agent
|
|
*/
|
|
async fallbackToAgent(skillName, prompt, context) {
|
|
const fullPrompt = `
|
|
作为 ${skillName} 专家,执行以下任务:
|
|
|
|
${prompt}
|
|
|
|
请返回结构化的 JSON 结果。
|
|
`
|
|
|
|
return await agent({
|
|
subagent_type: 'general-purpose',
|
|
prompt: fullPrompt
|
|
})
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 创建 Superpowers 集成实例
|
|
*/
|
|
export function createSuperpowersIntegration() {
|
|
return new SuperpowersIntegration()
|
|
}
|
|
|
|
/**
|
|
* 快速函数:调用 writing-plans
|
|
*/
|
|
export async function invokeWritingPlans(context) {
|
|
const integration = createSuperpowersIntegration()
|
|
return await integration.invokeWritingPlans(context)
|
|
}
|
|
|
|
/**
|
|
* 快速函数:调用 executing-plans
|
|
*/
|
|
export async function invokeExecutingPlans(plan) {
|
|
const integration = createSuperpowersIntegration()
|
|
return await integration.invokeExecutingPlans(plan)
|
|
}
|
|
|
|
/**
|
|
* 快速函数:调用 requesting-code-review
|
|
*/
|
|
export async function invokeRequestingCodeReview(code) {
|
|
const integration = createSuperpowersIntegration()
|
|
return await integration.invokeRequestingCodeReview(code)
|
|
}
|
|
|
|
/**
|
|
* 快速函数:调用 systematic-debugging
|
|
*/
|
|
export async function invokeSystematicDebugging(issue) {
|
|
const integration = createSuperpowersIntegration()
|
|
return await integration.invokeSystematicDebugging(issue)
|
|
}
|
|
|
|
/**
|
|
* 快速函数:调用 finishing-a-development-branch
|
|
*/
|
|
export async function invokeFinishingDevelopment(context) {
|
|
const integration = createSuperpowersIntegration()
|
|
return await integration.invokeFinishingDevelopment(context)
|
|
}
|
|
|
|
/**
|
|
* 辅助函数:日志输出
|
|
*/
|
|
function log(message) {
|
|
console.log(`[Superpowers] ${message}`)
|
|
}
|
|
|
|
/**
|
|
* 导出
|
|
*/
|
|
export default {
|
|
SuperpowersIntegration,
|
|
createSuperpowersIntegration,
|
|
invokeWritingPlans,
|
|
invokeExecutingPlans,
|
|
invokeRequestingCodeReview,
|
|
invokeSystematicDebugging,
|
|
invokeFinishingDevelopment,
|
|
SuperpowersPhase
|
|
}
|