diff --git a/packages/types/src/tool.ts b/packages/types/src/tool.ts index 9e807d639d..0e8fbc425a 100644 --- a/packages/types/src/tool.ts +++ b/packages/types/src/tool.ts @@ -33,6 +33,7 @@ export const toolNames = [ "new_task", "fetch_instructions", "codebase_search", + "manage_todo_list", ] as const export const toolNamesSchema = z.enum(toolNames) diff --git a/src/core/assistant-message/presentAssistantMessage.ts b/src/core/assistant-message/presentAssistantMessage.ts index 21c973ab50..7a9ac9c019 100644 --- a/src/core/assistant-message/presentAssistantMessage.ts +++ b/src/core/assistant-message/presentAssistantMessage.ts @@ -24,6 +24,7 @@ import { askFollowupQuestionTool } from "../tools/askFollowupQuestionTool" import { switchModeTool } from "../tools/switchModeTool" import { attemptCompletionTool } from "../tools/attemptCompletionTool" import { newTaskTool } from "../tools/newTaskTool" +import { manageTodoListTool } from "../tools/manageTodoListTool" import { checkpointSave } from "../checkpoints" @@ -211,6 +212,10 @@ export async function presentAssistantMessage(cline: Task) { const modeName = getModeBySlug(mode, customModes)?.name ?? mode return `[${block.name} in ${modeName} mode: '${message}']` } + case "manage_todo_list": + return `[${block.name} for '${block.params.todo_action}']` + default: + return `[${block.name}]` } } @@ -504,6 +509,9 @@ export async function presentAssistantMessage(cline: Task) { case "new_task": await newTaskTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag) break + case "manage_todo_list": + await manageTodoListTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag) + break case "attempt_completion": await attemptCompletionTool( cline, diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap index dd621b34b8..25fb6053e9 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap @@ -353,6 +353,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/ask-mode-prompt.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/ask-mode-prompt.snap index 3b8f357e8c..f01c9bf4b0 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/ask-mode-prompt.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/ask-mode-prompt.snap @@ -250,6 +250,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap index 719e7f0ea7..c33f9c01f8 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap @@ -424,6 +424,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap index 9f3ad102e8..50920a2b3e 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap @@ -424,6 +424,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap index 2c7e9ec165..e311df0145 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap @@ -380,6 +380,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap index b4220ce2e8..15ac76bdb6 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap @@ -375,6 +375,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap index 6248770325..0a15f1d0a4 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap @@ -428,6 +428,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-false.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-false.snap index b4220ce2e8..15ac76bdb6 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-false.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-false.snap @@ -375,6 +375,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap index 1fce8bf785..0acbd699a1 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap @@ -463,6 +463,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-undefined.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-undefined.snap index b4220ce2e8..15ac76bdb6 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-undefined.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-undefined.snap @@ -375,6 +375,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-different-viewport-size.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-different-viewport-size.snap index d07dc1d874..4dbebedd0a 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-different-viewport-size.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-different-viewport-size.snap @@ -428,6 +428,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap index 9f3ad102e8..50920a2b3e 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap @@ -424,6 +424,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-undefined-mcp-hub.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-undefined-mcp-hub.snap index b4220ce2e8..15ac76bdb6 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-undefined-mcp-hub.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-undefined-mcp-hub.snap @@ -375,6 +375,54 @@ Example: +## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all + + # Tool Use Guidelines 1. In tags, assess what information you already have and what information you need to proceed with the task. diff --git a/src/core/prompts/tools/index.ts b/src/core/prompts/tools/index.ts index 736c716a27..22af6d5f11 100644 --- a/src/core/prompts/tools/index.ts +++ b/src/core/prompts/tools/index.ts @@ -22,6 +22,7 @@ import { getAccessMcpResourceDescription } from "./access-mcp-resource" import { getSwitchModeDescription } from "./switch-mode" import { getNewTaskDescription } from "./new-task" import { getCodebaseSearchDescription } from "./codebase-search" +import { getManageTodoListDescription } from "./manage-todo-list" import { CodeIndexManager } from "../../../services/code-index/manager" // Map of tool names to their description functions @@ -43,6 +44,7 @@ const toolDescriptionMap: Record string | undefined> new_task: (args) => getNewTaskDescription(args), insert_content: (args) => getInsertContentDescription(args), search_and_replace: (args) => getSearchAndReplaceDescription(args), + manage_todo_list: () => getManageTodoListDescription(), apply_diff: (args) => args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "", } diff --git a/src/core/prompts/tools/manage-todo-list.ts b/src/core/prompts/tools/manage-todo-list.ts new file mode 100644 index 0000000000..0624d735a0 --- /dev/null +++ b/src/core/prompts/tools/manage-todo-list.ts @@ -0,0 +1,49 @@ +export function getManageTodoListDescription(): string { + return `## manage_todo_list +Description: Manage a todo list to track progress during complex task execution. This tool helps ensure no steps are missed by maintaining a persistent list of tasks and their completion status. Use this tool to add items, mark them as complete, view the current list, or clear completed items. +Parameters: +- todo_action: (required) The action to perform. Valid values are: + - "add": Add a new item to the todo list + - "complete": Mark an item as completed + - "list": Display the current todo list with completion status + - "clear_completed": Remove all completed items from the list + - "clear_all": Clear the entire todo list +- todo_item: (required for "add" action) The description of the todo item to add +- item_id: (required for "complete" action) The ID of the item to mark as completed + +Usage: + +action_name +item description (for add action) +item_id (for complete action) + + +Examples: + +1. Add a new todo item: + +add +Create user authentication system + + +2. Mark an item as completed: + +complete +1 + + +3. View the current todo list: + +list + + +4. Clear completed items: + +clear_completed + + +5. Clear all items: + +clear_all +` +} diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index 46da7485ed..e2ca4106ad 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -184,6 +184,15 @@ export class Task extends EventEmitter { consecutiveMistakeCountForApplyDiff: Map = new Map() toolUsage: ToolUsage = {} + // Todo List + todoList: Array<{ + id: number + description: string + completed: boolean + createdAt: Date + }> = [] + nextTodoId: number = 1 + // Checkpoints enableCheckpoints: boolean checkpointService?: RepoPerTaskCheckpointService diff --git a/src/core/tools/manageTodoListTool.ts b/src/core/tools/manageTodoListTool.ts new file mode 100644 index 0000000000..1bed1b52b7 --- /dev/null +++ b/src/core/tools/manageTodoListTool.ts @@ -0,0 +1,162 @@ +import { Task } from "../task/Task" +import { ToolUse, AskApproval, HandleError, PushToolResult, RemoveClosingTag } from "../../shared/tools" +import { formatResponse } from "../prompts/responses" + +interface TodoItem { + id: number + description: string + completed: boolean + createdAt: Date +} + +export async function manageTodoListTool( + cline: Task, + block: ToolUse, + askApproval: AskApproval, + handleError: HandleError, + pushToolResult: PushToolResult, + removeClosingTag: RemoveClosingTag, +) { + const todoAction: string | undefined = block.params.todo_action + const todoItem: string | undefined = block.params.todo_item + const itemId: string | undefined = block.params.item_id + + try { + if (block.partial) { + await cline + .ask( + "tool", + JSON.stringify({ tool: "manageTodoList", action: removeClosingTag("todo_action", todoAction) }), + block.partial, + ) + .catch(() => {}) + return + } else { + if (!todoAction) { + cline.consecutiveMistakeCount++ + cline.recordToolError("manage_todo_list") + pushToolResult(await cline.sayAndCreateMissingParamError("manage_todo_list", "todo_action")) + return + } + + cline.consecutiveMistakeCount = 0 + + // Get or initialize the todo list from task state + let todoList: TodoItem[] = cline.todoList || [] + let nextId = cline.nextTodoId || 1 + + let result = "" + + switch (todoAction) { + case "add": { + if (!todoItem) { + cline.consecutiveMistakeCount++ + cline.recordToolError("manage_todo_list") + pushToolResult(await cline.sayAndCreateMissingParamError("manage_todo_list", "todo_item")) + return + } + + const newItem: TodoItem = { + id: nextId, + description: todoItem, + completed: false, + createdAt: new Date(), + } + todoList.push(newItem) + cline.nextTodoId = nextId + 1 + result = `Added todo item #${nextId}: "${todoItem}"` + break + } + + case "complete": { + if (!itemId) { + cline.consecutiveMistakeCount++ + cline.recordToolError("manage_todo_list") + pushToolResult(await cline.sayAndCreateMissingParamError("manage_todo_list", "item_id")) + return + } + + const id = parseInt(itemId) + const item = todoList.find((item) => item.id === id) + if (!item) { + result = `Todo item #${id} not found` + } else if (item.completed) { + result = `Todo item #${id} is already completed` + } else { + item.completed = true + result = `Marked todo item #${id} as completed: "${item.description}"` + } + break + } + + case "list": { + if (todoList.length === 0) { + result = "Todo list is empty" + } else { + const pendingItems = todoList.filter((item) => !item.completed) + const completedItems = todoList.filter((item) => item.completed) + + result = "Current Todo List:\n\n" + + if (pendingItems.length > 0) { + result += "šŸ“‹ Pending Items:\n" + pendingItems.forEach((item) => { + result += ` ${item.id}. [ ] ${item.description}\n` + }) + } + + if (completedItems.length > 0) { + result += "\nāœ… Completed Items:\n" + completedItems.forEach((item) => { + result += ` ${item.id}. [āœ“] ${item.description}\n` + }) + } + + result += `\nTotal: ${todoList.length} items (${pendingItems.length} pending, ${completedItems.length} completed)` + } + break + } + + case "clear_completed": { + const completedCount = todoList.filter((item) => item.completed).length + todoList = todoList.filter((item) => !item.completed) + result = `Cleared ${completedCount} completed items from todo list` + break + } + + case "clear_all": { + const totalCount = todoList.length + todoList = [] + cline.nextTodoId = 1 + result = `Cleared all ${totalCount} items from todo list` + break + } + + default: + result = `Invalid todo_action: "${todoAction}". Valid actions are: add, complete, list, clear_completed, clear_all` + break + } + + // Save the updated todo list back to the task + cline.todoList = todoList + + const didApprove = await askApproval( + "tool", + JSON.stringify({ + tool: "manageTodoList", + action: todoAction, + result: result, + }), + ) + + if (!didApprove) { + return + } + + pushToolResult(result) + } + } catch (error) { + await handleError("managing todo list", error) + return + } +} diff --git a/src/shared/tools.ts b/src/shared/tools.ts index 0725e2e4d6..a8fc07712c 100644 --- a/src/shared/tools.ts +++ b/src/shared/tools.ts @@ -64,6 +64,9 @@ export const toolParamNames = [ "end_line", "query", "args", + "todo_action", + "todo_item", + "item_id", ] as const export type ToolParamName = (typeof toolParamNames)[number] @@ -163,6 +166,11 @@ export interface SearchAndReplaceToolUse extends ToolUse { Partial, "use_regex" | "ignore_case" | "start_line" | "end_line">> } +export interface ManageTodoListToolUse extends ToolUse { + name: "manage_todo_list" + params: Partial, "todo_action" | "todo_item" | "item_id">> +} + // Define tool group configuration export type ToolGroupConfig = { tools: readonly string[] @@ -188,6 +196,7 @@ export const TOOL_DISPLAY_NAMES: Record = { insert_content: "insert content", search_and_replace: "search and replace", codebase_search: "codebase search", + manage_todo_list: "manage todo list", } as const // Define available tool groups. @@ -226,6 +235,7 @@ export const ALWAYS_AVAILABLE_TOOLS: ToolName[] = [ "attempt_completion", "switch_mode", "new_task", + "manage_todo_list", ] as const export type DiffResult =