import { Type } from "typebox";
import { getAgentState } from "../../state.js";
const todoStatusSchema = Type.Union([
    Type.Literal("pending"),
    Type.Literal("in_progress"),
    Type.Literal("completed"),
]);
const todoItemSchema = Type.Object({
    content: Type.String({ description: "The task description." }),
    status: todoStatusSchema,
});
const todoWriteParams = Type.Object({
    todos: Type.Array(todoItemSchema, {
        description: "The full current todo list. Always provide the complete list, not just changed items.",
    }),
});
function summarizeTodos(todos) {
    if (todos.length === 0)
        return "Todo list cleared.";
    const counts = todos.reduce((acc, todo) => {
        acc[todo.status] = (acc[todo.status] ?? 0) + 1;
        return acc;
    }, {});
    const parts = ["pending", "in_progress", "completed"]
        .filter((status) => counts[status])
        .map((status) => `${status}: ${counts[status]}`)
        .join(", ");
    return `Todo list updated (${todos.length} item${todos.length === 1 ? "" : "s"}${parts ? `; ${parts}` : ""}).`;
}
export const todoWriteTool = {
    name: "TodoWrite",
    label: "TodoWrite",
    description: "Create or update the current task todo list. Use this for multi-step coding work so progress is visible and recoverable.",
    promptSnippet: "TodoWrite — create or update the current task todo list for multi-step work.",
    promptGuidelines: [
        "Use TodoWrite for non-trivial multi-step tasks; keep exactly one item in_progress when actively working.",
        "Update todos as work progresses and mark items completed promptly.",
    ],
    parameters: todoWriteParams,
    execute: (_toolCallId, params) => {
        const todos = params.todos.map((todo) => ({
            content: todo.content,
            status: todo.status,
        }));
        getAgentState().activityTracker.recordTodos(todos);
        return Promise.resolve({ content: [{ type: "text", text: summarizeTodos(todos) }], details: undefined });
    },
};
//# sourceMappingURL=todo-tool.js.map