* wip: replace tool parameter inputs with root directory paths * fix: moved path resolving responsibility to tools - made path in parameters to optional for AI - internalised path resolving using session roots * chore: update package-lock.json * chore: fix regressions and fix CI * fix: make projectRoot required * fix: add-task tool * fix: updateTask tool * fix: remove reportProgress * chore: cleanup * fix: expand-task tool * chore: remove usless logs * fix: dependency manager logging in mcp server
129 lines
3.3 KiB
JavaScript
129 lines
3.3 KiB
JavaScript
/**
|
|
* Direct function wrapper for clearSubtasks
|
|
*/
|
|
|
|
import { clearSubtasks } from '../../../../scripts/modules/task-manager.js';
|
|
import {
|
|
enableSilentMode,
|
|
disableSilentMode
|
|
} from '../../../../scripts/modules/utils.js';
|
|
import fs from 'fs';
|
|
|
|
/**
|
|
* Clear subtasks from specified tasks
|
|
* @param {Object} args - Function arguments
|
|
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
|
* @param {string} [args.id] - Task IDs (comma-separated) to clear subtasks from
|
|
* @param {boolean} [args.all] - Clear subtasks from all tasks
|
|
* @param {Object} log - Logger object
|
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
|
*/
|
|
export async function clearSubtasksDirect(args, log) {
|
|
// Destructure expected args
|
|
const { tasksJsonPath, id, all } = args;
|
|
try {
|
|
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
|
|
|
|
// Check if tasksJsonPath was provided
|
|
if (!tasksJsonPath) {
|
|
log.error('clearSubtasksDirect called without tasksJsonPath');
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: 'MISSING_ARGUMENT',
|
|
message: 'tasksJsonPath is required'
|
|
}
|
|
};
|
|
}
|
|
|
|
// Either id or all must be provided
|
|
if (!id && !all) {
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: 'INPUT_VALIDATION_ERROR',
|
|
message:
|
|
'Either task IDs with id parameter or all parameter must be provided'
|
|
}
|
|
};
|
|
}
|
|
|
|
// Use provided path
|
|
const tasksPath = tasksJsonPath;
|
|
|
|
// Check if tasks.json exists
|
|
if (!fs.existsSync(tasksPath)) {
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: 'FILE_NOT_FOUND_ERROR',
|
|
message: `Tasks file not found at ${tasksPath}`
|
|
}
|
|
};
|
|
}
|
|
|
|
let taskIds;
|
|
|
|
// If all is specified, get all task IDs
|
|
if (all) {
|
|
log.info('Clearing subtasks from all tasks');
|
|
const data = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
|
|
if (!data || !data.tasks || data.tasks.length === 0) {
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: 'INPUT_VALIDATION_ERROR',
|
|
message: 'No valid tasks found in the tasks file'
|
|
}
|
|
};
|
|
}
|
|
taskIds = data.tasks.map((t) => t.id).join(',');
|
|
} else {
|
|
// Use the provided task IDs
|
|
taskIds = id;
|
|
}
|
|
|
|
log.info(`Clearing subtasks from tasks: ${taskIds}`);
|
|
|
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
|
enableSilentMode();
|
|
|
|
// Call the core function
|
|
clearSubtasks(tasksPath, taskIds);
|
|
|
|
// Restore normal logging
|
|
disableSilentMode();
|
|
|
|
// Read the updated data to provide a summary
|
|
const updatedData = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
|
|
const taskIdArray = taskIds.split(',').map((id) => parseInt(id.trim(), 10));
|
|
|
|
// Build a summary of what was done
|
|
const clearedTasksCount = taskIdArray.length;
|
|
const taskSummary = taskIdArray.map((id) => {
|
|
const task = updatedData.tasks.find((t) => t.id === id);
|
|
return task ? { id, title: task.title } : { id, title: 'Task not found' };
|
|
});
|
|
|
|
return {
|
|
success: true,
|
|
data: {
|
|
message: `Successfully cleared subtasks from ${clearedTasksCount} task(s)`,
|
|
tasksCleared: taskSummary
|
|
}
|
|
};
|
|
} catch (error) {
|
|
// Make sure to restore normal logging even if there's an error
|
|
disableSilentMode();
|
|
|
|
log.error(`Error in clearSubtasksDirect: ${error.message}`);
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: 'CORE_FUNCTION_ERROR',
|
|
message: error.message
|
|
}
|
|
};
|
|
}
|
|
}
|