@al76/tools-and-spec-workflow-mcp
Version:
MCP server for spec-driven development workflow with real-time web dashboard
161 lines (160 loc) • 6.02 kB
JavaScript
import { PathUtils } from '../core/path-utils.js';
import { SpecParser } from '../core/parser.js';
export const specStatusTool = {
name: 'spec-status',
description: `显示全面的规范进度概览。
# 说明
在恢复规范工作或检查整体完成状态时调用。显示哪些阶段已完成以及任务实现进度。在继续之前了解工作流中的位置很有用。`,
inputSchema: {
type: 'object',
properties: {
projectPath: {
type: 'string',
description: '项目根目录的绝对路径'
},
specName: {
type: 'string',
description: '规范名称'
}
},
required: ['projectPath', 'specName']
}
};
export async function specStatusHandler(args, context) {
const { projectPath, specName } = args;
try {
const parser = new SpecParser(projectPath);
const spec = await parser.getSpec(specName);
if (!spec) {
return {
success: false,
message: `规范 '${specName}' 未找到`,
nextSteps: [
'检查规范名称',
'使用 spec-list 查看可用规范',
'使用 create-spec-doc 创建规范'
]
};
}
// Determine current phase and overall status
let currentPhase = 'not-started';
let overallStatus = 'not-started';
if (!spec.phases.requirements.exists) {
currentPhase = 'requirements';
overallStatus = 'requirements-needed';
}
else if (!spec.phases.design.exists) {
currentPhase = 'design';
overallStatus = 'design-needed';
}
else if (!spec.phases.tasks.exists) {
currentPhase = 'tasks';
overallStatus = 'tasks-needed';
}
else if (spec.taskProgress && spec.taskProgress.pending > 0) {
currentPhase = 'implementation';
overallStatus = 'implementing';
}
else if (spec.taskProgress && spec.taskProgress.total > 0 && spec.taskProgress.completed === spec.taskProgress.total) {
currentPhase = 'completed';
overallStatus = 'completed';
}
else {
currentPhase = 'implementation';
overallStatus = 'ready-for-implementation';
}
// 阶段详情
const phaseDetails = [
{
name: '需求',
status: spec.phases.requirements.exists ? (spec.phases.requirements.approved ? '已批准' : '已创建') : '缺失',
lastModified: spec.phases.requirements.lastModified
},
{
name: '设计',
status: spec.phases.design.exists ? (spec.phases.design.approved ? '已批准' : '已创建') : '缺失',
lastModified: spec.phases.design.lastModified
},
{
name: '任务',
status: spec.phases.tasks.exists ? (spec.phases.tasks.approved ? '已批准' : '已创建') : '缺失',
lastModified: spec.phases.tasks.lastModified
},
{
name: '实现',
status: spec.phases.implementation.exists ? '进行中' : '未开始',
progress: spec.taskProgress
}
];
// 基于当前阶段的下一步操作
const nextSteps = [];
switch (currentPhase) {
case 'requirements':
nextSteps.push('创建 requirements.md');
nextSteps.push('使用 get-steering-context 加载上下文');
nextSteps.push('请求审批');
break;
case 'design':
nextSteps.push('创建 design.md');
nextSteps.push('参考需求');
nextSteps.push('请求审批');
break;
case 'tasks':
nextSteps.push('创建 tasks.md');
nextSteps.push('分解设计');
nextSteps.push('请求审批');
break;
case 'implementation':
if (spec.taskProgress && spec.taskProgress.pending > 0) {
nextSteps.push('使用 manage-tasks 和 next-pending');
nextSteps.push('实现任务');
nextSteps.push('使用 manage-tasks 更新状态');
}
else {
nextSteps.push('使用 manage-tasks 开始实现');
}
break;
case 'completed':
nextSteps.push('规范完成');
nextSteps.push('运行测试');
break;
}
return {
success: true,
message: `规范 '${specName}' 状态: ${overallStatus}`,
data: {
name: specName,
description: spec.description,
currentPhase,
overallStatus,
createdAt: spec.createdAt,
lastModified: spec.lastModified,
phases: phaseDetails,
taskProgress: spec.taskProgress || {
total: 0,
completed: 0,
pending: 0
}
},
nextSteps,
projectContext: {
projectPath,
workflowRoot: PathUtils.getWorkflowRoot(projectPath),
currentPhase,
dashboardUrl: context.dashboardUrl
}
};
}
catch (error) {
return {
success: false,
message: `获取规范状态失败: ${error.message}`,
nextSteps: [
'检查规范是否存在',
'验证项目路径',
'使用 spec-list 查看可用规范'
]
};
}
}
//# sourceMappingURL=spec-status.js.map