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.
This commit is contained in:
@@ -23,13 +23,21 @@ import { createLogWrapper } from '../../tools/utils.js';
|
|||||||
* @param {string} [args.priority='medium'] - Task priority (high, medium, low)
|
* @param {string} [args.priority='medium'] - Task priority (high, medium, low)
|
||||||
* @param {string} [args.tasksJsonPath] - Path to the tasks.json file (resolved by tool)
|
* @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 {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} log - Logger object
|
||||||
* @param {Object} context - Additional context (session)
|
* @param {Object} context - Additional context (session)
|
||||||
* @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } }
|
* @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } }
|
||||||
*/
|
*/
|
||||||
export async function addTaskDirect(args, log, context = {}) {
|
export async function addTaskDirect(args, log, context = {}) {
|
||||||
// Destructure expected args (including research)
|
// Destructure expected args (including research and projectRoot)
|
||||||
const { tasksJsonPath, prompt, dependencies, priority, research } = args;
|
const {
|
||||||
|
tasksJsonPath,
|
||||||
|
prompt,
|
||||||
|
dependencies,
|
||||||
|
priority,
|
||||||
|
research,
|
||||||
|
projectRoot
|
||||||
|
} = args;
|
||||||
const { session } = context; // Destructure session from context
|
const { session } = context; // Destructure session from context
|
||||||
|
|
||||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
@@ -108,11 +116,13 @@ export async function addTaskDirect(args, log, context = {}) {
|
|||||||
taskPriority,
|
taskPriority,
|
||||||
{
|
{
|
||||||
session,
|
session,
|
||||||
mcpLog
|
mcpLog,
|
||||||
|
projectRoot
|
||||||
},
|
},
|
||||||
'json', // outputFormat
|
'json', // outputFormat
|
||||||
manualTaskData, // Pass the manual task data
|
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 {
|
} else {
|
||||||
// AI-driven task creation
|
// AI-driven task creation
|
||||||
@@ -128,7 +138,8 @@ export async function addTaskDirect(args, log, context = {}) {
|
|||||||
taskPriority,
|
taskPriority,
|
||||||
{
|
{
|
||||||
session,
|
session,
|
||||||
mcpLog
|
mcpLog,
|
||||||
|
projectRoot
|
||||||
},
|
},
|
||||||
'json', // outputFormat
|
'json', // outputFormat
|
||||||
null, // manualTaskData is null for AI creation
|
null, // manualTaskData is null for AI creation
|
||||||
|
|||||||
@@ -105,7 +105,8 @@ export function registerAddTaskTool(server) {
|
|||||||
testStrategy: args.testStrategy,
|
testStrategy: args.testStrategy,
|
||||||
dependencies: args.dependencies,
|
dependencies: args.dependencies,
|
||||||
priority: args.priority,
|
priority: args.priority,
|
||||||
research: args.research
|
research: args.research,
|
||||||
|
projectRoot: rootFolder
|
||||||
},
|
},
|
||||||
log,
|
log,
|
||||||
{ session }
|
{ session }
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
startLoadingIndicator,
|
startLoadingIndicator,
|
||||||
stopLoadingIndicator
|
stopLoadingIndicator
|
||||||
} from '../ui.js';
|
} 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 { generateObjectService } from '../ai-services-unified.js';
|
||||||
import { getDefaultPriority } from '../config-manager.js';
|
import { getDefaultPriority } from '../config-manager.js';
|
||||||
import generateTaskFiles from './generate-task-files.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} customEnv - Custom environment variables (optional) - Note: AI params override deprecated
|
||||||
* @param {Object} manualTaskData - Manual task data (optional, for direct task creation without AI)
|
* @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 {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
|
* @returns {number} The new task ID
|
||||||
*/
|
*/
|
||||||
async function addTask(
|
async function addTask(
|
||||||
tasksPath,
|
tasksPath,
|
||||||
prompt,
|
prompt,
|
||||||
dependencies = [],
|
dependencies = [],
|
||||||
priority = getDefaultPriority(), // Keep getter for default priority
|
priority = null,
|
||||||
{ reportProgress, mcpLog, session } = {},
|
context = {},
|
||||||
outputFormat = 'text',
|
outputFormat = 'text', // Default to text for CLI
|
||||||
// customEnv = null, // Removed as AI param overrides are deprecated
|
|
||||||
manualTaskData = null,
|
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;
|
let loadingIndicator = null;
|
||||||
|
|
||||||
// Create custom reporter that checks for MCP log
|
// Create custom reporter that checks for MCP log
|
||||||
@@ -62,7 +84,7 @@ async function addTask(
|
|||||||
if (mcpLog) {
|
if (mcpLog) {
|
||||||
mcpLog[level](message);
|
mcpLog[level](message);
|
||||||
} else if (outputFormat === 'text') {
|
} else if (outputFormat === 'text') {
|
||||||
log(level, message);
|
consoleLog(level, message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -220,11 +242,11 @@ async function addTask(
|
|||||||
const aiGeneratedTaskData = await generateObjectService({
|
const aiGeneratedTaskData = await generateObjectService({
|
||||||
role: serviceRole, // <-- Use the determined role
|
role: serviceRole, // <-- Use the determined role
|
||||||
session: session, // Pass session for API key resolution
|
session: session, // Pass session for API key resolution
|
||||||
|
projectRoot: projectRoot, // <<< Pass projectRoot here
|
||||||
schema: AiTaskDataSchema, // Pass the Zod schema
|
schema: AiTaskDataSchema, // Pass the Zod schema
|
||||||
objectName: 'newTaskData', // Name for the object
|
objectName: 'newTaskData', // Name for the object
|
||||||
systemPrompt: systemPrompt,
|
systemPrompt: systemPrompt,
|
||||||
prompt: userPrompt,
|
prompt: userPrompt
|
||||||
reportProgress // Pass progress reporter if available
|
|
||||||
});
|
});
|
||||||
report('DEBUG: generateObjectService returned successfully.', 'debug');
|
report('DEBUG: generateObjectService returned successfully.', 'debug');
|
||||||
|
|
||||||
@@ -254,7 +276,7 @@ async function addTask(
|
|||||||
testStrategy: taskData.testStrategy || '',
|
testStrategy: taskData.testStrategy || '',
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
dependencies: numericDependencies, // Use validated numeric dependencies
|
dependencies: numericDependencies, // Use validated numeric dependencies
|
||||||
priority: priority,
|
priority: effectivePriority,
|
||||||
subtasks: [] // Initialize with empty subtasks array
|
subtasks: [] // Initialize with empty subtasks array
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user