From 362e1ae6b859fc7b46a6411ebf28526ab04d8cfc Mon Sep 17 00:00:00 2001 From: cft0808 Date: Wed, 25 Mar 2026 22:26:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20cmd=5Fflow=20=E5=90=8C=E6=AD=A5=20org=20?= =?UTF-8?q?+=20cmd=5Fdone=20=E5=86=99=E5=85=A5=20outputMeta=20+=20STATE=5F?= =?UTF-8?q?ORG=5FMAP=20=E8=A1=A5=E5=85=A8=20Next=20+=20=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E9=98=88=E5=80=BC=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. cmd_flow 流转时同步更新 org=to_dept 并记录 agent 归属,修复看板流转 后仍显示旧部门的问题(#149 根因之一) 2. cmd_done 完成时立即写入 outputMeta,不再依赖异步补充 3. STATE_ORG_MAP 补全 'Next': '尚书省',修复 Next 状态 org 字段为空 4. 心跳阈值从 3/10min 调整为 5/15min,减少误报 Refs #162, Fixes #149 --- scripts/kanban_update.py | 19 +++++++++++++++++-- scripts/refresh_live_data.py | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/kanban_update.py b/scripts/kanban_update.py index 52d45a3..aa41f15 100644 --- a/scripts/kanban_update.py +++ b/scripts/kanban_update.py @@ -29,6 +29,7 @@ # 🔥 实时进展汇报(Agent 主动调用,频率不限) python3 kanban_update.py progress JJC-20260223-012 "正在分析需求,拟定3个子方案" "1.调研技术选型|2.撰写设计文档|3.实现原型" """ +import datetime import json, pathlib, sys, subprocess, logging, os, re _BASE = pathlib.Path(__file__).resolve().parent.parent @@ -43,7 +44,8 @@ from file_lock import atomic_json_read, atomic_json_update # noqa: E402 from utils import now_iso # noqa: E402 STATE_ORG_MAP = { - 'Taizi': '太子', 'Zhongshu': '中书省', 'Menxia': '门下省', 'Assigned': '尚书省', + 'Taizi': '太子', 'Zhongshu': '中书省', 'Menxia': '门下省', + 'Assigned': '尚书省', 'Next': '尚书省', 'Doing': '执行中', 'Review': '尚书省', 'Done': '完成', 'Blocked': '阻塞', } @@ -261,14 +263,19 @@ def cmd_state(task_id, new_state, now_text=None): def cmd_flow(task_id, from_dept, to_dept, remark): """添加流转记录(原子操作)""" clean_remark = _sanitize_remark(remark) + agent_id = _infer_agent_id_from_runtime() + agent_label = _AGENT_LABELS.get(agent_id, agent_id) def modifier(tasks): t = find_task(tasks, task_id) if not t: log.error(f'任务 {task_id} 不存在') return tasks t.setdefault('flow_log', []).append({ - "at": now_iso(), "from": from_dept, "to": to_dept, "remark": clean_remark + "at": now_iso(), "from": from_dept, "to": to_dept, "remark": clean_remark, + "agent": agent_id, "agentLabel": agent_label, }) + # 同步更新 org,使看板能正确显示当前所属部门 + t['org'] = to_dept t['updatedAt'] = now_iso() return tasks atomic_json_update(TASKS_FILE, modifier, []) @@ -290,6 +297,14 @@ def cmd_done(task_id, output_path='', summary=''): "at": now_iso(), "from": t.get('org', '执行部门'), "to": "皇上", "remark": f"✅ 完成:{summary or '任务已完成'}" }) + # 同步设置 outputMeta,避免依赖 refresh_live_data.py 异步补充 + if output_path: + p = pathlib.Path(output_path) + if p.exists(): + ts = datetime.datetime.fromtimestamp(p.stat().st_mtime).strftime('%Y-%m-%d %H:%M:%S') + t['outputMeta'] = {"exists": True, "lastModified": ts} + else: + t['outputMeta'] = {"exists": False, "lastModified": None} t['updatedAt'] = now_iso() return tasks atomic_json_update(TASKS_FILE, modifier, []) diff --git a/scripts/refresh_live_data.py b/scripts/refresh_live_data.py index bd96490..2d96771 100644 --- a/scripts/refresh_live_data.py +++ b/scripts/refresh_live_data.py @@ -55,9 +55,9 @@ def main(): pass if age_sec is None: t['heartbeat'] = {'status': 'unknown', 'label': '⚪ 未知', 'ageSec': None} - elif age_sec < 180: + elif age_sec < 300: t['heartbeat'] = {'status': 'active', 'label': f'🟢 活跃 {int(age_sec//60)}分钟前', 'ageSec': int(age_sec)} - elif age_sec < 600: + elif age_sec < 900: t['heartbeat'] = {'status': 'warn', 'label': f'🟡 可能停滞 {int(age_sec//60)}分钟前', 'ageSec': int(age_sec)} else: t['heartbeat'] = {'status': 'stalled', 'label': f'🔴 已停滞 {int(age_sec//60)}分钟', 'ageSec': int(age_sec)}