Files
claude-task-master/mcp-server/src/core/direct-functions/update-tasks.js
Parthy 43e0025f4c fix: prevent tag corruption in bulk updates (#856)
* fix(task-manager): prevent tag corruption in bulk updates and add tag preservation test

- Fix writeJSON call in scripts/modules/task-manager/update-tasks.js (line 469) to include projectRoot and tag parameters.
- Ensure tagged task lists maintain data integrity during bulk updates, preventing task disappearance in tagged contexts.
- Update MCP tools to properly pass tag context through the call chain.
- Introduce a comprehensive test case to verify that all tags are preserved when updating tasks, covering both master and feature-branch scenarios.

Addresses an issue where bulk updates could corrupt tasks.json in tagged task list structures, reinforcing task management robustness.

* style(tests): format task data in update-tasks test
2025-07-02 12:53:12 +02:00

126 lines
3.2 KiB
JavaScript

/**
* update-tasks.js
* Direct function implementation for updating tasks based on new context
*/
import path from 'path';
import { updateTasks } from '../../../../scripts/modules/task-manager.js';
import { createLogWrapper } from '../../tools/utils.js';
import {
enableSilentMode,
disableSilentMode
} from '../../../../scripts/modules/utils.js';
/**
* Direct function wrapper for updating tasks based on new context.
*
* @param {Object} args - Command arguments containing projectRoot, from, prompt, research options.
* @param {Object} log - Logger object.
* @param {Object} context - Context object containing session data.
* @returns {Promise<Object>} - Result object with success status and data/error information.
*/
export async function updateTasksDirect(args, log, context = {}) {
const { session } = context;
const { from, prompt, research, tasksJsonPath, projectRoot, tag } = args;
// Create the standard logger wrapper
const logWrapper = createLogWrapper(log);
// --- Input Validation ---
if (!projectRoot) {
logWrapper.error('updateTasksDirect requires a projectRoot argument.');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'projectRoot is required.'
}
};
}
if (!from) {
logWrapper.error('updateTasksDirect called without from ID');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'Starting task ID (from) is required'
}
};
}
if (!prompt) {
logWrapper.error('updateTasksDirect called without prompt');
return {
success: false,
error: {
code: 'MISSING_ARGUMENT',
message: 'Update prompt is required'
}
};
}
logWrapper.info(
`Updating tasks via direct function. From: ${from}, Research: ${research}, File: ${tasksJsonPath}, ProjectRoot: ${projectRoot}`
);
enableSilentMode(); // Enable silent mode
try {
// Call the core updateTasks function
const result = await updateTasks(
tasksJsonPath,
from,
prompt,
research,
{
session,
mcpLog: logWrapper,
projectRoot,
tag
},
'json'
);
if (result && result.success && Array.isArray(result.updatedTasks)) {
logWrapper.success(
`Successfully updated ${result.updatedTasks.length} tasks.`
);
return {
success: true,
data: {
message: `Successfully updated ${result.updatedTasks.length} tasks.`,
tasksPath: tasksJsonPath,
updatedCount: result.updatedTasks.length,
telemetryData: result.telemetryData,
tagInfo: result.tagInfo
}
};
} else {
// Handle case where core function didn't return expected success structure
logWrapper.error(
'Core updateTasks function did not return a successful structure.'
);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message:
result?.message ||
'Core function failed to update tasks or returned unexpected result.'
}
};
}
} catch (error) {
logWrapper.error(`Error executing core updateTasks: ${error.message}`);
return {
success: false,
error: {
code: 'UPDATE_TASKS_CORE_ERROR',
message: error.message || 'Unknown error updating tasks'
}
};
} finally {
disableSilentMode(); // Ensure silent mode is disabled
}
}