feat: added handling to get-task

This commit is contained in:
Shrey Paharia
2025-04-24 00:13:09 +05:30
parent 33d2569ace
commit be8fe8092f
3 changed files with 33 additions and 8 deletions

View File

@@ -3,7 +3,10 @@
* Direct function implementation for showing task details
*/
import { findTaskById } from '../../../../scripts/modules/utils.js';
import {
findTaskById,
readComplexityReport
} from '../../../../scripts/modules/utils.js';
import { readJSON } from '../../../../scripts/modules/utils.js';
import { getCachedOrExecute } from '../../tools/utils.js';
import {
@@ -17,12 +20,13 @@ import {
* @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 or subtask to show.
* @param {string} args.reportPath - Explicit path to the complexity report file.
* @param {Object} log - Logger object
* @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
*/
export async function showTaskDirect(args, log) {
// Destructure expected args
const { tasksJsonPath, id } = args;
const { tasksJsonPath, reportPath, id } = args;
if (!tasksJsonPath) {
log.error('showTaskDirect called without tasksJsonPath');
@@ -51,7 +55,7 @@ export async function showTaskDirect(args, log) {
}
// Generate cache key using the provided task path and ID
const cacheKey = `showTask:${tasksJsonPath}:${taskId}`;
const cacheKey = `showTask:${tasksJsonPath}:${taskId}:${reportPath}`;
// Define the action function to be executed on cache miss
const coreShowTaskAction = async () => {
@@ -76,8 +80,11 @@ export async function showTaskDirect(args, log) {
};
}
// Read the complexity report
const complexityReport = readComplexityReport(reportPath);
// Find the specific task
const task = findTaskById(data.tasks, taskId);
const task = findTaskById(data.tasks, taskId, complexityReport);
if (!task) {
disableSilentMode(); // Disable before returning

View File

@@ -10,7 +10,10 @@ import {
getProjectRootFromSession
} from './utils.js';
import { showTaskDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
import {
findTasksJsonPath,
findComplexityReportPath
} from '../core/utils/path-utils.js';
/**
* Custom processor function that removes allTasks from the response
@@ -41,6 +44,12 @@ export function registerShowTaskTool(server) {
parameters: z.object({
id: z.string().describe('Task ID to get'),
file: z.string().optional().describe('Absolute path to the tasks file'),
complexityReport: z
.string()
.optional()
.describe(
'Path to the complexity report file (relative to project root or absolute)'
),
projectRoot: z
.string()
.describe('The directory of the project. Must be an absolute path.')
@@ -89,10 +98,22 @@ export function registerShowTaskTool(server) {
log.info(`Attempting to use tasks file path: ${tasksJsonPath}`);
// Resolve the path to complexity report
let complexityReportPath;
try {
complexityReportPath = findComplexityReportPath(
rootFolder,
args.complexityReport,
log
);
} catch (error) {
log.error(`Error finding complexity report: ${error.message}`);
}
const result = await showTaskDirect(
{
// Pass the explicitly resolved path
tasksJsonPath: tasksJsonPath,
reportPath: complexityReportPath,
// Pass other relevant args
id: args.id
},

View File

@@ -91,9 +91,6 @@ export function registerListTasksTool(server) {
);
} catch (error) {
log.error(`Error finding complexity report: ${error.message}`);
return createErrorResponse(
`Failed to find complexity report: ${error.message}`
);
}
const result = await listTasksDirect(
{