/**
 * cancel_task Tool
 */

import { tool, type ToolDefinition } from "@opencode-ai/plugin";
import { ParallelAgentManager } from "../../core/agents/index.js";
import { OUTPUT_LABEL } from "../../shared/index.js";

export const createCancelTaskTool = (manager: ParallelAgentManager): ToolDefinition => tool({
    description: `Cancel a running task.`,
    args: {
        taskId: tool.schema.string().describe("Task ID to cancel"),
    },
    async execute(args) {
        const cancelled = await manager.cancelTask(args.taskId);
        if (cancelled) return `${OUTPUT_LABEL.CANCELLED} task: \`${args.taskId}\``;

        const task = manager.getTask(args.taskId);
        if (task) return `${OUTPUT_LABEL.WARNING} Cannot cancel: Task is ${task.status}`;
        return `${OUTPUT_LABEL.ERROR} Not found: \`${args.taskId}\``;

    },
});
