claudemaster
Version:
Task management MCP server optimized for Claude Code - no API keys required
321 lines (275 loc) • 10.2 kB
JavaScript
/**
* intelligent-task-management.js
* Smart task management tools optimized for Claude Code workflows
*/
import { z } from 'zod';
import TaskEngine from '../core/task-engine.js';
import { generateClaudePrompt } from '../core/claude-templates.js';
export function registerGetNextTaskTool(server) {
server.addTool({
name: 'get_next_task',
description: 'Get the next recommended task to work on, with intelligent context and suggestions for Claude Code.',
parameters: z.object({
projectRoot: z.string().describe('Absolute path to project root directory'),
includeContext: z.boolean().default(true).describe('Include additional context and suggestions')
}),
execute: async (args) => {
try {
const { projectRoot, includeContext } = args;
const taskEngine = new TaskEngine(projectRoot);
const nextTask = taskEngine.getNextTask();
const stats = taskEngine.getProjectStats();
if (!nextTask) {
return {
success: true,
message: 'No available tasks found',
reason: 'All tasks are either completed or blocked by dependencies',
suggestions: [
'Check if there are dependency issues using validate_dependencies',
'Add new tasks using claude_guided_task_creation',
'Review completed tasks to see if new work is needed'
],
projectStats: stats
};
}
const response = {
success: true,
nextTask,
projectStats: stats,
recommendations: {
action: 'start_task',
estimatedEffort: nextTask.priority === 'high' ? 'high' : 'medium',
preparationSteps: []
}
};
if (includeContext) {
// Add contextual information
const allTasks = taskEngine.listTasks();
const blockedTasks = allTasks.filter(t =>
t.status === 'pending' &&
t.dependencies &&
t.dependencies.length > 0 &&
!t.dependencies.every(depId => {
const dep = allTasks.find(dt => dt.id === depId);
return dep && dep.status === 'done';
})
);
response.context = {
totalTasks: allTasks.length,
blockedTasks: blockedTasks.length,
readyTasks: allTasks.filter(t => t.status === 'pending' &&
(!t.dependencies || t.dependencies.length === 0 ||
t.dependencies.every(depId => {
const dep = allTasks.find(dt => dt.id === depId);
return dep && dep.status === 'done';
}))).length
};
// Add preparation suggestions
if (nextTask.dependencies && nextTask.dependencies.length > 0) {
response.recommendations.preparationSteps.push('Review completed dependency tasks to understand context');
}
if (nextTask.details) {
response.recommendations.preparationSteps.push('Read the detailed implementation notes');
}
if (nextTask.subtasks && nextTask.subtasks.length > 0) {
response.recommendations.preparationSteps.push('Review existing subtasks before starting');
} else if (nextTask.priority === 'high' || (nextTask.details && nextTask.details.length > 200)) {
response.recommendations.preparationSteps.push('Consider breaking this task into subtasks');
}
}
return response;
} catch (error) {
return {
success: false,
error: error.message
};
}
}
});
}
export function registerAnalyzeProjectComplexityTool(server) {
server.addTool({
name: 'analyze_project_complexity',
description: 'Analyze project complexity and provide intelligent recommendations for task breakdown and project management.',
parameters: z.object({
projectRoot: z.string().describe('Absolute path to project root directory'),
includeRecommendations: z.boolean().default(true).describe('Include specific recommendations for improvement')
}),
execute: async (args) => {
try {
const { projectRoot, includeRecommendations } = args;
const taskEngine = new TaskEngine(projectRoot);
const tasks = taskEngine.listTasks();
const stats = taskEngine.getProjectStats();
const dependencies = taskEngine.validateDependencies();
// Basic complexity analysis
const complexityAnalysis = {
projectSize: tasks.length > 20 ? 'large' : tasks.length > 10 ? 'medium' : 'small',
dependencyComplexity: dependencies.length > 0 ? 'high' :
tasks.some(t => t.dependencies && t.dependencies.length > 2) ? 'medium' : 'low',
taskComplexity: 'unknown', // Will be determined by Claude Code
estimatedEffort: calculateEstimatedEffort(tasks)
};
const response = {
success: true,
analysis: complexityAnalysis,
projectStats: stats,
dependencyIssues: dependencies,
tasks: tasks.map(t => ({
id: t.id,
title: t.title,
description: t.description,
details: t.details,
subtaskCount: t.subtasks ? t.subtasks.length : 0,
dependencyCount: t.dependencies ? t.dependencies.length : 0
}))
};
if (includeRecommendations) {
// Generate prompt for Claude Code analysis
const prompt = generateClaudePrompt('COMPLEXITY_ANALYSIS', tasks);
response.claudeInstructions = {
systemPrompt: prompt.system,
userPrompt: prompt.user,
nextSteps: [
'Analyze the complexity of each task',
'Identify tasks that should be broken down',
'Use claude_guided_task_expansion for complex tasks',
'Update task priorities based on complexity analysis'
]
};
response.recommendations = generateRecommendations(tasks, stats, dependencies);
}
return response;
} catch (error) {
return {
success: false,
error: error.message
};
}
}
});
}
export function registerProjectHealthCheckTool(server) {
server.addTool({
name: 'project_health_check',
description: 'Comprehensive project health analysis with actionable insights for Claude Code.',
parameters: z.object({
projectRoot: z.string().describe('Absolute path to project root directory')
}),
execute: async (args) => {
try {
const { projectRoot } = args;
const taskEngine = new TaskEngine(projectRoot);
const tasks = taskEngine.listTasks();
const stats = taskEngine.getProjectStats();
const dependencies = taskEngine.validateDependencies();
// Health scoring
const health = calculateProjectHealth(tasks, stats, dependencies);
// Generate comprehensive analysis prompt for Claude Code
const prompt = generateClaudePrompt('PROJECT_ANALYSIS', tasks, stats, dependencies);
return {
success: true,
healthScore: health.score,
healthGrade: health.grade,
issues: health.issues,
recommendations: health.recommendations,
projectStats: stats,
claudeInstructions: {
systemPrompt: prompt.system,
userPrompt: prompt.user,
analysisType: 'comprehensive_project_health'
},
nextActions: prioritizeNextActions(health.issues, tasks)
};
} catch (error) {
return {
success: false,
error: error.message
};
}
}
});
}
function calculateEstimatedEffort(tasks) {
const total = tasks.length;
const high = tasks.filter(t => t.priority === 'high').length;
const withSubtasks = tasks.filter(t => t.subtasks && t.subtasks.length > 0).length;
if (high > total * 0.5 || withSubtasks > total * 0.3) {
return 'high';
} else if (high > total * 0.3 || withSubtasks > total * 0.2) {
return 'medium';
}
return 'low';
}
function generateRecommendations(tasks, stats, dependencies) {
const recommendations = [];
if (dependencies.length > 0) {
recommendations.push({
type: 'critical',
message: 'Fix dependency issues before proceeding',
action: 'Use validate_dependencies and fix_dependencies tools'
});
}
if (stats.pending > 10) {
recommendations.push({
type: 'organization',
message: 'Consider grouping or prioritizing pending tasks',
action: 'Review task priorities and consider creating epics'
});
}
const tasksWithoutDetails = tasks.filter(t => !t.details || t.details.length < 50);
if (tasksWithoutDetails.length > tasks.length * 0.3) {
recommendations.push({
type: 'planning',
message: 'Many tasks lack detailed implementation notes',
action: 'Use claude_guided_implementation_planning for unclear tasks'
});
}
return recommendations;
}
function calculateProjectHealth(tasks, stats, dependencies) {
let score = 100;
const issues = [];
const recommendations = [];
// Dependency issues
if (dependencies.length > 0) {
score -= dependencies.length * 10;
issues.push('Broken dependencies detected');
recommendations.push('Fix dependency issues immediately');
}
// Task completion rate
if (stats.completion < 30 && stats.total > 5) {
score -= 20;
issues.push('Low completion rate');
recommendations.push('Focus on completing existing tasks');
}
// Task organization
const tasksWithoutDetails = tasks.filter(t => !t.details || t.details.length < 20).length;
if (tasksWithoutDetails > tasks.length * 0.4) {
score -= 15;
issues.push('Many tasks lack detailed descriptions');
recommendations.push('Add implementation details to unclear tasks');
}
// Priority distribution
const highPriorityTasks = tasks.filter(t => t.priority === 'high').length;
if (highPriorityTasks > tasks.length * 0.6) {
score -= 10;
issues.push('Too many high-priority tasks');
recommendations.push('Review and rebalance task priorities');
}
const grade = score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : score >= 60 ? 'D' : 'F';
return { score, grade, issues, recommendations };
}
function prioritizeNextActions(issues, tasks) {
const actions = [];
if (issues.includes('Broken dependencies detected')) {
actions.push({ priority: 'critical', action: 'fix_dependencies', description: 'Fix broken task dependencies' });
}
if (issues.includes('Many tasks lack detailed descriptions')) {
actions.push({ priority: 'high', action: 'add_implementation_details', description: 'Add details to unclear tasks' });
}
if (issues.includes('Low completion rate')) {
actions.push({ priority: 'medium', action: 'focus_on_completion', description: 'Focus on completing in-progress tasks' });
}
return actions;
}