添加流转记录(原子操作)
(task_id, from_dept, to_dept, remark)
| 414 | |
| 415 | |
| 416 | def cmd_flow(task_id, from_dept, to_dept, remark): |
| 417 | """添加流转记录(原子操作)""" |
| 418 | clean_remark = _sanitize_remark(remark) |
| 419 | agent_id = _infer_agent_id_from_runtime() |
| 420 | agent_label = _AGENT_LABELS.get(agent_id, agent_id) |
| 421 | def modifier(tasks): |
| 422 | t = find_task(tasks, task_id) |
| 423 | if not t: |
| 424 | log.error(f'任务 {task_id} 不存在') |
| 425 | return tasks |
| 426 | t.setdefault('flow_log', []).append({ |
| 427 | "at": now_iso(), "from": from_dept, "to": to_dept, "remark": clean_remark, |
| 428 | "agent": agent_id, "agentLabel": agent_label, |
| 429 | }) |
| 430 | # 同步更新 org,使看板能正确显示当前所属部门 |
| 431 | t['org'] = to_dept |
| 432 | t['updatedAt'] = now_iso() |
| 433 | return tasks |
| 434 | atomic_json_update(TASKS_FILE, modifier, []) |
| 435 | _trigger_refresh() |
| 436 | log.info(f'✅ {task_id} 流转记录: {from_dept} → {to_dept}') |
| 437 | _append_audit(task_id, _infer_agent_id_from_runtime(), 'flow', from_dept, to_dept, clean_remark) |
| 438 | |
| 439 | |
| 440 | def cmd_done(task_id, output_path='', summary=''): |