From 8068ce0267647c97b91a19005bf78c2dc0ed1900 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Mon, 18 May 2026 00:29:09 +0800 Subject: [PATCH] auto-sync: 2026-05-18 00:29:09 --- src/daemon/ticker.py | 53 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/src/daemon/ticker.py b/src/daemon/ticker.py index 2ac7ed8..527c6da 100644 --- a/src/daemon/ticker.py +++ b/src/daemon/ticker.py @@ -192,6 +192,7 @@ class Ticker: "dispatched": [], "review_dispatched": [], "zombie_reclaimed": [], + "cards_processed": [], } # 保存当前 project_id(供 _dispatch_pending 使用) @@ -209,34 +210,62 @@ class Ticker: zombie_reclaimed = self._check_timeouts(db_path) result["zombie_reclaimed"] = zombie_reclaimed - # 4. 调度 pending 任务 - if self.dispatcher and self.spawner: - dispatched = await self._dispatch_pending(db_path, project_id) - result["dispatched"] = dispatched + # 4. per-Card 调度(v2.7:只处理 active cards) + card_ops = CardOps(db_path) + active_cards = card_ops.list_cards(status="active") - # 5. 调度审查任务 - if self.dispatcher and self.spawner: - review_dispatched = await self._dispatch_reviews(db_path, project_id) - result["review_dispatched"] = review_dispatched + for card in active_cards: + card_result = await self._tick_card(db_path, project_id, card.id) + result["dispatched"].extend(card_result.get("dispatched", [])) + result["review_dispatched"].extend(card_result.get("review_dispatched", [])) + result["cards_processed"].append(card.id) - # 6. 写 daemon_tick 事件(直接用 get_connection,不再 Blackboard() → init_db) + # 5. 写 daemon_tick 事件(直接用 get_connection,不再 Blackboard() → init_db) conn = get_connection(db_path) try: conn.execute("BEGIN IMMEDIATE") conn.execute( - "INSERT INTO events (task_id, agent, event_type, detail) VALUES (?,?,?,?)", + "INSERT INTO events (task_id, agent, event_type, detail, card_id) VALUES (?,?,?,?,?)", (None, "daemon", "daemon_tick", - json.dumps({"tick": self._tick_count, "advanced_count": len(advanced)})), + json.dumps({"tick": self._tick_count, "advanced_count": len(advanced), + "cards_processed": len(active_cards)}), + None), ) conn.commit() finally: conn.close() - # 7. 扫描后状态 + # 6. 扫描后状态 result["summary_after"] = queries.task_summary() return result + async def _tick_card(self, db_path: Path, project_id: str, + card_id: str) -> Dict[str, Any]: + """单 Card 的 tick 处理""" + result: Dict[str, Any] = { + "dispatched": [], + "review_dispatched": [], + } + + queries = Queries(db_path) + + # 调度 pending 任务 + if self.dispatcher and self.spawner: + dispatched = await self._dispatch_pending(db_path, project_id, card_id) + result["dispatched"] = dispatched + + # 调度审查任务 + if self.dispatcher and self.spawner: + review_dispatched = await self._dispatch_reviews(db_path, project_id, card_id) + result["review_dispatched"] = review_dispatched + + # 刷新 Card 状态 + card_ops = CardOps(db_path) + card_ops.refresh_card_status(card_id) + + return result + # ------------------------------------------------------------------ # 依赖推进 # ------------------------------------------------------------------