From fdbb25e185301e0f2b54935d44bdf0fa0bb717d7 Mon Sep 17 00:00:00 2001 From: Shrey Paharia Date: Wed, 23 Apr 2025 21:25:42 +0530 Subject: [PATCH] fix: fixed next cli command handling --- scripts/modules/task-manager.js | 7 +++++-- scripts/modules/ui.js | 8 +++++++- scripts/modules/utils.js | 25 +++++++++++-------------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/scripts/modules/task-manager.js b/scripts/modules/task-manager.js index 0141eb3d..99e4cb48 100644 --- a/scripts/modules/task-manager.js +++ b/scripts/modules/task-manager.js @@ -21,7 +21,7 @@ import { sanitizePrompt, findTaskById, readComplexityReport, - findTaskInComplexityReport, + addComplexityToTask, truncate, enableSilentMode, disableSilentMode, @@ -4543,7 +4543,7 @@ DO NOT include any text before or after the JSON array. No explanations, no mark * @param {Object[]} tasks - The array of tasks * @returns {Object|null} The next task to work on or null if no eligible tasks */ -function findNextTask(tasks) { +function findNextTask(tasks, complexityReport = null) { // Get all completed task IDs const completedTaskIds = new Set( tasks @@ -4591,6 +4591,9 @@ function findNextTask(tasks) { return a.id - b.id; // Lower ID first })[0]; // Return the first (highest priority) task + // Add complexity to the task + addComplexityToTask(nextTask, complexityReport); + return nextTask; } diff --git a/scripts/modules/ui.js b/scripts/modules/ui.js index 1525094a..67ea6753 100644 --- a/scripts/modules/ui.js +++ b/scripts/modules/ui.js @@ -686,7 +686,7 @@ async function displayNextTask(tasksPath, complexityReportPath = null) { const complexityReport = readComplexityReport(complexityReportPath); // Find the next task - const nextTask = findNextTask(data.tasks); + const nextTask = findNextTask(data.tasks, complexityReport); if (!nextTask) { console.log( @@ -759,6 +759,12 @@ async function displayNextTask(tasksPath, complexityReportPath = null) { complexityReport ) // Pass complexityReport ], + [ + chalk.cyan.bold('Complexity:'), + nextTask.complexityScore + ? getComplexityWithColor(nextTask.complexityScore) + : chalk.gray('N/A') + ], [chalk.cyan.bold('Description:'), nextTask.description] ); diff --git a/scripts/modules/utils.js b/scripts/modules/utils.js index 1098572d..7877ac3a 100644 --- a/scripts/modules/utils.js +++ b/scripts/modules/utils.js @@ -190,6 +190,15 @@ function findTaskInComplexityReport(report, taskId) { return report.complexityAnalysis.find((task) => task.taskId === taskId); } +function addComplexityToTask(task, complexityReport) { + const taskId = task.isSubtask ? task.parentTask.id : task.id; + + const taskAnalysis = findTaskInComplexityReport(complexityReport, taskId); + if (taskAnalysis) { + task.complexityScore = taskAnalysis.complexityScore; + } +} + /** * Checks if a task exists in the tasks array * @param {Array} tasks - The tasks array @@ -279,20 +288,7 @@ function findTaskById(tasks, taskId, complexityReport = null) { // If we found a task, check for complexity data if (taskResult && complexityReport) { - if (complexityReport && complexityReport.complexityAnalysis) { - // For a main task, look for a direct match - const taskId = taskResult.isSubtask - ? taskResult.parentTask.id - : taskResult.id; - - const taskAnalysis = complexityReport.complexityAnalysis.find( - (analysis) => analysis.taskId === taskId - ); - - if (taskAnalysis) { - taskResult.complexityScore = taskAnalysis.complexityScore; - } - } + addComplexityToTask(taskResult, complexityReport); } return taskResult; @@ -434,6 +430,7 @@ export { log, LOG_LEVELS, readComplexityReport, + addComplexityToTask, readJSON, sanitizePrompt, taskExists,