From 9ded11de7a819cb83146f8c046570564e5760410 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Fri, 30 Jan 2026 18:50:02 +0800 Subject: [PATCH] feat: support batch todo updates --- core/main_terminal.py | 18 +++++++++++++---- modules/todo_manager.py | 44 +++++++++++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/core/main_terminal.py b/core/main_terminal.py index a6aaa55..45fc486 100644 --- a/core/main_terminal.py +++ b/core/main_terminal.py @@ -1721,14 +1721,21 @@ class MainTerminal: "type": "function", "function": { "name": "todo_update_task", - "description": "勾选或取消指定任务;全部勾选时提示所有任务已完成。", + "description": "批量勾选或取消任务(支持单个或多个任务);全部勾选时提示所有任务已完成。", "parameters": { "type": "object", "properties": self._inject_intent({ - "task_index": {"type": "integer", "description": "任务序号(1-8)"}, + "task_index": {"type": "integer", "description": "任务序号(1-8),兼容旧参数"}, + "task_indices": { + "type": "array", + "items": {"type": "integer"}, + "minItems": 1, + "maxItems": 8, + "description": "要更新的任务序号列表(1-8),可一次勾选多个" + }, "completed": {"type": "boolean", "description": "true=打勾,false=取消"} }), - "required": ["task_index", "completed"] + "required": ["completed"] } } }, @@ -2349,8 +2356,11 @@ class MainTerminal: ) elif tool_name == "todo_update_task": + task_indices = arguments.get("task_indices") + if task_indices is None: + task_indices = arguments.get("task_index") result = self.todo_manager.update_task_status( - task_index=arguments.get("task_index"), + task_indices=task_indices, completed=arguments.get("completed", True) ) diff --git a/modules/todo_manager.py b/modules/todo_manager.py index 48b267a..4e3f419 100644 --- a/modules/todo_manager.py +++ b/modules/todo_manager.py @@ -109,21 +109,44 @@ class TodoManager: "todo_list": todo } - def update_task_status(self, task_index: int, completed: bool) -> Dict[str, Any]: + def update_task_status(self, task_indices: Any, completed: bool) -> Dict[str, Any]: todo = self._get_current() if not todo: return {"success": False, "error": "当前没有待办列表,请先创建。"} if todo.get("status") in {"completed", "closed"}: return {"success": False, "error": "待办列表已结束,无法继续修改。"} - if not isinstance(task_index, int): - return {"success": False, "error": "task_index 必须是数字。"} - if task_index < 1 or task_index > len(todo["tasks"]): - return {"success": False, "error": f"task_index 超出范围(1-{len(todo['tasks'])})。"} + # 兼容单个/多个序号 + if isinstance(task_indices, int): + indices = [task_indices] + elif isinstance(task_indices, list): + indices = [] + for idx in task_indices: + if isinstance(idx, int): + indices.append(idx) + else: + return {"success": False, "error": "task_index 或 task_indices 必须是数字或数字数组。"} + + if not indices: + return {"success": False, "error": "请提供至少一个任务序号。"} + + valid_max = len(todo["tasks"]) + invalid = [i for i in indices if i < 1 or i > valid_max] + if invalid: + return {"success": False, "error": f"任务序号超出范围(1-{valid_max}):{invalid}"} + + # 去重保持顺序 + seen = set() + normalized = [] + for i in indices: + if i not in seen: + seen.add(i) + normalized.append(i) - task = todo["tasks"][task_index - 1] new_status = "done" if completed else "pending" - task["status"] = new_status + for task_index in normalized: + task = todo["tasks"][task_index - 1] + task["status"] = new_status self._save(todo) all_done = all(t["status"] == "done" for t in todo["tasks"]) @@ -133,9 +156,14 @@ class TodoManager: "message": "所有任务已完成。", "todo_list": todo } + if len(normalized) == 1: + msg = f"任务 {normalized[0]}{'完成' if completed else '取消完成'}。" + else: + joined = ", ".join(str(i) for i in normalized) + msg = f"任务 {joined}{'全部完成' if completed else '已取消完成'}。" return { "success": True, - "message": f"任务 {task_index}{'完成' if completed else '取消完成'}。", + "message": msg, "todo_list": todo }