fix(move-task): Fix critical bugs in task move functionality
- Fixed parent-to-parent task moves where original task would remain as duplicate - Fixed moving tasks to become subtasks of empty parents (validation errors) - Fixed moving subtasks between different parent tasks - Improved comma-separated batch moves with proper error handling - Updated MCP tool to use core logic instead of custom implementation - Resolves task duplication issues and enables proper task hierarchy reorganization
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -3,14 +3,14 @@
|
||||
* Tool for moving tasks or subtasks to a new position
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse,
|
||||
withNormalizedProjectRoot
|
||||
} from './utils.js';
|
||||
import { moveTaskDirect } from '../core/task-master-core.js';
|
||||
import { findTasksPath } from '../core/utils/path-utils.js';
|
||||
withNormalizedProjectRoot,
|
||||
} from "./utils.js";
|
||||
import { moveTaskDirect } from "../core/task-master-core.js";
|
||||
import { findTasksPath } from "../core/utils/path-utils.js";
|
||||
|
||||
/**
|
||||
* Register the moveTask tool with the MCP server
|
||||
@@ -18,8 +18,8 @@ import { findTasksPath } from '../core/utils/path-utils.js';
|
||||
*/
|
||||
export function registerMoveTaskTool(server) {
|
||||
server.addTool({
|
||||
name: 'move_task',
|
||||
description: 'Move a task or subtask to a new position',
|
||||
name: "move_task",
|
||||
description: "Move a task or subtask to a new position",
|
||||
parameters: z.object({
|
||||
from: z
|
||||
.string()
|
||||
@@ -31,12 +31,12 @@ export function registerMoveTaskTool(server) {
|
||||
.describe(
|
||||
'ID of the destination (e.g., "7" or "7.3"). Must match the number of source IDs if comma-separated'
|
||||
),
|
||||
file: z.string().optional().describe('Custom path to tasks.json file'),
|
||||
file: z.string().optional().describe("Custom path to tasks.json file"),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.describe(
|
||||
'Root directory of the project (typically derived from session)'
|
||||
)
|
||||
"Root directory of the project (typically derived from session)"
|
||||
),
|
||||
}),
|
||||
execute: withNormalizedProjectRoot(async (args, { log, session }) => {
|
||||
try {
|
||||
@@ -48,14 +48,14 @@ export function registerMoveTaskTool(server) {
|
||||
}
|
||||
|
||||
// Parse comma-separated IDs
|
||||
const fromIds = args.from.split(',').map((id) => id.trim());
|
||||
const toIds = args.to.split(',').map((id) => id.trim());
|
||||
const fromIds = args.from.split(",").map((id) => id.trim());
|
||||
const toIds = args.to.split(",").map((id) => id.trim());
|
||||
|
||||
// Validate matching IDs count
|
||||
if (fromIds.length !== toIds.length) {
|
||||
return createErrorResponse(
|
||||
'The number of source and destination IDs must match',
|
||||
'MISMATCHED_ID_COUNT'
|
||||
"The number of source and destination IDs must match",
|
||||
"MISMATCHED_ID_COUNT"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ export function registerMoveTaskTool(server) {
|
||||
sourceId: fromId,
|
||||
destinationId: toId,
|
||||
tasksJsonPath,
|
||||
projectRoot: args.projectRoot
|
||||
projectRoot: args.projectRoot,
|
||||
},
|
||||
log,
|
||||
{ session }
|
||||
@@ -99,8 +99,8 @@ export function registerMoveTaskTool(server) {
|
||||
success: true,
|
||||
data: {
|
||||
moves: results,
|
||||
message: `Successfully moved ${results.length} tasks`
|
||||
}
|
||||
message: `Successfully moved ${results.length} tasks`,
|
||||
},
|
||||
},
|
||||
log
|
||||
);
|
||||
@@ -112,7 +112,7 @@ export function registerMoveTaskTool(server) {
|
||||
sourceId: args.from,
|
||||
destinationId: args.to,
|
||||
tasksJsonPath,
|
||||
projectRoot: args.projectRoot
|
||||
projectRoot: args.projectRoot,
|
||||
},
|
||||
log,
|
||||
{ session }
|
||||
@@ -123,9 +123,9 @@ export function registerMoveTaskTool(server) {
|
||||
} catch (error) {
|
||||
return createErrorResponse(
|
||||
`Failed to move task: ${error.message}`,
|
||||
'MOVE_TASK_ERROR'
|
||||
"MOVE_TASK_ERROR"
|
||||
);
|
||||
}
|
||||
})
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user