From d07f8fddc5d4ae5e22359acc4039e7a9c1e4c089 Mon Sep 17 00:00:00 2001 From: Eyal Toledano Date: Thu, 1 May 2025 14:53:15 -0400 Subject: [PATCH] fix(add-task): pass projectRoot and fix logging/refs Modified add-task core, direct function, and tool to pass projectRoot for .env API key fallback. Fixed logFn reference error and removed deprecated reportProgress call in core addTask function. Verified working. --- .../src/core/direct-functions/add-task.js | 21 +++++++--- mcp-server/src/tools/add-task.js | 3 +- scripts/modules/task-manager/add-task.js | 42 ++++++++++++++----- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/mcp-server/src/core/direct-functions/add-task.js b/mcp-server/src/core/direct-functions/add-task.js index 876d6ca1..18c4d2e1 100644 --- a/mcp-server/src/core/direct-functions/add-task.js +++ b/mcp-server/src/core/direct-functions/add-task.js @@ -23,13 +23,21 @@ import { createLogWrapper } from '../../tools/utils.js'; * @param {string} [args.priority='medium'] - Task priority (high, medium, low) * @param {string} [args.tasksJsonPath] - Path to the tasks.json file (resolved by tool) * @param {boolean} [args.research=false] - Whether to use research capabilities for task creation + * @param {string} [args.projectRoot] - Project root path * @param {Object} log - Logger object * @param {Object} context - Additional context (session) * @returns {Promise} - Result object { success: boolean, data?: any, error?: { code: string, message: string } } */ export async function addTaskDirect(args, log, context = {}) { - // Destructure expected args (including research) - const { tasksJsonPath, prompt, dependencies, priority, research } = args; + // Destructure expected args (including research and projectRoot) + const { + tasksJsonPath, + prompt, + dependencies, + priority, + research, + projectRoot + } = args; const { session } = context; // Destructure session from context // Enable silent mode to prevent console logs from interfering with JSON response @@ -108,11 +116,13 @@ export async function addTaskDirect(args, log, context = {}) { taskPriority, { session, - mcpLog + mcpLog, + projectRoot }, 'json', // outputFormat manualTaskData, // Pass the manual task data - false // research flag is false for manual creation + false, // research flag is false for manual creation + projectRoot // Pass projectRoot ); } else { // AI-driven task creation @@ -128,7 +138,8 @@ export async function addTaskDirect(args, log, context = {}) { taskPriority, { session, - mcpLog + mcpLog, + projectRoot }, 'json', // outputFormat null, // manualTaskData is null for AI creation diff --git a/mcp-server/src/tools/add-task.js b/mcp-server/src/tools/add-task.js index 7c726995..d2ba0611 100644 --- a/mcp-server/src/tools/add-task.js +++ b/mcp-server/src/tools/add-task.js @@ -105,7 +105,8 @@ export function registerAddTaskTool(server) { testStrategy: args.testStrategy, dependencies: args.dependencies, priority: args.priority, - research: args.research + research: args.research, + projectRoot: rootFolder }, log, { session } diff --git a/scripts/modules/task-manager/add-task.js b/scripts/modules/task-manager/add-task.js index 4bc37930..748b859f 100644 --- a/scripts/modules/task-manager/add-task.js +++ b/scripts/modules/task-manager/add-task.js @@ -10,7 +10,7 @@ import { startLoadingIndicator, stopLoadingIndicator } from '../ui.js'; -import { log, readJSON, writeJSON, truncate } from '../utils.js'; +import { readJSON, writeJSON, log as consoleLog, truncate } from '../utils.js'; import { generateObjectService } from '../ai-services-unified.js'; import { getDefaultPriority } from '../config-manager.js'; import generateTaskFiles from './generate-task-files.js'; @@ -42,19 +42,41 @@ const AiTaskDataSchema = z.object({ * @param {Object} customEnv - Custom environment variables (optional) - Note: AI params override deprecated * @param {Object} manualTaskData - Manual task data (optional, for direct task creation without AI) * @param {boolean} useResearch - Whether to use the research model (passed to unified service) + * @param {Object} context - Context object containing session and potentially projectRoot + * @param {string} [context.projectRoot] - Project root path (for MCP/env fallback) * @returns {number} The new task ID */ async function addTask( tasksPath, prompt, dependencies = [], - priority = getDefaultPriority(), // Keep getter for default priority - { reportProgress, mcpLog, session } = {}, - outputFormat = 'text', - // customEnv = null, // Removed as AI param overrides are deprecated + priority = null, + context = {}, + outputFormat = 'text', // Default to text for CLI manualTaskData = null, - useResearch = false // <-- Add useResearch parameter + useResearch = false ) { + const { session, mcpLog, projectRoot } = context; + const isMCP = !!mcpLog; + + // Create a consistent logFn object regardless of context + const logFn = isMCP + ? mcpLog // Use MCP logger if provided + : { + // Create a wrapper around consoleLog for CLI + info: (...args) => consoleLog('info', ...args), + warn: (...args) => consoleLog('warn', ...args), + error: (...args) => consoleLog('error', ...args), + debug: (...args) => consoleLog('debug', ...args), + success: (...args) => consoleLog('success', ...args) + }; + + const effectivePriority = priority || getDefaultPriority(projectRoot); + + logFn.info( + `Adding new task with prompt: "${prompt}", Priority: ${effectivePriority}, Dependencies: ${dependencies.join(', ') || 'None'}, Research: ${useResearch}, ProjectRoot: ${projectRoot}` + ); + let loadingIndicator = null; // Create custom reporter that checks for MCP log @@ -62,7 +84,7 @@ async function addTask( if (mcpLog) { mcpLog[level](message); } else if (outputFormat === 'text') { - log(level, message); + consoleLog(level, message); } }; @@ -220,11 +242,11 @@ async function addTask( const aiGeneratedTaskData = await generateObjectService({ role: serviceRole, // <-- Use the determined role session: session, // Pass session for API key resolution + projectRoot: projectRoot, // <<< Pass projectRoot here schema: AiTaskDataSchema, // Pass the Zod schema objectName: 'newTaskData', // Name for the object systemPrompt: systemPrompt, - prompt: userPrompt, - reportProgress // Pass progress reporter if available + prompt: userPrompt }); report('DEBUG: generateObjectService returned successfully.', 'debug'); @@ -254,7 +276,7 @@ async function addTask( testStrategy: taskData.testStrategy || '', status: 'pending', dependencies: numericDependencies, // Use validated numeric dependencies - priority: priority, + priority: effectivePriority, subtasks: [] // Initialize with empty subtasks array };