diff --git a/scripts/modules/commands.js b/scripts/modules/commands.js index 3405f73c..d90005d8 100644 --- a/scripts/modules/commands.js +++ b/scripts/modules/commands.js @@ -1346,10 +1346,6 @@ function registerCommands(programInstance) { process.exit(1); } - console.log( - chalk.blue(`Setting status of task(s) ${taskId} to: ${status}`) - ); - // Find project root for tag resolution const projectRoot = findProjectRoot(); if (!projectRoot) { @@ -1357,6 +1353,14 @@ function registerCommands(programInstance) { process.exit(1); } + // Resolve tag using standard pattern and show current tag context + const resolvedTag = tag || getCurrentTag(projectRoot) || 'master'; + displayCurrentTagIndicator(resolvedTag); + + console.log( + chalk.blue(`Setting status of task(s) ${taskId} to: ${status}`) + ); + await setTaskStatus(tasksPath, taskId, status, { projectRoot, tag }); }); diff --git a/scripts/modules/task-manager/set-task-status.js b/scripts/modules/task-manager/set-task-status.js index 2d2cbb7e..9a08fcba 100644 --- a/scripts/modules/task-manager/set-task-status.js +++ b/scripts/modules/task-manager/set-task-status.js @@ -96,10 +96,30 @@ async function setTaskStatus( const taskIds = taskIdInput.split(',').map((id) => id.trim()); const updatedTasks = []; - // Update each task + // Update each task and capture old status for display for (const id of taskIds) { + // Capture old status before updating + let oldStatus = 'unknown'; + + if (id.includes('.')) { + // Handle subtask + const [parentId, subtaskId] = id + .split('.') + .map((id) => parseInt(id, 10)); + const parentTask = data.tasks.find((t) => t.id === parentId); + if (parentTask?.subtasks) { + const subtask = parentTask.subtasks.find((st) => st.id === subtaskId); + oldStatus = subtask?.status || 'pending'; + } + } else { + // Handle regular task + const taskId = parseInt(id, 10); + const task = data.tasks.find((t) => t.id === taskId); + oldStatus = task?.status || 'pending'; + } + await updateSingleTaskStatus(tasksPath, id, newStatus, data, !isMcpMode); - updatedTasks.push(id); + updatedTasks.push({ id, oldStatus, newStatus }); } // Update the raw data structure with the modified tasks @@ -126,16 +146,15 @@ async function setTaskStatus( // Display success message - only in CLI mode if (!isMcpMode) { - for (const id of updatedTasks) { - const task = findTaskById(data.tasks, id); - const taskName = task ? task.title : id; + for (const updateInfo of updatedTasks) { + const { id, oldStatus, newStatus: updatedStatus } = updateInfo; console.log( boxen( chalk.white.bold(`Successfully updated task ${id} status:`) + '\n' + - `From: ${chalk.yellow(task ? task.status : 'unknown')}\n` + - `To: ${chalk.green(newStatus)}`, + `From: ${chalk.yellow(oldStatus)}\n` + + `To: ${chalk.green(updatedStatus)}`, { padding: 1, borderColor: 'green', borderStyle: 'round' } ) ); @@ -145,9 +164,10 @@ async function setTaskStatus( // Return success value for programmatic use return { success: true, - updatedTasks: updatedTasks.map((id) => ({ + updatedTasks: updatedTasks.map(({ id, oldStatus, newStatus }) => ({ id, - status: newStatus + oldStatus, + newStatus })) }; } catch (error) { diff --git a/scripts/modules/utils.js b/scripts/modules/utils.js index 3f938392..198c80fd 100644 --- a/scripts/modules/utils.js +++ b/scripts/modules/utils.js @@ -821,9 +821,8 @@ function formatTaskId(id) { * @param {Array} tasks - The tasks array * @param {string|number} taskId - The task ID to find * @param {Object|null} complexityReport - Optional pre-loaded complexity report - * @returns {Object|null} The task object or null if not found * @param {string} [statusFilter] - Optional status to filter subtasks by - * @returns {{task: Object|null, originalSubtaskCount: number|null}} The task object (potentially with filtered subtasks) and the original subtask count if filtered, or nulls if not found. + * @returns {{task: Object|null, originalSubtaskCount: number|null, originalSubtasks: Array|null}} The task object (potentially with filtered subtasks), the original subtask count, and original subtasks array if filtered, or nulls if not found. */ function findTaskById( tasks, @@ -844,7 +843,7 @@ function findTaskById( const parentTask = tasks.find((t) => t.id === parentId); if (!parentTask || !parentTask.subtasks) { - return { task: null, originalSubtaskCount: null }; + return { task: null, originalSubtaskCount: null, originalSubtasks: null }; } const subtask = parentTask.subtasks.find((st) => st.id === subtaskId); @@ -863,11 +862,16 @@ function findTaskById( addComplexityToTask(subtask, complexityReport); } - return { task: subtask || null, originalSubtaskCount: null }; + return { + task: subtask || null, + originalSubtaskCount: null, + originalSubtasks: null + }; } let taskResult = null; - const originalSubtaskCount = null; + let originalSubtaskCount = null; + let originalSubtasks = null; // Find the main task const id = parseInt(taskId, 10); @@ -875,13 +879,17 @@ function findTaskById( // If task not found, return nulls if (!task) { - return { task: null, originalSubtaskCount: null }; + return { task: null, originalSubtaskCount: null, originalSubtasks: null }; } taskResult = task; // If task found and statusFilter provided, filter its subtasks if (statusFilter && task.subtasks && Array.isArray(task.subtasks)) { + // Store original subtasks and count before filtering + originalSubtasks = [...task.subtasks]; // Clone the original subtasks array + originalSubtaskCount = task.subtasks.length; + // Clone the task to avoid modifying the original array const filteredTask = { ...task }; filteredTask.subtasks = task.subtasks.filter( @@ -898,8 +906,8 @@ function findTaskById( addComplexityToTask(taskResult, complexityReport); } - // Return the found task and original subtask count - return { task: taskResult, originalSubtaskCount }; + // Return the found task, original subtask count, and original subtasks + return { task: taskResult, originalSubtaskCount, originalSubtasks }; } /**