From 8ae772086d043024ff4f2d95d90c5f07669c79b3 Mon Sep 17 00:00:00 2001 From: Eyal Toledano Date: Wed, 7 May 2025 14:07:50 -0400 Subject: [PATCH] fix(next): adjusts CLI output for next when the result is a subtask. previously incorrect suggested creating subtasks for the subtask. --- scripts/modules/ui.js | 51 +++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/scripts/modules/ui.js b/scripts/modules/ui.js index fac65328..b9937bd5 100644 --- a/scripts/modules/ui.js +++ b/scripts/modules/ui.js @@ -860,8 +860,11 @@ async function displayNextTask(tasksPath) { ); } - // Show subtasks if they exist - if (nextTask.subtasks && nextTask.subtasks.length > 0) { + // Determine if the nextTask is a subtask + const isSubtask = !!nextTask.parentId; + + // Show subtasks if they exist (only for parent tasks) + if (!isSubtask && nextTask.subtasks && nextTask.subtasks.length > 0) { console.log( boxen(chalk.white.bold('Subtasks'), { padding: { top: 0, bottom: 0, left: 1, right: 1 }, @@ -966,8 +969,10 @@ async function displayNextTask(tasksPath) { }); console.log(subtaskTable.toString()); - } else { - // Suggest expanding if no subtasks + } + + // Suggest expanding if no subtasks (only for parent tasks without subtasks) + if (!isSubtask && (!nextTask.subtasks || nextTask.subtasks.length === 0)) { console.log( boxen( chalk.yellow('No subtasks found. Consider breaking down this task:') + @@ -986,22 +991,30 @@ async function displayNextTask(tasksPath) { } // Show action suggestions + let suggestedActionsContent = chalk.white.bold('Suggested Actions:') + '\n'; + if (isSubtask) { + // Suggested actions for a subtask + suggestedActionsContent += + `${chalk.cyan('1.')} Mark as in-progress: ${chalk.yellow(`task-master set-status --id=${nextTask.id} --status=in-progress`)}\n` + + `${chalk.cyan('2.')} Mark as done when completed: ${chalk.yellow(`task-master set-status --id=${nextTask.id} --status=done`)}\n` + + `${chalk.cyan('3.')} View parent task: ${chalk.yellow(`task-master show --id=${nextTask.parentId}`)}`; + } else { + // Suggested actions for a parent task + suggestedActionsContent += + `${chalk.cyan('1.')} Mark as in-progress: ${chalk.yellow(`task-master set-status --id=${nextTask.id} --status=in-progress`)}\n` + + `${chalk.cyan('2.')} Mark as done when completed: ${chalk.yellow(`task-master set-status --id=${nextTask.id} --status=done`)}\n` + + (nextTask.subtasks && nextTask.subtasks.length > 0 + ? `${chalk.cyan('3.')} Update subtask status: ${chalk.yellow(`task-master set-status --id=${nextTask.id}.1 --status=done`)}` // Example: first subtask + : `${chalk.cyan('3.')} Break down into subtasks: ${chalk.yellow(`task-master expand --id=${nextTask.id}`)}`); + } + console.log( - boxen( - chalk.white.bold('Suggested Actions:') + - '\n' + - `${chalk.cyan('1.')} Mark as in-progress: ${chalk.yellow(`task-master set-status --id=${nextTask.id} --status=in-progress`)}\n` + - `${chalk.cyan('2.')} Mark as done when completed: ${chalk.yellow(`task-master set-status --id=${nextTask.id} --status=done`)}\n` + - (nextTask.subtasks && nextTask.subtasks.length > 0 - ? `${chalk.cyan('3.')} Update subtask status: ${chalk.yellow(`task-master set-status --id=${nextTask.id}.1 --status=done`)}` - : `${chalk.cyan('3.')} Break down into subtasks: ${chalk.yellow(`task-master expand --id=${nextTask.id}`)}`), - { - padding: { top: 0, bottom: 0, left: 1, right: 1 }, - borderColor: 'green', - borderStyle: 'round', - margin: { top: 1 } - } - ) + boxen(suggestedActionsContent, { + padding: { top: 0, bottom: 0, left: 1, right: 1 }, + borderColor: 'green', + borderStyle: 'round', + margin: { top: 1 } + }) ); }