| |
| |
| |
|
|
|
|
| const GitContextAnalyzer = require('./git-context-analyzer');
|
|
|
| class PriorityAnalyzer {
|
| constructor(projectRoot = process.cwd()) {
|
| this.weights = {
|
| severity: 0.30,
|
| impact: 0.25,
|
| complexity: 0.20,
|
| dependencies: 0.15,
|
| age: 0.10
|
| };
|
|
|
| this.severityScores = {
|
| CRITICAL: 100,
|
| HIGH: 75,
|
| MEDIUM: 50,
|
| LOW: 25,
|
| MINIMAL: 10
|
| };
|
|
|
|
|
| this.gitContext = new GitContextAnalyzer(projectRoot);
|
| }
|
|
|
| |
| |
|
|
| analyze(tasks) {
|
| const prioritizedTasks = tasks.map(task => {
|
|
|
| const enrichedTask = this.enrichTaskWithGitContext(task);
|
|
|
| const scores = {
|
| severity: this.calculateSeverityScore(enrichedTask),
|
| impact: this.calculateImpactScore(enrichedTask),
|
| complexity: this.calculateComplexityScore(enrichedTask),
|
| dependencies: this.calculateDependencyScore(enrichedTask),
|
| age: this.calculateAgeScore(enrichedTask)
|
| };
|
|
|
| const priority = this.calculatePriority(scores);
|
|
|
| return {
|
| ...enrichedTask,
|
| scores,
|
| priority,
|
| priorityLevel: this.getPriorityLevel(priority),
|
| recommendation: this.generateRecommendation(enrichedTask, scores, priority)
|
| };
|
| });
|
|
|
| return this.sortByPriority(prioritizedTasks);
|
| }
|
|
|
| |
| |
|
|
| enrichTaskWithGitContext(task) {
|
|
|
| if (!task.filePath || !task.line) {
|
| return task;
|
| }
|
|
|
| try {
|
| const gitAge = this.gitContext.getAnnotationAge(task.filePath, task.line);
|
|
|
| if (gitAge) {
|
| return {
|
| ...task,
|
| actualAge: gitAge.days,
|
| author: gitAge.author,
|
| lastModified: gitAge.date,
|
| gitContext: true
|
| };
|
| }
|
| } catch (error) {
|
|
|
| }
|
|
|
| return task;
|
| }
|
|
|
| |
| |
|
|
| calculateSeverityScore(task) {
|
|
|
| if (task.type === 'security') {
|
| return this.severityScores[task.severity] || 50;
|
| }
|
|
|
|
|
| if (task.type === 'bug') {
|
| if (task.severity === 'CRITICAL' || task.critical) return 100;
|
| if (task.severity === 'HIGH') return 75;
|
| if (task.severity === 'MEDIUM') return 50;
|
| return 25;
|
| }
|
|
|
|
|
| if (task.type === 'code-smell' || task.type === 'quality') {
|
| return this.severityScores[task.severity] || 30;
|
| }
|
|
|
|
|
| if (task.type === 'feature' || task.type === 'todo') {
|
| return 40;
|
| }
|
|
|
| return 25;
|
| }
|
|
|
| |
| |
|
|
| calculateImpactScore(task) {
|
| let score = 0;
|
|
|
|
|
| if (task.filesAffected) {
|
| score += Math.min(task.filesAffected * 5, 40);
|
| }
|
|
|
|
|
| if (task.linesAffected) {
|
| score += Math.min(task.linesAffected / 10, 30);
|
| }
|
|
|
|
|
| if (task.userFacing) {
|
| score += 30;
|
| }
|
|
|
|
|
| if (task.breaking) {
|
| score += 40;
|
| }
|
|
|
|
|
| if (task.module) {
|
| if (/(?:auth|security|payment|database)/i.test(task.module)) {
|
| score += 20;
|
| }
|
| }
|
|
|
| return Math.min(score, 100);
|
| }
|
|
|
| |
| |
| |
|
|
| calculateComplexityScore(task) {
|
| let score = 50;
|
|
|
|
|
| if (task.effort) {
|
| const effortMap = {
|
| 'XS': 90,
|
| 'S': 75,
|
| 'M': 50,
|
| 'L': 30,
|
| 'XL': 10
|
| };
|
| score = effortMap[task.effort] || 50;
|
| }
|
|
|
|
|
| if (task.complexity) {
|
| if (task.complexity > 20) score -= 30;
|
| else if (task.complexity > 10) score -= 15;
|
| }
|
|
|
|
|
| if (task.blockedBy && task.blockedBy.length > 0) {
|
| score -= (task.blockedBy.length * 10);
|
| }
|
|
|
|
|
| if (task.type === 'tech-debt') {
|
| score += 20;
|
| }
|
|
|
| return Math.max(0, Math.min(100, score));
|
| }
|
|
|
| |
| |
| |
|
|
| calculateDependencyScore(task) {
|
| let score = 0;
|
|
|
|
|
| if (task.blocks && task.blocks.length > 0) {
|
| score += task.blocks.length * 20;
|
| }
|
|
|
|
|
| if (task.dependents) {
|
| score += Math.min(task.dependents * 5, 50);
|
| }
|
|
|
|
|
| if (task.criticalPath) {
|
| score += 50;
|
| }
|
|
|
| return Math.min(score, 100);
|
| }
|
|
|
| |
| |
| |
| |
|
|
| calculateAgeScore(task) {
|
|
|
| if (task.actualAge !== undefined) {
|
| const daysOld = task.actualAge;
|
|
|
| if (daysOld > 180) return 100;
|
| if (daysOld > 90) return 75;
|
| if (daysOld > 30) return 50;
|
| if (daysOld > 7) return 25;
|
| return 10;
|
| }
|
|
|
|
|
| if (!task.createdAt && !task.age) return 25;
|
|
|
| let daysOld = 0;
|
|
|
| if (task.age) {
|
| daysOld = task.age;
|
| } else if (task.createdAt) {
|
| const created = new Date(task.createdAt);
|
| const now = new Date();
|
| daysOld = Math.floor((now - created) / (1000 * 60 * 60 * 24));
|
| }
|
|
|
|
|
| if (daysOld > 180) return 100;
|
| if (daysOld > 90) return 75;
|
| if (daysOld > 30) return 50;
|
| if (daysOld > 7) return 25;
|
| return 10;
|
| }
|
|
|
| |
| |
|
|
| calculatePriority(scores) {
|
| let priority = 0;
|
|
|
| priority += scores.severity * this.weights.severity;
|
| priority += scores.impact * this.weights.impact;
|
| priority += scores.complexity * this.weights.complexity;
|
| priority += scores.dependencies * this.weights.dependencies;
|
| priority += scores.age * this.weights.age;
|
|
|
| return Math.round(priority);
|
| }
|
|
|
| |
| |
|
|
| getPriorityLevel(priority) {
|
| if (priority >= 80) return 'CRITICAL';
|
| if (priority >= 60) return 'HIGH';
|
| if (priority >= 40) return 'MEDIUM';
|
| if (priority >= 20) return 'LOW';
|
| return 'MINIMAL';
|
| }
|
|
|
| |
| |
|
|
| generateRecommendation(task, scores, priority) {
|
| const recommendations = [];
|
|
|
|
|
| if (priority >= 80) {
|
| recommendations.push('Address immediately');
|
|
|
| if (scores.severity > 75) {
|
| recommendations.push('High severity - production risk');
|
| }
|
| if (scores.impact > 75) {
|
| recommendations.push('Wide impact - affects many users/files');
|
| }
|
| if (scores.dependencies > 75) {
|
| recommendations.push('Blocking other tasks');
|
| }
|
| }
|
|
|
|
|
| else if (priority >= 60) {
|
| recommendations.push('Schedule for current sprint');
|
|
|
| if (scores.complexity > 60) {
|
| recommendations.push('Relatively easy fix - quick win');
|
| }
|
| if (scores.age > 60) {
|
| recommendations.push('Long-standing issue - address soon');
|
| }
|
| }
|
|
|
|
|
| else if (priority >= 40) {
|
| recommendations.push('Plan for next sprint');
|
|
|
| if (scores.complexity < 40) {
|
| recommendations.push('Complex - may need team discussion');
|
| }
|
| }
|
|
|
|
|
| else {
|
| recommendations.push('Backlog - address when capacity allows');
|
|
|
| if (task.type === 'tech-debt') {
|
| recommendations.push('Technical debt - consider during refactoring');
|
| }
|
| }
|
|
|
|
|
| if (scores.complexity > 70) {
|
| recommendations.push('Estimated effort: Small (1-2 hours)');
|
| } else if (scores.complexity > 40) {
|
| recommendations.push('Estimated effort: Medium (3-8 hours)');
|
| } else {
|
| recommendations.push('Estimated effort: Large (1-3 days)');
|
| }
|
|
|
| return recommendations;
|
| }
|
|
|
| |
| |
|
|
| sortByPriority(tasks) {
|
| return tasks.sort((a, b) => {
|
|
|
| if (b.priority !== a.priority) {
|
| return b.priority - a.priority;
|
| }
|
|
|
|
|
| const severityOrder = { CRITICAL: 5, HIGH: 4, MEDIUM: 3, LOW: 2, MINIMAL: 1 };
|
| return (severityOrder[b.priorityLevel] || 0) - (severityOrder[a.priorityLevel] || 0);
|
| });
|
| }
|
|
|
| |
| |
|
|
| generateReport(prioritizedTasks) {
|
| const summary = {
|
| totalTasks: prioritizedTasks.length,
|
| priorityDistribution: {
|
| CRITICAL: 0,
|
| HIGH: 0,
|
| MEDIUM: 0,
|
| LOW: 0,
|
| MINIMAL: 0
|
| },
|
| typeDistribution: {},
|
| topPriorities: [],
|
| quickWins: [],
|
| blockers: [],
|
| averageAge: 0
|
| };
|
|
|
| let totalAge = 0;
|
|
|
| prioritizedTasks.forEach(task => {
|
|
|
| summary.priorityDistribution[task.priorityLevel]++;
|
|
|
|
|
| summary.typeDistribution[task.type] = (summary.typeDistribution[task.type] || 0) + 1;
|
|
|
|
|
| if (task.scores.age) {
|
| totalAge += task.scores.age;
|
| }
|
| });
|
|
|
| summary.averageAge = prioritizedTasks.length > 0
|
| ? Math.round(totalAge / prioritizedTasks.length)
|
| : 0;
|
|
|
|
|
| summary.topPriorities = prioritizedTasks
|
| .slice(0, 10)
|
| .map(t => ({
|
| title: t.title || t.message,
|
| priority: t.priority,
|
| priorityLevel: t.priorityLevel,
|
| type: t.type
|
| }));
|
|
|
|
|
| summary.quickWins = prioritizedTasks
|
| .filter(t => t.priority >= 60 && t.scores.complexity >= 70)
|
| .slice(0, 5)
|
| .map(t => ({
|
| title: t.title || t.message,
|
| priority: t.priority,
|
| effort: 'Small'
|
| }));
|
|
|
|
|
| summary.blockers = prioritizedTasks
|
| .filter(t => t.scores.dependencies >= 50)
|
| .slice(0, 5)
|
| .map(t => ({
|
| title: t.title || t.message,
|
| priority: t.priority,
|
| blocks: t.blocks ? t.blocks.length : 0
|
| }));
|
|
|
| return summary;
|
| }
|
| }
|
|
|
| module.exports = PriorityAnalyzer;
|
|
|