Implement fix-dependencies MCP command for automatically fixing invalid dependencies

This commit is contained in:
Eyal Toledano
2025-03-31 14:01:49 -04:00
parent 4d2db4d165
commit 6657ca817c
5 changed files with 97 additions and 2 deletions

View File

@@ -0,0 +1,55 @@
/**
* Direct function wrapper for fixDependenciesCommand
*/
import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import fs from 'fs';
/**
* Fix invalid dependencies in tasks.json automatically
* @param {Object} args - Function arguments
* @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 fixDependenciesDirect(args, log) {
try {
log.info(`Fixing invalid dependencies in tasks...`);
// Determine the tasks file path
const tasksPath = args.file || await findTasksJsonPath(args.projectRoot);
// Verify the file exists
if (!fs.existsSync(tasksPath)) {
return {
success: false,
error: {
code: 'FILE_NOT_FOUND',
message: `Tasks file not found at ${tasksPath}`
}
};
}
// Call the original command function
await fixDependenciesCommand(tasksPath);
return {
success: true,
data: {
message: 'Dependencies fixed successfully',
tasksPath
}
};
} catch (error) {
log.error(`Error fixing dependencies: ${error.message}`);
return {
success: false,
error: {
code: 'FIX_DEPENDENCIES_ERROR',
message: error.message
}
};
}
}

View File

@@ -24,6 +24,7 @@ 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';
import { validateDependenciesDirect } from './direct-functions/validate-dependencies.js';
import { fixDependenciesDirect } from './direct-functions/fix-dependencies.js';
// Re-export utility functions
export { findTasksJsonPath } from './utils/path-utils.js';
@@ -48,7 +49,8 @@ export const directFunctions = new Map([
['clearSubtasksDirect', clearSubtasksDirect],
['expandAllTasksDirect', expandAllTasksDirect],
['removeDependencyDirect', removeDependencyDirect],
['validateDependenciesDirect', validateDependenciesDirect]
['validateDependenciesDirect', validateDependenciesDirect],
['fixDependenciesDirect', fixDependenciesDirect]
]);
// Re-export all direct function implementations
@@ -71,5 +73,6 @@ export {
clearSubtasksDirect,
expandAllTasksDirect,
removeDependencyDirect,
validateDependenciesDirect
validateDependenciesDirect,
fixDependenciesDirect
};