fix: replace tool parameter inputs with root directory paths (#147)

* 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
This commit is contained in:
Ralph Khreish
2025-04-11 18:57:43 +02:00
committed by GitHub
parent 30e6d47577
commit d3d9dc6ebe
51 changed files with 9476 additions and 8918 deletions

View File

@@ -11,7 +11,6 @@ import {
disableSilentMode,
isSilentMode
} from '../../../../scripts/modules/utils.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
import {
getAnthropicClientForMCP,
getModelConfig
@@ -23,12 +22,20 @@ import fs from 'fs';
* Direct function wrapper for expanding a task into subtasks with error handling.
*
* @param {Object} args - Command arguments
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
* @param {string} args.id - The ID of the task to expand.
* @param {number|string} [args.num] - Number of subtasks to generate.
* @param {boolean} [args.research] - Enable Perplexity AI for research-backed subtask generation.
* @param {string} [args.prompt] - Additional context to guide subtask generation.
* @param {boolean} [args.force] - Force expansion even if subtasks exist.
* @param {Object} log - Logger object
* @param {Object} context - Context object containing session and reportProgress
* @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/
export async function expandTaskDirect(args, log, context = {}) {
const { session } = context;
// Destructure expected args
const { tasksJsonPath, id, num, research, prompt, force } = args;
// Log session root data for debugging
log.info(
@@ -40,48 +47,26 @@ export async function expandTaskDirect(args, log, context = {}) {
})}`
);
let tasksPath;
try {
// If a direct file path is provided, use it directly
if (args.file && fs.existsSync(args.file)) {
log.info(
`[expandTaskDirect] Using explicitly provided tasks file: ${args.file}`
);
tasksPath = args.file;
} else {
// Find the tasks path through standard logic
log.info(
`[expandTaskDirect] No direct file path provided or file not found at ${args.file}, searching using findTasksJsonPath`
);
tasksPath = findTasksJsonPath(args, log);
}
} catch (error) {
log.error(
`[expandTaskDirect] Error during tasksPath determination: ${error.message}`
);
// Include session roots information in error
const sessionRootsInfo = session
? `\nSession.roots: ${JSON.stringify(session.roots)}\n` +
`Current Working Directory: ${process.cwd()}\n` +
`Args.projectRoot: ${args.projectRoot}\n` +
`Args.file: ${args.file}\n`
: '\nSession object not available';
// Check if tasksJsonPath was provided
if (!tasksJsonPath) {
log.error('expandTaskDirect called without tasksJsonPath');
return {
success: false,
error: {
code: 'FILE_NOT_FOUND_ERROR',
message: `Error determining tasksPath: ${error.message}${sessionRootsInfo}`
code: 'MISSING_ARGUMENT',
message: 'tasksJsonPath is required'
},
fromCache: false
};
}
log.info(`[expandTaskDirect] Determined tasksPath: ${tasksPath}`);
// Use provided path
const tasksPath = tasksJsonPath;
log.info(`[expandTaskDirect] Using tasksPath: ${tasksPath}`);
// Validate task ID
const taskId = args.id ? parseInt(args.id, 10) : null;
const taskId = id ? parseInt(id, 10) : null;
if (!taskId) {
log.error('Task ID is required');
return {
@@ -95,9 +80,10 @@ export async function expandTaskDirect(args, log, context = {}) {
}
// Process other parameters
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
const useResearch = args.research === true;
const additionalContext = args.prompt || '';
const numSubtasks = num ? parseInt(num, 10) : undefined;
const useResearch = research === true;
const additionalContext = prompt || '';
const forceFlag = force === true;
// Initialize AI client if needed (for expandTask function)
try {
@@ -172,15 +158,16 @@ export async function expandTaskDirect(args, log, context = {}) {
};
}
// Check for existing subtasks
// Check for existing subtasks and force flag
const hasExistingSubtasks = task.subtasks && task.subtasks.length > 0;
// If the task already has subtasks, just return it (matching core behavior)
if (hasExistingSubtasks) {
log.info(`Task ${taskId} already has ${task.subtasks.length} subtasks`);
if (hasExistingSubtasks && !forceFlag) {
log.info(
`Task ${taskId} already has ${task.subtasks.length} subtasks. Use --force to overwrite.`
);
return {
success: true,
data: {
message: `Task ${taskId} already has subtasks. Expansion skipped.`,
task,
subtasksAdded: 0,
hasExistingSubtasks
@@ -189,6 +176,14 @@ export async function expandTaskDirect(args, log, context = {}) {
};
}
// If force flag is set, clear existing subtasks
if (hasExistingSubtasks && forceFlag) {
log.info(
`Force flag set. Clearing existing subtasks for task ${taskId}.`
);
task.subtasks = [];
}
// Keep a copy of the task before modification
const originalTask = JSON.parse(JSON.stringify(task));