UNPKG

@al76/tools-and-spec-workflow-mcp

Version:

MCP server for spec-driven development workflow with real-time web dashboard

128 lines (127 loc) 4.85 kB
import { PathUtils } from '../core/path-utils.js'; import { SpecParser } from '../core/parser.js'; export const specListTool = { name: 'spec-list', description: `列出项目中的所有规范。 # 说明 在选择要处理的规范之前调用以查看可用规范。显示每个规范的状态,包括阶段完成情况。对于选择要实现或继续处理的规范很有用。`, inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: '项目根目录的绝对路径' } }, required: ['projectPath'] } }; export async function specListHandler(args, context) { const { projectPath } = args; try { const parser = new SpecParser(projectPath); const specs = await parser.getAllSpecs(); if (specs.length === 0) { const response = { success: true, message: '未找到规范', data: { specs: [], total: 0 }, nextSteps: [ '使用 spec-create 创建新规范', '示例: spec-create user-authentication "用户登录和注册"' ], projectContext: { projectPath, workflowRoot: PathUtils.getWorkflowRoot(projectPath), dashboardUrl: context.dashboardUrl } }; return response; } // Format specs for display const formattedSpecs = specs.map(spec => { const phaseCount = Object.values(spec.phases).filter(p => p.exists).length; const completedPhases = Object.entries(spec.phases) .filter(([_, phase]) => phase.exists && phase.approved) .map(([name]) => name); let status = '未开始'; if (phaseCount === 0) { status = '未开始'; } else if (phaseCount < 3) { status = '进行中'; } else if (completedPhases.length === 3) { status = '准备实现'; } else if (spec.taskProgress && spec.taskProgress.completed > 0) { status = '实现中'; } else { status = '准备实现'; } if (spec.taskProgress && spec.taskProgress.completed === spec.taskProgress.total && spec.taskProgress.total > 0) { status = '已完成'; } return { name: spec.name, description: spec.description, status, phases: { requirements: spec.phases.requirements.exists, design: spec.phases.design.exists, tasks: spec.phases.tasks.exists, implementation: spec.phases.implementation.exists }, taskProgress: spec.taskProgress, lastModified: spec.lastModified, createdAt: spec.createdAt }; }); // Summary statistics const statusCounts = formattedSpecs.reduce((acc, spec) => { acc[spec.status] = (acc[spec.status] || 0) + 1; return acc; }, {}); const response = { success: true, message: `找到 ${specs.length} 个规范`, data: { specs: formattedSpecs, total: specs.length, summary: { byStatus: statusCounts, totalTasks: formattedSpecs.reduce((sum, spec) => sum + (spec.taskProgress?.total || 0), 0), completedTasks: formattedSpecs.reduce((sum, spec) => sum + (spec.taskProgress?.completed || 0), 0) } }, nextSteps: [ '使用 spec-status <name> 查看特定规范的详细状态', '使用 spec-execute <task-id> <name> 继续实现', '使用 spec-create 创建新规范' ], projectContext: { projectPath, workflowRoot: PathUtils.getWorkflowRoot(projectPath), dashboardUrl: context.dashboardUrl } }; return response; } catch (error) { const errorResponse = { success: false, message: `列出规范失败: ${error.message}`, nextSteps: [ '检查项目路径是否存在', '验证 .spec-workflow 目录是否存在', '如果不存在,使用 spec-create 创建规范' ] }; return errorResponse; } } //# sourceMappingURL=spec-list.js.map