From 4bc80290808fb383371b510e3c1800d19ef088d4 Mon Sep 17 00:00:00 2001 From: Parthy <52548018+mm-parthy@users.noreply.github.com> Date: Thu, 10 Jul 2025 09:25:56 +0200 Subject: [PATCH] refactor: streamline task path resolution in commands.js (#948) - Replaced local `tasksPath` variable assignments with direct calls to `taskMaster.getTasksPath()` for consistency and clarity across multiple command functions. - This change enhances maintainability by ensuring a single source of truth for task paths, reducing redundancy in path handling logic. --- scripts/modules/commands.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/modules/commands.js b/scripts/modules/commands.js index 63bc86a5..a2fa6f06 100644 --- a/scripts/modules/commands.js +++ b/scripts/modules/commands.js @@ -970,6 +970,8 @@ function registerCommands(programInstance) { const prompt = options.prompt; const useResearch = options.research || false; + const tasksPath = taskMaster.getTasksPath(); + // Resolve tag using standard pattern const tag = options.tag || getCurrentTag(taskMaster.getProjectRoot()) || 'master'; @@ -1063,6 +1065,7 @@ function registerCommands(programInstance) { const taskMaster = initTaskMaster({ tasksPath: options.file || true }); + const tasksPath = taskMaster.getTasksPath(); // Resolve tag using standard pattern const tag = @@ -1160,7 +1163,7 @@ function registerCommands(programInstance) { } const result = await updateTaskById( - tasksPath, + taskMaster.getTasksPath(), taskId, prompt, useResearch, @@ -1234,6 +1237,7 @@ function registerCommands(programInstance) { const taskMaster = initTaskMaster({ tasksPath: options.file || true }); + const tasksPath = taskMaster.getTasksPath(); // Resolve tag using standard pattern const tag = @@ -1333,7 +1337,7 @@ function registerCommands(programInstance) { } const result = await updateSubtaskById( - tasksPath, + taskMaster.getTasksPath(), subtaskId, prompt, useResearch, @@ -1571,7 +1575,7 @@ function registerCommands(programInstance) { // Updated call to the refactored expandAllTasks try { const result = await expandAllTasks( - tasksPath, + taskMaster.getTasksPath(), options.num, // Pass num options.research, // Pass research flag options.prompt, // Pass additional context @@ -1598,7 +1602,7 @@ function registerCommands(programInstance) { try { // Call the refactored expandTask function await expandTask( - tasksPath, + taskMaster.getTasksPath(), options.id, options.num, options.research, @@ -2091,7 +2095,6 @@ ${result.result} .option('--all', 'Clear subtasks from all tasks') .option('--tag ', 'Specify tag context for task operations') .action(async (options) => { - const tasksPath = options.file || TASKMASTER_TASKS_FILE; const taskIds = options.id; const all = options.all; const tag = options.tag; @@ -2249,7 +2252,7 @@ ${result.result} try { const { newTaskId, telemetryData } = await addTask( - tasksPath, + taskMaster.getTasksPath(), options.prompt, dependenciesArray, options.priority, @@ -2288,8 +2291,6 @@ ${result.result} ) .option('--tag ', 'Specify tag context for task operations') .action(async (options) => { - const tasksPath = options.file || TASKMASTER_TASKS_FILE; - const reportPath = options.report; const tag = options.tag; // Initialize TaskMaster @@ -4236,6 +4237,7 @@ Examples: const taskMaster = initTaskMaster({ tasksPath: options.file || true }); + const tasksPath = taskMaster.getTasksPath(); // Validate tasks file exists if (!fs.existsSync(tasksPath)) { @@ -4305,7 +4307,7 @@ Examples: }; await createTagFromBranch( - tasksPath, + taskMaster.getTasksPath(), currentBranch, branchOptions, context, @@ -4375,6 +4377,7 @@ Examples: const taskMaster = initTaskMaster({ tasksPath: options.file || true }); + const tasksPath = taskMaster.getTasksPath(); // Validate tasks file exists if (!fs.existsSync(tasksPath)) { @@ -4429,6 +4432,7 @@ Examples: const taskMaster = initTaskMaster({ tasksPath: options.file || true }); + const tasksPath = taskMaster.getTasksPath(); // Validate tasks file exists if (!fs.existsSync(tasksPath)) { @@ -4478,6 +4482,7 @@ Examples: const taskMaster = initTaskMaster({ tasksPath: options.file || true }); + const tasksPath = taskMaster.getTasksPath(); // Validate tasks file exists if (!fs.existsSync(tasksPath)) { @@ -4523,6 +4528,7 @@ Examples: const taskMaster = initTaskMaster({ tasksPath: options.file || true }); + const tasksPath = taskMaster.getTasksPath(); // Validate tasks file exists if (!fs.existsSync(tasksPath)) { @@ -4574,6 +4580,7 @@ Examples: const taskMaster = initTaskMaster({ tasksPath: options.file || true }); + const tasksPath = taskMaster.getTasksPath(); // Validate tasks file exists if (!fs.existsSync(tasksPath)) { @@ -4594,7 +4601,7 @@ Examples: }; await copyTag( - taskMaster.getTasksPath(), + tasksPath, sourceName, targetName, copyOptions,