archive_completed_tasks
Move completed tasks to a specified archive file in the Memory Bank MCP Server, enabling organized project management and efficient task tracking.
Instructions
归档已完成任务
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| destination | No | 归档目标文件 | |
| projectId | Yes | 项目ID |
Implementation Reference
- src/mcp/tools.ts:1009-1095 (handler)The primary handler function implementing the logic to archive completed tasks. It parses the tasks markdown, identifies completed tasks under the '已完成任务' section, removes them from the main tasks doc, and creates a new archive document.export const archiveCompletedTasks = async (projectId: string, destination?: string) => { try { // 检查项目是否存在 const project = await projectStorage.getById(projectId); if (!project) throw new Error('项目不存在'); // 获取tasks文档 const docs = await documentStorage.getByProjectId(projectId); const tasksDoc = docs.find(d => d.type === 'tasks'); if (!tasksDoc) { throw new Error('任务文档不存在,请先运行van_verify初始化核心文档'); } // 解析文档内容 const lines = tasksDoc.content.split('\n'); const completedTasks = []; const remainingLines = []; let inCompletedSection = false; // 查找已完成任务部分,收集已完成的任务 for (let i = 0; i < lines.length; i++) { const line = lines[i]; // 检查是否进入已完成任务部分 if (line.match(/^##\s+已完成任务/)) { inCompletedSection = true; remainingLines.push(line); // 保留部分标题 continue; } // 检查是否离开已完成任务部分 if (inCompletedSection && line.match(/^##\s+/)) { inCompletedSection = false; } // 收集已完成的任务 if (inCompletedSection && line.trim().startsWith('- [x]')) { completedTasks.push(line); } else { remainingLines.push(line); } } // 如果没有找到已完成任务,返回 if (completedTasks.length === 0) { return { status: 'success', message: '没有找到已完成任务,无需归档', archivedTasks: 0 }; } // 更新任务文档,移除已归档的任务 const updatedTasksContent = remainingLines.join('\n'); await documentStorage.update(tasksDoc.id, updatedTasksContent); // 准备归档内容 const archiveDate = new Date().toISOString().split('T')[0]; const archiveTitle = `# 已归档任务 (${archiveDate})\n\n`; const archiveContent = archiveTitle + completedTasks.join('\n') + '\n'; // 确定归档目标 const archiveDestination = destination || `archived_tasks_${archiveDate}.md`; // 创建归档文档 await documentStorage.create( projectId, archiveDestination, archiveContent, 'archive_' + Date.now() ); return { status: 'success', message: '任务归档成功', archive: { archivedTasks: completedTasks.length, destination: archiveDestination, archivedAt: new Date().toISOString() } }; } catch (error) { console.error('归档已完成任务错误:', error); throw new Error('归档已完成任务失败'); } };
- src/mcp/server.ts:571-584 (schema)JSON schema defining the input parameters for the tool: required projectId (string) and optional destination (string).inputSchema: { type: 'object', properties: { projectId: { type: 'string', description: '项目ID', }, destination: { type: 'string', description: '归档目标文件', }, }, required: ['projectId'], }
- src/mcp/server.ts:900-907 (registration)MCP server request handler case that dispatches the tool call to the archiveCompletedTasks function from tools module, including parameter validation.case 'archive_completed_tasks': { if (!args.projectId) { throw new McpError(ErrorCode.InvalidParams, '项目ID不能为空'); } return this.formatResponse(await tools.archiveCompletedTasks( args.projectId as string, args.destination as string | undefined ));
- src/mcp/server.ts:568-584 (registration)Tool registration in the MCP server's tools list, specifying name, description, and input schema.{ name: 'archive_completed_tasks', description: '归档已完成任务', inputSchema: { type: 'object', properties: { projectId: { type: 'string', description: '项目ID', }, destination: { type: 'string', description: '归档目标文件', }, }, required: ['projectId'], }