implement-task.ts•3.81 kB
import { Prompt, PromptMessage } from '@modelcontextprotocol/sdk/types.js';
import { PromptDefinition } from './types.js';
import { ToolContext } from '../types.js';
const prompt: Prompt = {
name: 'implement-task',
title: 'Implement Specification Task',
description: 'Guide for implementing a specific task from the tasks.md document. Provides comprehensive instructions for task execution, including reading _Prompt fields, marking progress, and completion criteria.',
arguments: [
{
name: 'specName',
description: 'Feature name in kebab-case for the task to implement',
required: true
},
{
name: 'taskId',
description: 'Specific task ID to implement (e.g., "1", "2.1", "3")',
required: false
}
]
};
async function handler(args: Record<string, any>, context: ToolContext): Promise<PromptMessage[]> {
const { specName, taskId } = args;
if (!specName) {
throw new Error('specName is a required argument');
}
const messages: PromptMessage[] = [
{
role: 'user',
content: {
type: 'text',
text: `Implement ${taskId ? `task ${taskId}` : 'the next pending task'} for the "${specName}" feature.
**Context:**
- Project: ${context.projectPath}
- Feature: ${specName}
${taskId ? `- Task ID: ${taskId}` : ''}
${context.dashboardUrl ? `- Dashboard: ${context.dashboardUrl}` : ''}
**Implementation Workflow:**
1. **Check Current Status:**
- Use the spec-status tool with specName "${specName}" to see overall progress
- Read .spec-workflow/specs/${specName}/tasks.md to see all tasks
- Identify ${taskId ? `task ${taskId}` : 'the next pending task marked with [ ]'}
2. **Start the Task:**
- Edit .spec-workflow/specs/${specName}/tasks.md directly
- Change the task marker from [ ] to [-] for the task you're starting
- Only one task should be in-progress at a time
3. **Read Task Guidance:**
- Look for the _Prompt field in the task - it contains structured guidance:
- Role: The specialized developer role to assume
- Task: Clear description with context references
- Restrictions: What not to do and constraints
- Success: Specific completion criteria
- Note the _Leverage fields for files/utilities to use
- Check _Requirements fields for which requirements this implements
4. **Implement the Task:**
- Follow the _Prompt guidance exactly
- Use the files mentioned in _Leverage fields
- Create or modify the files specified in the task
- Write clean, well-commented code
- Follow existing patterns in the codebase
- Test your implementation thoroughly
5. **Complete the Task:**
- Verify all success criteria from the _Prompt are met
- Run any relevant tests to ensure nothing is broken
- Edit .spec-workflow/specs/${specName}/tasks.md directly
- Change the task marker from [-] to [x] for the completed task
- Only mark complete when fully implemented and tested
**Important Guidelines:**
- Always mark a task as in-progress before starting work
- Follow the _Prompt field guidance for role, approach, and success criteria
- Use existing patterns and utilities mentioned in _Leverage fields
- Test your implementation before marking the task complete
- If a task has subtasks (e.g., 4.1, 4.2), complete them in order
- If you encounter blockers, document them and move to another task
**Tools to Use:**
- spec-status: Check overall progress
- Edit: Directly update task markers in tasks.md file
- Read/Write/Edit: Implement the actual code changes
- Bash: Run tests and verify implementation
Please proceed with implementing ${taskId ? `task ${taskId}` : 'the next task'} following this workflow.`
}
}
];
return messages;
}
export const implementTaskPrompt: PromptDefinition = {
prompt,
handler
};