From 48c2b8ea3dc0d4d64825965de0ffe260a359346f Mon Sep 17 00:00:00 2001 From: cfdaily Date: Sat, 20 Jun 2026 11:47:03 +0800 Subject: [PATCH] =?UTF-8?q?[moz]=20docs(=C2=A721):=20=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=C2=A711=20Issue=20closed=20=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:Issue 被关闭时 daemon 不感知、创建者收不到通知 设计:_handle_issues 增加 action=closed 分支 - 通知 Issue 创建者(非关闭者) - 纯通知类型(auto-pass) - 包含关闭者 + 修复摘要 --- docs/design/21-unified-toolchain-design.md | 98 +++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/docs/design/21-unified-toolchain-design.md b/docs/design/21-unified-toolchain-design.md index c55506c..0d789ae 100644 --- a/docs/design/21-unified-toolchain-design.md +++ b/docs/design/21-unified-toolchain-design.md @@ -473,7 +473,103 @@ L2 重组后的 section 列表: --- -## §11. 不做的事 +## §11. Issue closed 事件处理 + +### 11.1 问题 + +当前 `_handle_issues` 只处理 `action == "assigned"`,不处理 `action == "closed"`。Issue 被关闭时: +- daemon 不感知(webhook `issues/closed` 被忽略) +- 创建者 / 关注者收不到通知 +- 如果该 Issue 对应一个活跃的 task,daemon 不知道 Issue 已关闭 + +### 11.2 设计 + +`_handle_issues` 增加 `action == "closed"` 分支: + +**谁被通知**:Issue 创建者(`issue.user.login`)。 + +**通知内容**(通过 toolchain task 发给创建者): +- Issue 标题 + 编号 +- 关闭者(`payload.sender.login`) +- 关闭时间 +- Issue 上最后一个 comment 的摘要(修复说明) + +**通知类型**:纯通知(event_type=issue_closed,verify auto-pass,和 review_merged 一样)。 + +**特殊情况**: +- 如果关闭者是创建者自己(自己关自己创建的),不通知(避免自环) +- 如果 Issue 没有创建者信息或创建者不是已知 agent,跳过 + +### 11.3 实现伪代码 + +```python +# _handle_issues 中新增 +if action == "closed": + issue_creator = issue.get("user", {}).get("login", "") + closed_by = payload.get("sender", {}).get("login", "") + + # 自己关自己创建的,不通知 + if issue_creator == closed_by: + return + + # 只通知已注册的 agent + if issue_creator not in AGENT_IDS: + return + + # 读取最后一个 comment 作为修复摘要 + comments = issue.get("comments", 0) + last_comment_summary = "(无 comment)" + # 可选:调 Gitea API 读最后一个 comment + + title = f"Issue 已关闭: {issue_title} ({repo}#{issue_number})" + description = f"Issue {repo}#{issue_number} 已被 {closed_by} 关闭。\n\n{last_comment_summary}" + + _send_toolchain_task( + to_agent=issue_creator, + title=title, + description=description, + event_type="issue_closed", + action_type="issue_closed", + steps=[], # 纯通知,无步骤 + context_data={ + "issue_number": issue_number, + "repo": repo, + "issue_title": issue_title, + "closed_by": closed_by, + }, + ) +``` + +### 11.4 _ACTION_HINTS 新增 + +```python +"issue_closed": "你创建的 Issue 已被关闭。这是一条纯通知,阅读即可。", +``` + +### 11.5 EVENT_LABELS_ZH 新增 + +```python +"issue_closed": "Issue 已关闭", +``` + +### 11.6 verify_completion + +issue_closed 走 auto-pass(和 review_merged 一样),纯通知不需要 agent 动作。 + +### 11.7 涉及改动 + +| 文件 | 改动 | +|------|------| +| `src/api/toolchain_routes.py` `_handle_issues` | 新增 `action == "closed"` 分支 | +| `src/daemon/toolchain_handler.py` `_ACTION_HINTS` | 新增 issue_closed | +| `src/daemon/toolchain_handler.py` `EVENT_LABELS_ZH` | 新增 issue_closed | +| `src/daemon/toolchain_handler.py` `verify_completion` | issue_closed auto-pass | +| `templates/toolchain/issue_closed.md` | 新建通知模板 | +| `tests/` | 新增 closed 事件测试 | + +--- + +## §12. 不做的事 | 不做 | 理由 | |------|------|