From 18223d5a263f10a91b8b4f566f48a429b524a10b Mon Sep 17 00:00:00 2001 From: lookatbar Date: Fri, 11 Sep 2026 16:25:24 +0800 Subject: [PATCH] chore: auto release commit (2026-09-11 16:25:24) --- assets/actions.json | 26 ++++++++++++++++++++++++++ scripts/service/task_service.py | 24 +++++++++++------------- scripts/service/todo_service.py | 16 ++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/assets/actions.json b/assets/actions.json index 035b2d8..29c5c2a 100644 --- a/assets/actions.json +++ b/assets/actions.json @@ -258,6 +258,32 @@ "{{id}}" ] } + }, + { + "id": "todo-remind", + "placements": [ + "agent", + "cron" + ], + "executionProfile": "async", + "inputSchema": { + "type": "object", + "properties": { + "seconds": { + "type": "number", + "default": 3 + } + } + }, + "label": "到期提醒", + "description": "在指定时间提醒到期的待办事项。", + "entrypoint": { + "type": "cli", + "command": "todo", + "args": [ + "remind" + ] + } } ] } \ No newline at end of file diff --git a/scripts/service/task_service.py b/scripts/service/task_service.py index aaf09e2..566c871 100644 --- a/scripts/service/task_service.py +++ b/scripts/service/task_service.py @@ -261,33 +261,31 @@ def cmd_stats() -> int: # ---------------- async 任务范式(demo) ---------------- async def _run_remind_async(*, seconds: int) -> dict[str, Any]: - """模拟长耗时任务:每秒 emit 一次进度,最后 finish 终态。 - - 真实平台会推送到任务中心 UI 并支持取消;本 demo 在 stdout 打印 JSON Lines。 """ - steps = max(1, int(seconds)) - for i in range(1, steps + 1): - await interruptible_sleep(1) - emit(f"提醒任务进度 {i}/{steps}", skill=SKILL_SLUG, stage="remind", progress=i, total=steps) - # 真实业务在这里会查 todos 表挑出 due/pending 项发出提醒;demo 不做真实推送 + 真实平台会推送到任务中心 UI 并支持取消; + """ + todos = todo_service.get_current_remind_todos() + for todo in todos: + todo_service.mark_done(todo.id) + emit(f"提醒待办 {todo.title}", skill=SKILL_SLUG, stage="remind") summary = todo_service.stats() - return {"remind": True, "duration_seconds": steps, "stats": summary} + return {"remind": True, "duration_seconds": len(todos), "stats": summary} def cmd_remind(*, seconds: int = 3) -> int: """演示 async 任务编排。CLI 入口仍走同一内核;Agent 真实调度时 通过 ``run_skill_action``(executionProfile: async)触发。""" log = _get_task_logger() - task_type = "remind" + task_type = "cron" with job_context(skill=SKILL_SLUG): - log.info("task_start task_type=%s stage=remind seconds=%s", task_type, seconds) + log.info("task_start task_type=%s stage=remind", task_type) emit("开始执行提醒任务", skill=SKILL_SLUG, stage="remind") try: result = asyncio.run(_run_remind_async(seconds=seconds)) log.info("task_done task_type=%s status=ok", task_type) finish( - status="ok", - message=f"提醒任务完成,处理 {seconds} 秒", + status="success", + message=f"提醒任务完成", skill=SKILL_SLUG, stage="remind", **result, diff --git a/scripts/service/todo_service.py b/scripts/service/todo_service.py index dbc95a6..93b6543 100644 --- a/scripts/service/todo_service.py +++ b/scripts/service/todo_service.py @@ -157,6 +157,22 @@ def delete_todo(todo_id: int) -> bool: finally: conn.close() +def get_current_remind_todos() -> list[Todo]: + """获取当前需要提醒的待办。""" + now = _now() + conn = get_conn() + try: + cur = conn.cursor() + cur.execute( + "SELECT id, title, status, priority, due_at, created_at, updated_at " + "FROM todos WHERE due_at <= ? AND status = ?", + (int(now / 60) * 60 + 59, STATUS_PENDING), + ) + rows = cur.fetchall() + return [Todo(*row) for row in rows] + finally: + conn.close() + def stats() -> dict: """简单统计:用于 ``todo stats`` 命令与 demo 报告。"""