diff --git a/.changeset/quick-laws-cover.md b/.changeset/quick-laws-cover.md new file mode 100644 index 00000000..15281282 --- /dev/null +++ b/.changeset/quick-laws-cover.md @@ -0,0 +1,8 @@ +--- +"task-master-ai": minor +--- + +Add stricter validation and clearer feedback for task priority when adding new tasks + +- if a task priority is invalid, it will default to medium +- made taks priority case-insensitive, essentially making HIGH and high the same value diff --git a/scripts/modules/task-manager/add-task.js b/scripts/modules/task-manager/add-task.js index 0fc29478..f3896532 100644 --- a/scripts/modules/task-manager/add-task.js +++ b/scripts/modules/task-manager/add-task.js @@ -29,6 +29,12 @@ import { generateObjectService } from '../ai-services-unified.js'; import { getDefaultPriority } from '../config-manager.js'; import ContextGatherer from '../utils/contextGatherer.js'; import generateTaskFiles from './generate-task-files.js'; +import { + TASK_PRIORITY_OPTIONS, + DEFAULT_TASK_PRIORITY, + isValidTaskPriority, + normalizeTaskPriority +} from '../../../src/constants/task-priority.js'; // Define Zod schema for the expected AI output object const AiTaskDataSchema = z.object({ @@ -115,7 +121,25 @@ async function addTask( success: (...args) => consoleLog('success', ...args) }; - const effectivePriority = priority || getDefaultPriority(projectRoot); + // Validate priority - only accept high, medium, or low + let effectivePriority = + priority || getDefaultPriority(projectRoot) || DEFAULT_TASK_PRIORITY; + + // If priority is provided, validate and normalize it + if (priority) { + const normalizedPriority = normalizeTaskPriority(priority); + if (normalizedPriority) { + effectivePriority = normalizedPriority; + } else { + if (outputFormat === 'text') { + consoleLog( + 'warn', + `Invalid priority "${priority}". Using default priority "${DEFAULT_TASK_PRIORITY}".` + ); + } + effectivePriority = DEFAULT_TASK_PRIORITY; + } + } logFn.info( `Adding new task with prompt: "${prompt}", Priority: ${effectivePriority}, Dependencies: ${dependencies.join(', ') || 'None'}, Research: ${useResearch}, ProjectRoot: ${projectRoot}` diff --git a/src/constants/task-priority.js b/src/constants/task-priority.js new file mode 100644 index 00000000..0d766dd5 --- /dev/null +++ b/src/constants/task-priority.js @@ -0,0 +1,39 @@ +/** + * @typedef {'high' | 'medium' | 'low'} TaskPriority + */ + +/** + * Task priority options + * @type {TaskPriority[]} + * @description Defines possible task priorities: + * - high: Critical tasks that need immediate attention + * - medium: Standard priority tasks (default) + * - low: Tasks that can be deferred or are nice-to-have + */ +export const TASK_PRIORITY_OPTIONS = ['high', 'medium', 'low']; + +/** + * Default task priority + * @type {TaskPriority} + */ +export const DEFAULT_TASK_PRIORITY = 'medium'; + +/** + * Check if a given priority is valid + * @param {string} priority - The priority to check + * @returns {boolean} True if the priority is valid, false otherwise + */ +export function isValidTaskPriority(priority) { + return TASK_PRIORITY_OPTIONS.includes(priority?.toLowerCase()); +} + +/** + * Normalize a priority value to lowercase + * @param {string} priority - The priority to normalize + * @returns {TaskPriority|null} The normalized priority or null if invalid + */ +export function normalizeTaskPriority(priority) { + if (!priority) return null; + const normalized = priority.toLowerCase(); + return isValidTaskPriority(normalized) ? normalized : null; +}