MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / execute

Method execute

src/core/tools/UpdateTodoListTool.ts:19–87  ·  view source on GitHub ↗
(params: UpdateTodoListParams, task: Task, callbacks: ToolCallbacks)

Source from the content-addressed store, hash-verified

17 readonly name = "update_todo_list" as const
18
19 async execute(params: UpdateTodoListParams, task: Task, callbacks: ToolCallbacks): Promise<void> {
20 const { pushToolResult, handleError, askApproval } = callbacks
21
22 try {
23 const todosRaw = params.todos
24
25 let todos: TodoItem[]
26 try {
27 todos = parseMarkdownChecklist(todosRaw || "")
28 } catch {
29 task.consecutiveMistakeCount++
30 task.recordToolError("update_todo_list")
31 task.didToolFailInCurrentTurn = true
32 pushToolResult(formatResponse.toolError("The todos parameter is not valid markdown checklist or JSON"))
33 return
34 }
35
36 const { valid, error } = validateTodos(todos)
37 if (!valid) {
38 task.consecutiveMistakeCount++
39 task.recordToolError("update_todo_list")
40 task.didToolFailInCurrentTurn = true
41 pushToolResult(formatResponse.toolError(error || "todos parameter validation failed"))
42 return
43 }
44
45 let normalizedTodos: TodoItem[] = todos.map((t) => ({
46 id: t.id,
47 content: t.content,
48 status: normalizeStatus(t.status),
49 }))
50
51 const approvalMsg = JSON.stringify({
52 tool: "updateTodoList",
53 todos: normalizedTodos,
54 })
55
56 approvedTodoList = cloneDeep(normalizedTodos)
57 const didApprove = await askApproval("tool", approvalMsg)
58 if (!didApprove) {
59 pushToolResult("User declined to update the todoList.")
60 return
61 }
62
63 const isTodoListChanged =
64 approvedTodoList !== undefined && JSON.stringify(normalizedTodos) !== JSON.stringify(approvedTodoList)
65 if (isTodoListChanged) {
66 normalizedTodos = approvedTodoList ?? []
67 task.say(
68 "user_edit_todos",
69 JSON.stringify({
70 tool: "updateTodoList",
71 todos: normalizedTodos,
72 }),
73 )
74 }
75
76 await setTodoListForTask(task, normalizedTodos)

Callers

nothing calls this directly

Calls 10

pushToolResultFunction · 0.85
validateTodosFunction · 0.85
normalizeStatusFunction · 0.85
askApprovalFunction · 0.85
setTodoListForTaskFunction · 0.85
todoListToMarkdownFunction · 0.85
handleErrorFunction · 0.85
recordToolErrorMethod · 0.80
sayMethod · 0.80
parseMarkdownChecklistFunction · 0.70

Tested by

no test coverage detected