🔥 实时进展汇报 — Agent 主动调用,不改变状态,只更新 now + todos now_text: 当前正在做什么的一句话描述(必填) todos_pipe: 可选,用 | 分隔的 todo 列表,格式: "已完成的事项✅|正在做的事项🔄|计划做的事项" - 以 ✅ 结尾 → completed - 以 🔄 结尾 → in-progress - 其他 → not-started tokens: 可选,本次消耗的 token 数 cost: 可选,本次成本(美元) elapsed:
(task_id, now_text, todos_pipe='', tokens=0, cost=0.0, elapsed=0)
| 554 | |
| 555 | |
| 556 | def cmd_progress(task_id, now_text, todos_pipe='', tokens=0, cost=0.0, elapsed=0): |
| 557 | """🔥 实时进展汇报 — Agent 主动调用,不改变状态,只更新 now + todos |
| 558 | |
| 559 | now_text: 当前正在做什么的一句话描述(必填) |
| 560 | todos_pipe: 可选,用 | 分隔的 todo 列表,格式: |
| 561 | "已完成的事项✅|正在做的事项🔄|计划做的事项" |
| 562 | - 以 ✅ 结尾 → completed |
| 563 | - 以 🔄 结尾 → in-progress |
| 564 | - 其他 → not-started |
| 565 | tokens: 可选,本次消耗的 token 数 |
| 566 | cost: 可选,本次成本(美元) |
| 567 | elapsed: 可选,本次耗时(秒) |
| 568 | """ |
| 569 | clean = _sanitize_remark(now_text) |
| 570 | # 解析 todos_pipe |
| 571 | parsed_todos = None |
| 572 | if todos_pipe: |
| 573 | new_todos = [] |
| 574 | for i, item in enumerate(todos_pipe.split('|'), 1): |
| 575 | item = item.strip() |
| 576 | if not item: |
| 577 | continue |
| 578 | if item.endswith('✅'): |
| 579 | status = 'completed' |
| 580 | title = item[:-1].strip() |
| 581 | elif item.endswith('🔄'): |
| 582 | status = 'in-progress' |
| 583 | title = item[:-1].strip() |
| 584 | else: |
| 585 | status = 'not-started' |
| 586 | title = item |
| 587 | new_todos.append({'id': str(i), 'title': title, 'status': status}) |
| 588 | if new_todos: |
| 589 | parsed_todos = new_todos |
| 590 | |
| 591 | # 解析资源消耗参数 |
| 592 | try: |
| 593 | tokens = int(tokens) if tokens else 0 |
| 594 | except (ValueError, TypeError): |
| 595 | tokens = 0 |
| 596 | try: |
| 597 | cost = float(cost) if cost else 0.0 |
| 598 | except (ValueError, TypeError): |
| 599 | cost = 0.0 |
| 600 | try: |
| 601 | elapsed = int(elapsed) if elapsed else 0 |
| 602 | except (ValueError, TypeError): |
| 603 | elapsed = 0 |
| 604 | |
| 605 | done_cnt = [0] |
| 606 | total_cnt = [0] |
| 607 | def modifier(tasks): |
| 608 | t = find_task(tasks, task_id) |
| 609 | if not t: |
| 610 | log.error(f'任务 {task_id} 不存在') |
| 611 | return tasks |
| 612 | t['now'] = clean |
| 613 | if parsed_todos is not None: |
no test coverage detected