[moz] docs(§21): 新增 §11 Issue closed 事件处理设计
CI / lint (pull_request) Successful in 18s
CI / test (pull_request) Successful in 9m35s
CI / frontend (pull_request) Successful in 14s
CI / notify-on-failure (pull_request) Successful in 0s

问题:Issue 被关闭时 daemon 不感知、创建者收不到通知
设计:_handle_issues 增加 action=closed 分支
  - 通知 Issue 创建者(非关闭者)
  - 纯通知类型(auto-pass)
  - 包含关闭者 + 修复摘要
This commit is contained in:
cfdaily
2026-06-20 11:47:03 +08:00
parent e89bd51d7c
commit 48c2b8ea3d
+97 -1
View File
@@ -473,7 +473,103 @@ L2 重组后的 section 列表:
---
## §11. 不做的事
## §11. Issue closed 事件处理
### 11.1 问题
当前 `_handle_issues` 只处理 `action == "assigned"`,不处理 `action == "closed"`。Issue 被关闭时:
- daemon 不感知(webhook `issues/closed` 被忽略)
- 创建者 / 关注者收不到通知
- 如果该 Issue 对应一个活跃的 taskdaemon 不知道 Issue 已关闭
### 11.2 设计
`_handle_issues` 增加 `action == "closed"` 分支:
**谁被通知**Issue 创建者(`issue.user.login`)。
**通知内容**(通过 toolchain task 发给创建者):
- Issue 标题 + 编号
- 关闭者(`payload.sender.login`
- 关闭时间
- Issue 上最后一个 comment 的摘要(修复说明)
**通知类型**:纯通知(event_type=issue_closedverify 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. 不做的事
| 不做 | 理由 |
|------|------|