Implement remove-dependency MCP command for removing dependencies from tasks

This commit is contained in:
Eyal Toledano
2025-03-31 13:51:39 -04:00
parent 7f0cdf9046
commit fba6131db7
7 changed files with 132 additions and 4 deletions

View File

@@ -0,0 +1,73 @@
/**
* Direct function wrapper for removeDependency
*/
import { removeDependency } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
/**
* Remove a dependency from a task
* @param {Object} args - Function arguments
* @param {string|number} args.id - Task ID to remove dependency from
* @param {string|number} args.dependsOn - Task ID to remove as a dependency
* @param {string} [args.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/
export async function removeDependencyDirect(args, log) {
try {
log.info(`Removing dependency with args: ${JSON.stringify(args)}`);
// Validate required parameters
if (!args.id) {
return {
success: false,
error: {
code: 'INPUT_VALIDATION_ERROR',
message: 'Task ID (id) is required'
}
};
}
if (!args.dependsOn) {
return {
success: false,
error: {
code: 'INPUT_VALIDATION_ERROR',
message: 'Dependency ID (dependsOn) is required'
}
};
}
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
// Format IDs for the core function
const taskId = args.id.includes && args.id.includes('.') ? args.id : parseInt(args.id, 10);
const dependencyId = args.dependsOn.includes && args.dependsOn.includes('.') ? args.dependsOn : parseInt(args.dependsOn, 10);
log.info(`Removing dependency: task ${taskId} no longer depends on ${dependencyId}`);
// Call the core function
await removeDependency(tasksPath, taskId, dependencyId);
return {
success: true,
data: {
message: `Successfully removed dependency: Task ${taskId} no longer depends on ${dependencyId}`,
taskId: taskId,
dependencyId: dependencyId
}
};
} catch (error) {
log.error(`Error in removeDependencyDirect: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message
}
};
}
}

View File

@@ -22,6 +22,7 @@ import { removeSubtaskDirect } from './direct-functions/remove-subtask.js';
import { analyzeTaskComplexityDirect } from './direct-functions/analyze-task-complexity.js';
import { clearSubtasksDirect } from './direct-functions/clear-subtasks.js';
import { expandAllTasksDirect } from './direct-functions/expand-all-tasks.js';
import { removeDependencyDirect } from './direct-functions/remove-dependency.js';
// Re-export utility functions
export { findTasksJsonPath } from './utils/path-utils.js';
@@ -44,7 +45,8 @@ export const directFunctions = new Map([
['removeSubtaskDirect', removeSubtaskDirect],
['analyzeTaskComplexityDirect', analyzeTaskComplexityDirect],
['clearSubtasksDirect', clearSubtasksDirect],
['expandAllTasksDirect', expandAllTasksDirect]
['expandAllTasksDirect', expandAllTasksDirect],
['removeDependencyDirect', removeDependencyDirect]
]);
// Re-export all direct function implementations
@@ -65,5 +67,6 @@ export {
removeSubtaskDirect,
analyzeTaskComplexityDirect,
clearSubtasksDirect,
expandAllTasksDirect
expandAllTasksDirect,
removeDependencyDirect
};