dsh-inbox-bridge 2.16.3 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.en.md +4 -1
- package/README.md +4 -1
- package/client.js +4 -2
- package/docs/configuration.md +2 -0
- package/docs/how-it-works.md +8 -0
- package/docs/index.json +5 -5
- package/index.js +2 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
- package/scripts/github-inbox.mjs +129 -4
- package/scripts/github-inbox.test.mjs +105 -0
- package/scripts/inbox-bridge.mjs +364 -1
- package/scripts/inbox-bridge.test.mjs +169 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 2.17.0
|
|
2
|
+
|
|
3
|
+
- 新命令 `doctor`:逐项自检身份(App 安装令牌一小时过期,过期时这里直接 fail)、订阅的仓库是否可读、每个仓库上次轮询离现在多久、队列积压与过期投递、归档登录是否还在。有 fail 时退出码 1,适合放进脚本。
|
|
4
|
+
- 新命令 `explain <key>`:回答「这件事走到哪一步了」——没被报出、被 `roles` 挡住、仓库不在订阅里、在等你这一轮、已投递还在重提窗口里,或者已经收口。
|
|
5
|
+
- 事件来源多了两类:开着的 Dependabot 与 code scanning 告警(按告警编号做 key,修掉后下一次轮询自动收口);我作为作者或指派人的 PR 与基分支冲突或落后。仓库没开 Dependabot、或令牌没有 `security_events` 权限时只记一笔,不会跳过整次轮询。
|
|
6
|
+
- 干净的 PR 的 key 不变,新增的合并状态不会让已投递的事实重新提醒。
|
|
7
|
+
|
|
8
|
+
## 2.16.4
|
|
9
|
+
|
|
10
|
+
- 商店与设置页里的简介还写着「空闲时不发请求」,而 2.16.2 起唤醒模式必须空闲取数才能叫醒你。改成按模式说明:为唤醒服务的空闲取数只在能开轮的模式里发生,默认的只注入模式空闲时依旧不发任何请求。
|
|
1
11
|
## 2.16.3
|
|
2
12
|
|
|
3
13
|
- 修掉一处会静默丢掉订阅的配置缺陷:页面覆盖层与 profile 各自改一个键,两者偶尔会互相矛盾(页面选过 `quiet`,profile 里写着 wakeup 用的角色)。旧逻辑因此拒绝整份覆盖层并静默丢弃,连页面上订阅的仓库一起消失,队列从此只读工作目录那一个仓库。现在只让不生效的那个键闲置,启动行会说明;覆盖层真被拒绝时也会写一行 `overlay ignored: …`,不再无声。
|
package/README.en.md
CHANGED
|
@@ -26,6 +26,7 @@ That is also why it only reads: its job is to make the agent aware. The work hap
|
|
|
26
26
|
- **Relevance comes from your identity.** It queries the repositories as your `gh` login (or a configured App identity) and keeps only events where you are the author, the reviewer, the assignee, or are mentioned. Failed checks on someone else's PR, and unrelated repositories, never enter the queue.
|
|
27
27
|
- **It reads repositories, not the notification inbox.** GitHub's notification inbox pushes per account and cannot tell one session or repository from another; querying repository state directly keeps two repositories on the same account apart.
|
|
28
28
|
- **Polling follows turns.** Once when a session starts, every minute while a turn runs, once when it ends; an idle session makes no request. Only with `delivery: wakeup` does it also read on that interval while idle — without that it could never wake you while you are away.
|
|
29
|
+
- **It also watches security and merge state.** Open Dependabot and code-scanning alerts, and a pull request of yours that conflicts with the base branch or is behind it, matter as much as a red check.
|
|
29
30
|
- **It goes into the context, and opens a turn only when it has to.** By default a notice arrives at the next safe injection point and does not interrupt the tool loop; with `delivery: wakeup` it opens a turn only for a listed `wakeOn` role, with the session idle for 15 minutes, at most 3 times in a row per session, and at most 2 times an hour — anything else keeps queueing. A notice is marked `delivered`, and unhandled events come back once after six hours.
|
|
30
31
|
|
|
31
32
|
## What you will see
|
|
@@ -38,7 +39,7 @@ At the top of a turn:
|
|
|
38
39
|
>
|
|
39
40
|
> Act only where it affects the current work; when done, run `node "...\dsh-inbox-bridge\scripts\inbox-bridge.mjs" ack --done -- <key>`.
|
|
40
41
|
|
|
41
|
-
The bracket states the relation to that identity: `reviewer` means it waits for your review, `author` means you opened it, `assignee` means it is assigned to you, `mention` means a comment mentions you. Run the `ack` command when you are done; an unacknowledged event is repeated after six hours rather than piling up.
|
|
42
|
+
`[Dependabot]` is an open dependency advisory and `[Code scanning]` an open code-scanning alert. The rest of the bracket states the relation to that identity: `reviewer` means it waits for your review, `author` means you opened it, `assignee` means it is assigned to you, `mention` means a comment mentions you. Run the `ack` command when you are done; an unacknowledged event is repeated after six hours rather than piling up.
|
|
42
43
|
|
|
43
44
|
## The panel
|
|
44
45
|
|
|
@@ -79,6 +80,8 @@ All three routes install the same package; versions live on [npm](https://www.np
|
|
|
79
80
|
|
|
80
81
|
Then give it a working directory (`cwd`) in the plugin configuration. The repository and the identity are read from that directory's `git remote` and from `gh`; nothing else needs filling in.
|
|
81
82
|
|
|
83
|
+
To see what it can actually see: `node scripts/inbox-bridge.mjs doctor` walks the identity, repository access, each repository's last poll and the queue; for one event that never reached you, `node scripts/inbox-bridge.mjs explain <key>` says where it stopped.
|
|
84
|
+
|
|
82
85
|
## Configuration
|
|
83
86
|
|
|
84
87
|
| Key | Default | Effect |
|
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
- **按身份判断相关性。** 用 `gh` 的登录身份(或配置的 App 身份)查询仓库,只保留以你为作者、评审人、指派对象或提及对象的事件;其他 PR 的检查失败、无关仓库的变动不会进入队列。
|
|
27
27
|
- **只看仓库,不看通知箱。** GitHub 的通知箱(`/notifications`)按账号推送,无法区分是哪个会话、哪个仓库;这里直接查仓库状态,因此同一个账号下的两个仓库互不干扰。
|
|
28
28
|
- **轮询跟随回合。** 会话开始时一次、进行中每 1 分钟一次、结束时一次,空闲会话不发请求;开启 `delivery: wakeup` 后空闲时也按同一间隔读一次,否则它没机会在你不在时叫醒你。
|
|
29
|
+
- **也看安全与合并状态。** 开着的 Dependabot 告警、code scanning 告警,以及我这些 PR 与基分支的冲突或落后,和 CI 失败一样是要紧的事。
|
|
29
30
|
- **送进上下文,必要时才开一轮。** 默认只在这一轮的下一次安全注入点进入会话,不打断工具循环;开启 `delivery: wakeup` 后,只有命中 `wakeOn` 的角色、会话空闲满 15 分钟、每会话连续不超过 3 次、每小时不超过 2 次时才主动开一轮,其余情况仍然排队。送达后标为 `delivered`,未处理的 6 小时后重新提醒一次。
|
|
30
31
|
|
|
31
32
|
## 你会看到什么
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
>
|
|
39
40
|
> 只在它影响当前工作时处理;处理完运行 `node "...\dsh-inbox-bridge\scripts\inbox-bridge.mjs" ack --done -- <key>` 标记完成。
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
`[Dependabot]` 表示一条开着的依赖告警,`[Code scanning]` 表示一条开着的代码告警。方括号里其余部分是该事件与该身份的关系:`reviewer` 表示你是评审人,`author` 表示你是作者,`assignee` 表示指派给你,`mention` 表示评论中提到你。处理完执行提示里的 `ack` 命令;未 ack 的事件在 6 小时后重新提示,不会重复累积。
|
|
42
43
|
|
|
43
44
|
## 界面
|
|
44
45
|
|
|
@@ -79,6 +80,8 @@ dsh plugin add dsh-inbox-bridge
|
|
|
79
80
|
|
|
80
81
|
安装后在插件配置里指定工作目录 `cwd`。仓库名与身份都从该目录的 `git remote` 与 `gh` 读取,不需要另外填写。
|
|
81
82
|
|
|
83
|
+
想确认它到底能看见什么:`node scripts/inbox-bridge.mjs doctor` 逐项检查身份、仓库可读性、每个仓库的上次轮询与队列;某件事没到眼前,用 `node scripts/inbox-bridge.mjs explain <key>` 看它卡在哪一步。
|
|
84
|
+
|
|
82
85
|
## 配置
|
|
83
86
|
|
|
84
87
|
| 键 | 默认 | 作用 |
|
package/client.js
CHANGED
|
@@ -110,6 +110,7 @@ window.__ModuleLoader__.load({
|
|
|
110
110
|
none: "未配置仓库",
|
|
111
111
|
open: "打开收件箱",
|
|
112
112
|
more: (n) => `还有 ${n} 条`,
|
|
113
|
+
kinds: { Dependabot: "依赖告警", "Code scanning": "代码告警" },
|
|
113
114
|
roles: { author: "作者", reviewer: "评审", assignee: "指派", mention: "提及", ci: "CI", any: "" },
|
|
114
115
|
ago: { now: "刚刚", minutes: (n) => `${n} 分钟前`, hours: (n) => `${n} 小时前`, days: (n) => `${n} 天前` },
|
|
115
116
|
pick: {
|
|
@@ -161,6 +162,7 @@ window.__ModuleLoader__.load({
|
|
|
161
162
|
none: "no repositories configured",
|
|
162
163
|
open: "open the inbox",
|
|
163
164
|
more: (n) => `${n} more`,
|
|
165
|
+
kinds: { Dependabot: "Dependabot", "Code scanning": "Code scan" },
|
|
164
166
|
roles: { author: "author", reviewer: "reviewer", assignee: "assignee", mention: "mention", ci: "CI", any: "" },
|
|
165
167
|
ago: { now: "just now", minutes: (n) => `${n}m ago`, hours: (n) => `${n}h ago`, days: (n) => `${n}d ago` },
|
|
166
168
|
pick: {
|
|
@@ -570,7 +572,7 @@ window.__ModuleLoader__.load({
|
|
|
570
572
|
}
|
|
571
573
|
|
|
572
574
|
function Role({ role, text }) {
|
|
573
|
-
const label = text.roles[role] ?? "";
|
|
575
|
+
const label = text.roles[role] ?? text.kinds?.[role] ?? "";
|
|
574
576
|
if (!label) return null;
|
|
575
577
|
return h("span", { style: styles.tag }, label);
|
|
576
578
|
}
|
|
@@ -591,7 +593,7 @@ window.__ModuleLoader__.load({
|
|
|
591
593
|
h(
|
|
592
594
|
"span",
|
|
593
595
|
{ style: { display: "inline-flex", gap: "6px", alignItems: "baseline", minWidth: 0 } },
|
|
594
|
-
h(Role, { role: event.
|
|
596
|
+
h(Role, { role: event.role && event.role !== "any" ? event.role : event.kind, text }),
|
|
595
597
|
event.repo
|
|
596
598
|
? h("span", { style: styles.tag, title: event.repo }, event.repo.split("/").pop())
|
|
597
599
|
: null,
|
package/docs/configuration.md
CHANGED
|
@@ -93,6 +93,8 @@ node scripts/inbox-bridge.mjs status # 仓库、身份、角色、投
|
|
|
93
93
|
node scripts/inbox-bridge.mjs poll # 立刻抓一次
|
|
94
94
|
node scripts/inbox-bridge.mjs ack --done -- <key> # 划掉一条,并停止提醒
|
|
95
95
|
node scripts/inbox-bridge.mjs ack --all-delivered --done # 把所有 delivered 一次划掉
|
|
96
|
+
node scripts/inbox-bridge.mjs doctor # 逐项自检:身份、仓库可读性、上次轮询、队列、归档登录
|
|
97
|
+
node scripts/inbox-bridge.mjs explain <key> # 某件事走到哪一步了,为什么没到你眼前 # 把所有 delivered 一次划掉
|
|
96
98
|
```
|
|
97
99
|
|
|
98
100
|
`ack` 不带 `--done` 只把它们标成 delivered,意思是「给过了但还没处理」——6 小时后会再提。经 `npm run` 转发时,`--done` 必须写在 `--` 之后,否则被 npm 吞掉。
|
package/docs/how-it-works.md
CHANGED
|
@@ -66,6 +66,8 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
|
|
|
66
66
|
| 评论 | 不是我自己发的,且 @我 |
|
|
67
67
|
| CI | 默认分支,以及我自己 PR 那条分支;红的才出声,恢复时给一条「已恢复」 |
|
|
68
68
|
| 基础设施失败 | 只提醒一次,因为再改代码也修不好它 |
|
|
69
|
+
| 安全告警 | 开着的 Dependabot 与 code scanning 告警;按告警编号做 key,修掉后下一次轮询就收口 |
|
|
70
|
+
| PR 变脏 | 我是作者或指派人,且 PR 与基分支冲突或落后;评审人不算,合并是作者的事 |
|
|
69
71
|
|
|
70
72
|
同一条事实不会因为检查状态变来变去就变成好几条通知:key 只由「需要你处理的状态」构成,`QUEUED → IN_PROGRESS → SUCCESS` 全程同一个 key。
|
|
71
73
|
|
|
@@ -88,6 +90,12 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
|
|
|
88
90
|
|
|
89
91
|
每次唤醒写一行 `woke <session> because <role>:<key>`,被拒绝写 `no wakeup: <原因>`。这样「它为什么叫我」和「它为什么没叫我」都能查。
|
|
90
92
|
|
|
93
|
+
## 出问题时先看两条命令
|
|
94
|
+
|
|
95
|
+
`doctor` 逐项自检:插件是否在这台机器跑过、身份能不能用(App 安装令牌一小时过期,过期时这里是 fail)、订阅的仓库是否可读、每个仓库上次轮询离现在多久、队列积压、归档登录是否还在。
|
|
96
|
+
|
|
97
|
+
`explain <key>` 回答一个更具体的问题:这件事走到哪一步了——没被报出、被 `roles` 挡住、仓库不在订阅里、在等你这一轮、已投递还在重提窗口里,或者已经收口。
|
|
98
|
+
|
|
91
99
|
## 已知边界
|
|
92
100
|
|
|
93
101
|
- **只读 GitHub**:不改仓库、不评论、不合并;自动审批不该长在通知插件里。
|
package/docs/index.json
CHANGED
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"zh": "GitHub 收件箱"
|
|
29
29
|
},
|
|
30
30
|
"description": {
|
|
31
|
-
"en": "Lets the agent keep watch over your repository the way a maintainer would: it reads the GitHub repositories a session subscribes to, keeps the events that concern you — failed checks, reviews waiting for you, issues assigned to you, comments that mention you — and puts them in front of the agent in its own turn, opening one by itself when the session is idle and the fact matters, so a broken check gets fixed and a review request gets reviewed without waiting for you. A chip in the status row lists them and switches delivery, message clearing and subscriptions. Read-only; waking is opt-in and gated
|
|
32
|
-
"zh": "让 agent 像维护者一样盯着你的仓库:按会话订阅的 GitHub 仓库取数,只保留与你有关、需要你处理的事件(失败的 CI、待你评审的 PR、指派给你的 issue
|
|
31
|
+
"en": "Lets the agent keep watch over your repository the way a maintainer would: it reads the GitHub repositories a session subscribes to, keeps the events that concern you — failed checks, reviews waiting for you, issues assigned to you, comments that mention you, open security alerts, and pull requests that conflict with the base branch — and puts them in front of the agent in its own turn, opening one by itself when the session is idle and the fact matters, so a broken check gets fixed and a review request gets reviewed without waiting for you. A chip in the status row lists them and switches delivery, message clearing and subscriptions. Read-only; waking is opt-in and gated, and reading while idle happens only in the mode that can wake — the default queue-only mode makes no request while idle.",
|
|
32
|
+
"zh": "让 agent 像维护者一样盯着你的仓库:按会话订阅的 GitHub 仓库取数,只保留与你有关、需要你处理的事件(失败的 CI、待你评审的 PR、指派给你的 issue、@你的评论、开着的安全告警、与基分支冲突的 PR),在自己的回合送进上下文——CI 挂了就修,有人请你评审就审,不用等你回来看;会话空闲又遇到要紧的事,它也会主动开一轮。状态行里的胶囊可查看待处理项,并切换提醒方式、消息清理与订阅仓库。只读 GitHub;主动开轮需显式开启且有四道门,为它服务的空闲取数也随模式而定——默认的只注入模式空闲时不发任何请求。"
|
|
33
33
|
},
|
|
34
34
|
"icon": "icon.svg",
|
|
35
35
|
"author": "c3115644151",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
},
|
|
51
51
|
"versions": [
|
|
52
52
|
{
|
|
53
|
-
"version": "2.
|
|
54
|
-
"publishTimestamp":
|
|
53
|
+
"version": "2.17.0",
|
|
54
|
+
"publishTimestamp": 1794912854,
|
|
55
55
|
"source": {
|
|
56
56
|
"type": "git",
|
|
57
57
|
"url": "https://github.com/c3115644151/dsh-inbox-bridge",
|
|
58
|
-
"commit": "
|
|
58
|
+
"commit": "44dc921ec4ad7afbcda547c6907ca6231ba7e351"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"dsh": ">=0.1.0"
|
package/index.js
CHANGED
|
@@ -321,7 +321,7 @@ export function apply(ctx, config) {
|
|
|
321
321
|
for (const event of events) {
|
|
322
322
|
recent.delete(event.key);
|
|
323
323
|
recent.set(event.key, {
|
|
324
|
-
kind: event.kind ?? null,
|
|
324
|
+
kind: event.label ?? event.kind ?? null,
|
|
325
325
|
role: event.role ?? null,
|
|
326
326
|
title: event.title ?? null,
|
|
327
327
|
url: event.url ?? null,
|
|
@@ -1362,7 +1362,7 @@ export function buildMessage(count, text, label = "外部收件箱") {
|
|
|
1362
1362
|
}
|
|
1363
1363
|
|
|
1364
1364
|
function describeEvent(event) {
|
|
1365
|
-
const kind = event.kind ?? "event";
|
|
1365
|
+
const kind = event.label ?? event.kind ?? "event";
|
|
1366
1366
|
const role = event.role && event.role !== "any" && event.role !== "ci" ? `/${event.role}` : "";
|
|
1367
1367
|
const ref = event.ref ? `${event.ref} ` : "";
|
|
1368
1368
|
const url = event.url ? ` ${event.url}` : "";
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "GitHub inbox",
|
|
4
|
-
"description": "Lets the agent keep watch over your repository the way a maintainer would: it reads the GitHub repositories a session subscribes to, keeps the events that concern you — failed checks, reviews waiting for you, issues assigned to you, comments that mention you — and puts them in front of the agent in its own turn, opening one by itself when the session is idle and the fact matters, so a broken check gets fixed and a review request gets reviewed without waiting for you. A chip in the status row lists them and switches delivery, message clearing and subscriptions. Read-only; waking is opt-in and gated
|
|
4
|
+
"description": "Lets the agent keep watch over your repository the way a maintainer would: it reads the GitHub repositories a session subscribes to, keeps the events that concern you — failed checks, reviews waiting for you, issues assigned to you, comments that mention you, open security alerts, and pull requests that conflict with the base branch — and puts them in front of the agent in its own turn, opening one by itself when the session is idle and the fact matters, so a broken check gets fixed and a review request gets reviewed without waiting for you. A chip in the status row lists them and switches delivery, message clearing and subscriptions. Read-only; waking is opt-in and gated, and reading while idle happens only in the mode that can wake — the default queue-only mode makes no request while idle.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "GitHub 收件箱",
|
|
4
|
-
"description": "让 agent 像维护者一样盯着你的仓库:按会话订阅的 GitHub 仓库取数,只保留与你有关、需要你处理的事件(失败的 CI、待你评审的 PR、指派给你的 issue
|
|
4
|
+
"description": "让 agent 像维护者一样盯着你的仓库:按会话订阅的 GitHub 仓库取数,只保留与你有关、需要你处理的事件(失败的 CI、待你评审的 PR、指派给你的 issue、@你的评论、开着的安全告警、与基分支冲突的 PR),在自己的回合送进上下文——CI 挂了就修,有人请你评审就审,不用等你回来看;会话空闲又遇到要紧的事,它也会主动开一轮。状态行里的胶囊可查看待处理项,并切换提醒方式、消息清理与订阅仓库。只读 GitHub;主动开轮需显式开启且有四道门,为它服务的空闲取数也随模式而定——默认的只注入模式空闲时不发任何请求。",
|
|
5
5
|
"detail": "docs/DETAIL.zh.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-inbox-bridge",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"displayName": "GitHub inbox",
|
|
5
|
-
"description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue
|
|
5
|
+
"description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "c3115644151",
|
package/scripts/github-inbox.mjs
CHANGED
|
@@ -73,8 +73,10 @@ const FAILED_CHECK_STATES = new Set([
|
|
|
73
73
|
const RUN_FIELDS =
|
|
74
74
|
"databaseId,name,displayTitle,conclusion,headSha,headBranch,workflowName,createdAt,url";
|
|
75
75
|
const PR_FIELDS =
|
|
76
|
-
"number,title,headRefName,url,statusCheckRollup,reviewDecision,updatedAt,author,reviewRequests,assignees,isDraft";
|
|
77
|
-
|
|
76
|
+
"number,title,headRefName,url,statusCheckRollup,reviewDecision,updatedAt,author,reviewRequests,assignees,isDraft,mergeStateStatus";
|
|
77
|
+
// Order inside one notice: something to fix first, then what is waiting on a
|
|
78
|
+
// person, then conversation.
|
|
79
|
+
const KIND_ORDER = { recovered: 0, security: 1, ci: 2, pr: 3, comment: 4, issue: 5 };
|
|
78
80
|
/** How a GitHub notification reason maps onto the role vocabulary. */
|
|
79
81
|
const NOTIFICATION_ROLES = {
|
|
80
82
|
review_requested: "reviewer",
|
|
@@ -106,6 +108,10 @@ Usage:
|
|
|
106
108
|
the unread badge, not the inbox history. Only threads from
|
|
107
109
|
the repositories this instance reads are touched.
|
|
108
110
|
|
|
111
|
+
Security: open Dependabot and code-scanning alerts are read as well. A repository
|
|
112
|
+
without either feature answers 403/404, which is reported (in --json)
|
|
113
|
+
instead of skipped, so one missing feature never hides the rest.
|
|
114
|
+
|
|
109
115
|
State: .work/github-inbox/state.json (one slice per repository)
|
|
110
116
|
History: .work/github-inbox/pending.md`;
|
|
111
117
|
|
|
@@ -250,11 +256,29 @@ export function tagEvents(repo, events = []) {
|
|
|
250
256
|
|
|
251
257
|
const IN_PROGRESS_CHECK_STATES = new Set(["QUEUED", "IN_PROGRESS", "PENDING", "WAITING", "REQUESTED"]);
|
|
252
258
|
|
|
259
|
+
// A pull request that cannot be merged is work, even when nothing failed: the
|
|
260
|
+
// branch has to be rebased or the conflict resolved. These two states are the
|
|
261
|
+
// ones a person has to act on; BLOCKED/UNSTABLE are already covered by the
|
|
262
|
+
// review and check digests.
|
|
263
|
+
const BLOCKED_MERGE_STATES = new Set(["DIRTY", "BEHIND"]);
|
|
264
|
+
|
|
265
|
+
export function mergeBlocker(pr) {
|
|
266
|
+
const state = String(pr?.mergeStateStatus ?? "").toUpperCase();
|
|
267
|
+
if (BLOCKED_MERGE_STATES.has(state)) return state;
|
|
268
|
+
// `gh pr list --json mergeable` answers CONFLICTING when the merge is dirty;
|
|
269
|
+
// accept it so the older field shape keeps working.
|
|
270
|
+
return String(pr?.mergeable ?? "").toUpperCase() === "CONFLICTING" ? "DIRTY" : null;
|
|
271
|
+
}
|
|
272
|
+
|
|
253
273
|
export function prStatusDigest(pr) {
|
|
254
274
|
// 摘要只反映“需要你处理的状态”:失败的检查与评审决定。
|
|
255
275
|
// 进行中或成功完成的检查不进 key,否则同一 PR 在检查跑完前会被反复当成新事件。
|
|
256
276
|
const failing = failingCheckNames(pr).sort();
|
|
257
|
-
|
|
277
|
+
const blocker = mergeBlocker(pr);
|
|
278
|
+
// 只在真的冲突/落后时才把合并状态写进 key:合并干净的 PR 保持原来的 key,
|
|
279
|
+
// 已投递的事实不会因为一次格式变化被重新提醒一次。
|
|
280
|
+
const merge = blocker ? `|merge:${blocker}` : "";
|
|
281
|
+
return `failed[${failing.join(",")}]|review:${String(pr?.reviewDecision ?? "").toUpperCase() || "NONE"}${merge}`;
|
|
258
282
|
}
|
|
259
283
|
|
|
260
284
|
export function failingCheckNames(pr) {
|
|
@@ -383,6 +407,7 @@ export function extractPrEvents(prs = [], { me = null } = {}) {
|
|
|
383
407
|
if (role === null) continue;
|
|
384
408
|
const review = String(pr?.reviewDecision ?? "").toUpperCase();
|
|
385
409
|
const failing = failingCheckNames(pr);
|
|
410
|
+
const blocker = mergeBlocker(pr);
|
|
386
411
|
const reasons = [];
|
|
387
412
|
if (role === "reviewer") {
|
|
388
413
|
// Already reviewed: the ball is back with the author.
|
|
@@ -391,6 +416,10 @@ export function extractPrEvents(prs = [], { me = null } = {}) {
|
|
|
391
416
|
} else {
|
|
392
417
|
if (failing.length) reasons.push(`checks failed: ${failing.slice(0, 4).join(", ")}`);
|
|
393
418
|
if (review === "CHANGES_REQUESTED") reasons.push("changes requested");
|
|
419
|
+
// Merging is the author's job, not the reviewer's: a reviewer reading a
|
|
420
|
+
// conflicted PR has nothing to do about the conflict.
|
|
421
|
+
if (blocker === "DIRTY") reasons.push("merge conflict with the base branch");
|
|
422
|
+
if (blocker === "BEHIND") reasons.push("behind the base branch");
|
|
394
423
|
}
|
|
395
424
|
if (reasons.length === 0) continue;
|
|
396
425
|
// A reviewer's key must not move when checks change: it is the same review
|
|
@@ -526,8 +555,58 @@ export function extractIssueEvents(issues = [], state = {}, { me = null } = {})
|
|
|
526
555
|
return events;
|
|
527
556
|
}
|
|
528
557
|
|
|
558
|
+
/**
|
|
559
|
+
* Security advisories are repository facts, not personal ones: they belong to
|
|
560
|
+
* whoever maintains the repository, so they carry role `any` and are never the
|
|
561
|
+
* reason to wake a session (unless `wakeOn` names `any`).
|
|
562
|
+
* The key is the alert number alone, so an open alert stays one entry while it
|
|
563
|
+
* is being fixed, and closes by itself once the alert is resolved — a fixed
|
|
564
|
+
* vulnerability stops being reported, and `closeResolved` settles it.
|
|
565
|
+
*/
|
|
566
|
+
export function extractSecurityEvents(alerts = []) {
|
|
567
|
+
const events = [];
|
|
568
|
+
for (const entry of Array.isArray(alerts) ? alerts : []) {
|
|
569
|
+
const alert = entry?.alert;
|
|
570
|
+
const number = alert?.number;
|
|
571
|
+
if (number == null) continue;
|
|
572
|
+
if (entry.source === "dependabot") {
|
|
573
|
+
const severity = singleLine(alert?.security_advisory?.severity ?? "unknown").toLowerCase();
|
|
574
|
+
const pkg = singleLine(alert?.dependency?.package?.name ?? "");
|
|
575
|
+
const summary = singleLine(alert?.security_advisory?.summary ?? "vulnerable dependency");
|
|
576
|
+
events.push({
|
|
577
|
+
key: `dependabot:${number}`,
|
|
578
|
+
kind: "security",
|
|
579
|
+
role: "any",
|
|
580
|
+
repo: activeRepo,
|
|
581
|
+
label: "Dependabot",
|
|
582
|
+
ref: pkg ? `${pkg} #${number}` : `#${number}`,
|
|
583
|
+
title: compact([severity, summary]),
|
|
584
|
+
url: alert?.html_url ?? "",
|
|
585
|
+
at: alert?.updated_at ?? alert?.created_at ?? null,
|
|
586
|
+
});
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
if (entry.source === "code-scanning") {
|
|
590
|
+
const rule = singleLine(alert?.rule?.description ?? alert?.rule?.id ?? "code scanning alert");
|
|
591
|
+
const where = singleLine(alert?.most_recent_instance?.location?.path ?? "");
|
|
592
|
+
events.push({
|
|
593
|
+
key: `code-scanning:${number}`,
|
|
594
|
+
kind: "security",
|
|
595
|
+
role: "any",
|
|
596
|
+
repo: activeRepo,
|
|
597
|
+
label: "Code scanning",
|
|
598
|
+
ref: where ? `${where} #${number}` : `#${number}`,
|
|
599
|
+
title: rule,
|
|
600
|
+
url: alert?.html_url ?? "",
|
|
601
|
+
at: alert?.updated_at ?? alert?.created_at ?? null,
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return events;
|
|
606
|
+
}
|
|
607
|
+
|
|
529
608
|
export function extractEvents(
|
|
530
|
-
{ runs = [], prs = [], notifications = [], comments = [], issues = [] } = {},
|
|
609
|
+
{ runs = [], prs = [], notifications = [], comments = [], issues = [], security = [] } = {},
|
|
531
610
|
state = {},
|
|
532
611
|
{ me = null } = {},
|
|
533
612
|
) {
|
|
@@ -537,6 +616,7 @@ export function extractEvents(
|
|
|
537
616
|
...extractNotificationEvents(notifications),
|
|
538
617
|
...extractCommentEvents(comments, { me }),
|
|
539
618
|
...extractIssueEvents(issues, state, { me }),
|
|
619
|
+
...extractSecurityEvents(security),
|
|
540
620
|
];
|
|
541
621
|
// Every event names the repository it came from and how this identity is
|
|
542
622
|
// involved, so delivery never has to guess either from the session's cwd.
|
|
@@ -621,6 +701,7 @@ export function pollOnce({
|
|
|
621
701
|
fetchPrs,
|
|
622
702
|
fetchFeed = () => ({ ok: true, source: "none", notifications: [], comments: [], issues: [] }),
|
|
623
703
|
fetchIssues,
|
|
704
|
+
fetchSecurity,
|
|
624
705
|
markRead,
|
|
625
706
|
} = {}) {
|
|
626
707
|
const runsResult =
|
|
@@ -649,6 +730,14 @@ export function pollOnce({
|
|
|
649
730
|
if (number != null) issueNumbers.add(number);
|
|
650
731
|
issues.push(issue);
|
|
651
732
|
}
|
|
733
|
+
// Security advisories are optional: a repository without Dependabot, or a
|
|
734
|
+
// token without the security scopes, answers 403/404. That must not skip the
|
|
735
|
+
// poll — it only means this instance cannot see those facts, and the reason
|
|
736
|
+
// is reported instead of swallowed.
|
|
737
|
+
const securityResult =
|
|
738
|
+
typeof fetchSecurity === "function" ? fetchSecurity() : { alerts: [], notes: [] };
|
|
739
|
+
const security = Array.isArray(securityResult?.alerts) ? securityResult.alerts : [];
|
|
740
|
+
const securityNotes = Array.isArray(securityResult?.notes) ? securityResult.notes : [];
|
|
652
741
|
const payload = {
|
|
653
742
|
// The default branch always counts; a feature branch counts only while this
|
|
654
743
|
// identity has an open PR from it.
|
|
@@ -661,6 +750,7 @@ export function pollOnce({
|
|
|
661
750
|
notifications: Array.isArray(feed.notifications) ? feed.notifications : [],
|
|
662
751
|
comments: Array.isArray(feed.comments) ? feed.comments : [],
|
|
663
752
|
issues,
|
|
753
|
+
security,
|
|
664
754
|
};
|
|
665
755
|
const events = extractEvents(payload, state, { me });
|
|
666
756
|
const fresh = sortEvents(repeat ? events : diffEvents(events, state));
|
|
@@ -681,6 +771,7 @@ export function pollOnce({
|
|
|
681
771
|
source: feed.ok === true ? (feed.source ?? null) : null,
|
|
682
772
|
feedSkipped:
|
|
683
773
|
feedResult && feedResult.ok === false ? (feedResult.reason ?? "feed failed") : null,
|
|
774
|
+
securityNotes,
|
|
684
775
|
};
|
|
685
776
|
}
|
|
686
777
|
|
|
@@ -711,6 +802,8 @@ export function formatEvent(event) {
|
|
|
711
802
|
return compact([`[Comment${role}] ${event.ref ?? ""}:`, title, url]);
|
|
712
803
|
case "issue":
|
|
713
804
|
return compact([`[Issue${role}] ${event.ref ?? ""}:`, title, url]);
|
|
805
|
+
case "security":
|
|
806
|
+
return compact([`[${event.label ?? "Security"}] ${event.ref ?? ""}:`, title, url]);
|
|
714
807
|
default:
|
|
715
808
|
return compact([`[${event.label ?? event.kind ?? "event"}${role}]`, title, url]);
|
|
716
809
|
}
|
|
@@ -943,6 +1036,31 @@ export function fetchOpenPullRequests(cwd) {
|
|
|
943
1036
|
return ghJson(["pr", "list", "--state", "open", "--json", PR_FIELDS], { cwd });
|
|
944
1037
|
}
|
|
945
1038
|
|
|
1039
|
+
/**
|
|
1040
|
+
* Open security advisories for the watched repository. Never fatal: a private
|
|
1041
|
+
* repository on a free plan, a disabled Dependabot, or a token without the
|
|
1042
|
+
* `security_events` scope all answer 403/404, and the poll continues.
|
|
1043
|
+
*/
|
|
1044
|
+
export function fetchSecurityAlerts(cwd) {
|
|
1045
|
+
const wanted = [
|
|
1046
|
+
{ source: "dependabot", path: "dependabot/alerts" },
|
|
1047
|
+
{ source: "code-scanning", path: "code-scanning/alerts" },
|
|
1048
|
+
];
|
|
1049
|
+
const alerts = [];
|
|
1050
|
+
const notes = [];
|
|
1051
|
+
for (const { source, path } of wanted) {
|
|
1052
|
+
const result = ghJson(["api", `repos/${activeRepo}/${path}?state=open&per_page=20`], { cwd });
|
|
1053
|
+
if (!result.ok) {
|
|
1054
|
+
notes.push(`${source} unavailable (${result.reason})`);
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
for (const alert of Array.isArray(result.value) ? result.value : []) {
|
|
1058
|
+
alerts.push({ source, alert });
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return { alerts, notes };
|
|
1062
|
+
}
|
|
1063
|
+
|
|
946
1064
|
export function notificationsSince(state, cwd) {
|
|
947
1065
|
const since =
|
|
948
1066
|
typeof state?.lastPollAt === "string" && Number.isFinite(Date.parse(state.lastPollAt))
|
|
@@ -1132,6 +1250,7 @@ function runPoll({ repoRoot, stateFile, pendingFile, state, options, now, me, re
|
|
|
1132
1250
|
const fresh = [];
|
|
1133
1251
|
const skipped = [];
|
|
1134
1252
|
const notices = [];
|
|
1253
|
+
const securityNotes = [];
|
|
1135
1254
|
const cleared = [];
|
|
1136
1255
|
const clearFailed = [];
|
|
1137
1256
|
const nextRepos = { ...normalizeStateFile(state).repos };
|
|
@@ -1151,6 +1270,7 @@ function runPoll({ repoRoot, stateFile, pendingFile, state, options, now, me, re
|
|
|
1151
1270
|
fetchPrs: () => fetchOpenPullRequests(repoRoot),
|
|
1152
1271
|
fetchIssues: () => fetchOpenIssues(repoRoot),
|
|
1153
1272
|
fetchFeed: (currentState) => fetchFeed(currentState, repoRoot),
|
|
1273
|
+
fetchSecurity: () => fetchSecurityAlerts(repoRoot),
|
|
1154
1274
|
});
|
|
1155
1275
|
if (result.skipped) {
|
|
1156
1276
|
skipped.push({ repo, reason: result.skipped });
|
|
@@ -1163,6 +1283,10 @@ function runPoll({ repoRoot, stateFile, pendingFile, state, options, now, me, re
|
|
|
1163
1283
|
cleared.push(...(result.cleared ?? []));
|
|
1164
1284
|
clearFailed.push(...(result.clearFailed ?? []));
|
|
1165
1285
|
if (result.feedSkipped) notices.push(`${repo}: feed skipped (${result.feedSkipped})`);
|
|
1286
|
+
// A repository without Dependabot / code scanning answers 403 on every poll.
|
|
1287
|
+
// That is a standing fact about the install, not news per minute, so it is
|
|
1288
|
+
// reported in `--json` and by `doctor` instead of the per-poll log line.
|
|
1289
|
+
for (const note of result.securityNotes ?? []) securityNotes.push(`${repo}: ${note}`);
|
|
1166
1290
|
nextRepos[repo] = {
|
|
1167
1291
|
...result.nextState,
|
|
1168
1292
|
lastPoll: {
|
|
@@ -1193,6 +1317,7 @@ function runPoll({ repoRoot, stateFile, pendingFile, state, options, now, me, re
|
|
|
1193
1317
|
fresh,
|
|
1194
1318
|
cleared,
|
|
1195
1319
|
clearFailed,
|
|
1320
|
+
securityNotes,
|
|
1196
1321
|
stateFile,
|
|
1197
1322
|
pendingFile,
|
|
1198
1323
|
state: withMeta,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
extractNotificationEvents,
|
|
18
18
|
extractPrEvents,
|
|
19
19
|
extractRunEvents,
|
|
20
|
+
extractSecurityEvents,
|
|
20
21
|
filterRuns,
|
|
21
22
|
formatEvent,
|
|
22
23
|
mentionsLogin,
|
|
@@ -884,3 +885,107 @@ test("clearing off never touches the threads", () => {
|
|
|
884
885
|
assert.equal(called, false);
|
|
885
886
|
assert.deepEqual(result.cleared, []);
|
|
886
887
|
});
|
|
888
|
+
|
|
889
|
+
// ---------------------------------------------------------------------------
|
|
890
|
+
// Pull requests that cannot merge, and security advisories
|
|
891
|
+
// ---------------------------------------------------------------------------
|
|
892
|
+
|
|
893
|
+
test("a conflicted pull request is work even when nothing failed", () => {
|
|
894
|
+
const author = { login: ME };
|
|
895
|
+
const conflicted = extractPrEvents(
|
|
896
|
+
[
|
|
897
|
+
{
|
|
898
|
+
number: 12,
|
|
899
|
+
title: "feat: land the thing",
|
|
900
|
+
author,
|
|
901
|
+
reviewRequests: [],
|
|
902
|
+
assignees: [],
|
|
903
|
+
reviewDecision: "",
|
|
904
|
+
mergeStateStatus: "DIRTY",
|
|
905
|
+
statusCheckRollup: [{ name: "verify", conclusion: "SUCCESS" }],
|
|
906
|
+
},
|
|
907
|
+
],
|
|
908
|
+
{ me: ME },
|
|
909
|
+
);
|
|
910
|
+
assert.equal(conflicted.length, 1);
|
|
911
|
+
assert.match(formatEvent(conflicted[0]), /merge conflict with the base branch/u);
|
|
912
|
+
assert.match(conflicted[0].key, /\|merge:DIRTY$/u);
|
|
913
|
+
|
|
914
|
+
const behind = extractPrEvents(
|
|
915
|
+
[{ number: 13, title: "x", author, reviewDecision: "", mergeStateStatus: "BEHIND" }],
|
|
916
|
+
{ me: ME },
|
|
917
|
+
);
|
|
918
|
+
assert.match(formatEvent(behind[0]), /behind the base branch/u);
|
|
919
|
+
assert.match(behind[0].key, /\|merge:BEHIND$/u);
|
|
920
|
+
|
|
921
|
+
// A reviewer reading a conflicted PR has nothing to do about the conflict:
|
|
922
|
+
// the review request is the task, and the merge state must not enter its key.
|
|
923
|
+
const asReviewer = extractPrEvents(
|
|
924
|
+
[
|
|
925
|
+
{
|
|
926
|
+
number: 14,
|
|
927
|
+
title: "x",
|
|
928
|
+
author: { login: "someone-else" },
|
|
929
|
+
reviewRequests: [{ login: ME }],
|
|
930
|
+
mergeStateStatus: "DIRTY",
|
|
931
|
+
},
|
|
932
|
+
],
|
|
933
|
+
{ me: ME },
|
|
934
|
+
);
|
|
935
|
+
assert.equal(asReviewer.length, 1);
|
|
936
|
+
assert.equal(asReviewer[0].key, "pr:14:reviewer:review-requested");
|
|
937
|
+
assert.deepEqual(asReviewer[0].reasons, ["review requested from you"]);
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
test("a clean pull request keeps the digest it had before", () => {
|
|
941
|
+
const clean = pullRequest({ mergeStateStatus: "CLEAN" });
|
|
942
|
+
assert.equal(prStatusDigest(clean), prStatusDigest(pullRequest()));
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
test("open security advisories are events keyed by the alert number", () => {
|
|
946
|
+
const alerts = [
|
|
947
|
+
{
|
|
948
|
+
source: "dependabot",
|
|
949
|
+
alert: {
|
|
950
|
+
number: 3,
|
|
951
|
+
html_url: "https://github.com/owner/repo/security/dependabot/3",
|
|
952
|
+
security_advisory: { severity: "high", summary: "Prototype pollution in foo" },
|
|
953
|
+
dependency: { package: { name: "foo" } },
|
|
954
|
+
updated_at: "2026-11-16T09:00:00Z",
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
source: "code-scanning",
|
|
959
|
+
alert: {
|
|
960
|
+
number: 7,
|
|
961
|
+
html_url: "https://github.com/owner/repo/security/code-scanning/7",
|
|
962
|
+
rule: { description: "Unvalidated input reaches the shell" },
|
|
963
|
+
most_recent_instance: { location: { path: "scripts/run.mjs" } },
|
|
964
|
+
},
|
|
965
|
+
},
|
|
966
|
+
];
|
|
967
|
+
const events = extractSecurityEvents(alerts);
|
|
968
|
+
assert.deepEqual(
|
|
969
|
+
events.map((event) => event.key),
|
|
970
|
+
["dependabot:3", "code-scanning:7"],
|
|
971
|
+
);
|
|
972
|
+
assert.equal(events[0].kind, "security");
|
|
973
|
+
assert.equal(events[0].role, "any");
|
|
974
|
+
assert.match(formatEvent(events[0]), /^\[Dependabot\] foo #3: high Prototype pollution/u);
|
|
975
|
+
assert.match(formatEvent(events[1]), /^\[Code scanning\] scripts\/run\.mjs #7: Unvalidated/u);
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
test("a repository without Dependabot still polls the rest", () => {
|
|
979
|
+
const result = pollOnce({
|
|
980
|
+
state: normalizeState({}),
|
|
981
|
+
...sources({ runs: [run()] }),
|
|
982
|
+
fetchSecurity: () => ({
|
|
983
|
+
alerts: [],
|
|
984
|
+
notes: ["dependabot unavailable (HTTP 403: Resource not accessible by integration)"],
|
|
985
|
+
}),
|
|
986
|
+
now: new Date("2026-11-15T04:00:00Z"),
|
|
987
|
+
});
|
|
988
|
+
assert.equal(result.skipped, undefined);
|
|
989
|
+
assert.equal(result.fresh.length, 1);
|
|
990
|
+
assert.match(result.securityNotes[0], /dependabot unavailable/u);
|
|
991
|
+
});
|
package/scripts/inbox-bridge.mjs
CHANGED
|
@@ -390,6 +390,348 @@ export function detectRepo(cwd) {
|
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
+
// ---------------------------------------------------------------------------
|
|
394
|
+
// doctor / explain — what this install can and cannot see
|
|
395
|
+
//
|
|
396
|
+
// The failures that actually bit users were silent: a client module that never
|
|
397
|
+
// registered, a notification scope that dropped the subscriptions, a schedule
|
|
398
|
+
// that never fired while idle. None of them produced a line saying "I could
|
|
399
|
+
// have done this and did not". These two commands answer that question without
|
|
400
|
+
// changing any behaviour.
|
|
401
|
+
// ---------------------------------------------------------------------------
|
|
402
|
+
|
|
403
|
+
function probeGh(root, args) {
|
|
404
|
+
try {
|
|
405
|
+
const stdout = execFileSync("gh", args, {
|
|
406
|
+
cwd: root,
|
|
407
|
+
encoding: "utf8",
|
|
408
|
+
timeout: 20_000,
|
|
409
|
+
windowsHide: true,
|
|
410
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
411
|
+
});
|
|
412
|
+
return { ok: true, value: String(stdout).trim() };
|
|
413
|
+
} catch (error) {
|
|
414
|
+
const stderr = typeof error?.stderr === "string" ? error.stderr : "";
|
|
415
|
+
const first = stderr.trim().split("\n")[0];
|
|
416
|
+
return {
|
|
417
|
+
ok: false,
|
|
418
|
+
reason: first || (error instanceof Error ? error.message : String(error)),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const DOCTOR_MARKS = { ok: "ok ", warn: "warn", fail: "fail" };
|
|
424
|
+
const ROLE_WORDS = new Set(["any", "author", "reviewer", "assignee", "mention", "ci"]);
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Check the install end to end: is the plugin running here, does its identity
|
|
428
|
+
* still work, can it read each subscribed repository, is each of them actually
|
|
429
|
+
* being polled, is the queue coherent, and is the sweep signed in.
|
|
430
|
+
* Every probe is injectable so the checks stay offline in tests.
|
|
431
|
+
*/
|
|
432
|
+
export function describeDoctor(root, options = {}) {
|
|
433
|
+
const readJson = options.readJson ?? readJsonFile;
|
|
434
|
+
const git = options.readGitRepo ?? detectRepo;
|
|
435
|
+
const gh = options.probeGh ?? ((argv) => probeGh(root, argv));
|
|
436
|
+
const now = options.now ?? Date.now();
|
|
437
|
+
const checks = [];
|
|
438
|
+
const add = (id, status, title, detail = null) => checks.push({ id, status, title, detail });
|
|
439
|
+
|
|
440
|
+
const runtime = readJson(resolve(root, RUNTIME_REL));
|
|
441
|
+
const source = readJson(resolve(root, SOURCE_STATE_REL));
|
|
442
|
+
const queue = readState(stateFileOf(root)).events ?? {};
|
|
443
|
+
const counts = { pending: 0, delivered: 0, done: 0 };
|
|
444
|
+
for (const entry of Object.values(queue)) {
|
|
445
|
+
if (entry?.status in counts) counts[entry.status] += 1;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (!runtime) {
|
|
449
|
+
add(
|
|
450
|
+
"plugin",
|
|
451
|
+
"warn",
|
|
452
|
+
"插件还没在这个工作区运行过(没有 runtime.json)",
|
|
453
|
+
"在 DSH 里启用 inbox-bridge;如果 profile 的 cwd 指向别的目录,那个目录才是它的工作区",
|
|
454
|
+
);
|
|
455
|
+
} else {
|
|
456
|
+
add("plugin", "ok", `插件在这里运行过:${runtime.cwd ?? root}`);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const repos =
|
|
460
|
+
Array.isArray(runtime?.repos) && runtime.repos.length > 0
|
|
461
|
+
? runtime.repos
|
|
462
|
+
: [options.repo ?? git(root)].filter(Boolean);
|
|
463
|
+
|
|
464
|
+
const identity = runtime?.identity ?? null;
|
|
465
|
+
if (!identity) {
|
|
466
|
+
add("identity", "warn", "还不知道插件用什么身份读 GitHub", "插件没运行过,或 runtime.json 里没有 identity");
|
|
467
|
+
} else if (identity.kind === "app") {
|
|
468
|
+
const live = gh(["api", "installation/repositories", "--jq", ".repositories | length"]);
|
|
469
|
+
if (live.ok) {
|
|
470
|
+
add(
|
|
471
|
+
"identity",
|
|
472
|
+
"ok",
|
|
473
|
+
`GitHub App 令牌现在有效(可列出 ${live.value} 个仓库)`,
|
|
474
|
+
"App 的安装令牌一小时过期。配置里写死一个令牌,过期后插件会安静地什么都不读——" +
|
|
475
|
+
"用 INBOX_IDENTITY_TOKEN 每轮换新令牌,或改用用户身份。",
|
|
476
|
+
);
|
|
477
|
+
} else {
|
|
478
|
+
add(
|
|
479
|
+
"identity",
|
|
480
|
+
"fail",
|
|
481
|
+
"GitHub App 令牌被拒绝",
|
|
482
|
+
`${live.reason} —— 安装令牌一小时过期,换一个新令牌再试`,
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
} else {
|
|
486
|
+
const who = gh(["api", "user", "--jq", ".login"]);
|
|
487
|
+
if (who.ok) {
|
|
488
|
+
const mismatch =
|
|
489
|
+
identity.login && identity.login !== who.value ? `runtime.json 记录的是 ${identity.login}` : null;
|
|
490
|
+
add("identity", "ok", `本机 gh 已登录为 ${who.value}`, mismatch);
|
|
491
|
+
} else {
|
|
492
|
+
add("identity", "fail", "本机 gh 没有可用的登录", who.reason);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (repos.length === 0) {
|
|
497
|
+
add("repos", "fail", "没有订阅任何仓库", "在面板里添加仓库,或给 profile 写 repos: ['owner/name']");
|
|
498
|
+
}
|
|
499
|
+
for (const repo of repos) {
|
|
500
|
+
const result = gh(["api", `repos/${repo}`, "--jq", ".full_name"]);
|
|
501
|
+
if (result.ok) add(`repo:${repo}`, "ok", `${repo} 可读`);
|
|
502
|
+
else
|
|
503
|
+
add(
|
|
504
|
+
`repo:${repo}`,
|
|
505
|
+
"fail",
|
|
506
|
+
`${repo} 读不到`,
|
|
507
|
+
`${result.reason} —— 名字写错,或这个身份没有被授权(App 需要装到这个仓库上)`,
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const intervalMs = Number(runtime?.intervalMs ?? 0);
|
|
512
|
+
const staleAfter = intervalMs > 0 ? intervalMs * 3 : 15 * 60 * 1000;
|
|
513
|
+
for (const repo of repos) {
|
|
514
|
+
const last = source?.repos?.[repo]?.lastPoll ?? null;
|
|
515
|
+
const at = Date.parse(last?.at ?? "");
|
|
516
|
+
if (!Number.isFinite(at)) {
|
|
517
|
+
add(
|
|
518
|
+
`poll:${repo}`,
|
|
519
|
+
"warn",
|
|
520
|
+
`${repo} 还没有轮询记录`,
|
|
521
|
+
"等下一次回合边界,或手动跑一次 node scripts/inbox-bridge.mjs list",
|
|
522
|
+
);
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
const age = Math.max(0, now - at);
|
|
526
|
+
const minutes = Math.round(age / 60_000);
|
|
527
|
+
if (age > staleAfter) {
|
|
528
|
+
add(
|
|
529
|
+
`poll:${repo}`,
|
|
530
|
+
"warn",
|
|
531
|
+
`${repo} 上次轮询在 ${minutes} 分钟前(间隔 ${Math.round(intervalMs / 60_000)} 分钟)`,
|
|
532
|
+
"插件可能停了,或这个仓库刚被加进订阅",
|
|
533
|
+
);
|
|
534
|
+
} else {
|
|
535
|
+
add(`poll:${repo}`, "ok", `${repo} 上次轮询在 ${minutes} 分钟前`);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const staleDelivered = Object.entries(queue).filter(([, entry]) => {
|
|
540
|
+
const at = Date.parse(entry?.at ?? "");
|
|
541
|
+
return entry?.status === "delivered" && Number.isFinite(at) && now - at > RESURFACE_MS;
|
|
542
|
+
});
|
|
543
|
+
add(
|
|
544
|
+
"queue",
|
|
545
|
+
staleDelivered.length > 0 ? "warn" : "ok",
|
|
546
|
+
`队列 pending ${counts.pending} · delivered ${counts.delivered} · done ${counts.done}`,
|
|
547
|
+
staleDelivered.length === 0
|
|
548
|
+
? null
|
|
549
|
+
: `${staleDelivered.length} 条已投递但超过 6 小时没人收口(例如 ${staleDelivered[0][0]}):` +
|
|
550
|
+
"它们到期会重提一次,然后自行收口;想立刻清掉用 ack --all-delivered",
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
if (!source) {
|
|
554
|
+
add("source", "warn", "还没有来源状态:这台机器还没轮询过 GitHub");
|
|
555
|
+
} else if (source.version !== 2 || typeof source.repos !== "object") {
|
|
556
|
+
add(
|
|
557
|
+
"source",
|
|
558
|
+
"warn",
|
|
559
|
+
"来源状态是旧格式(单仓库)",
|
|
560
|
+
"下一次轮询会把它升级成按仓库分片;在此之前 status 只显示一个仓库",
|
|
561
|
+
);
|
|
562
|
+
} else {
|
|
563
|
+
const names = Object.keys(source.repos);
|
|
564
|
+
add("source", "ok", `来源状态按仓库分片:${names.join(", ") || "(空)"}`);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (runtime?.sweep && runtime.sweep !== "off" && runtime.sweep !== null) {
|
|
568
|
+
const cookies = join(resolve(root), ".work", "browser-profile", "Default", "Cookies");
|
|
569
|
+
const cli = join(dirname(fileURLToPath(import.meta.url)), "clear-inbox.mjs");
|
|
570
|
+
if (existsSync(cookies)) {
|
|
571
|
+
add(
|
|
572
|
+
"sweep",
|
|
573
|
+
"ok",
|
|
574
|
+
"清理收件箱用的浏览器配置里有登录痕迹",
|
|
575
|
+
"这只是痕迹,不代表会话还有效;真失效时日志会写 sweep needs a one-time sign-in",
|
|
576
|
+
);
|
|
577
|
+
} else {
|
|
578
|
+
add(
|
|
579
|
+
"sweep",
|
|
580
|
+
"warn",
|
|
581
|
+
"清理收件箱还没有登录过",
|
|
582
|
+
`运行一次 node "${cli}" --login,在那个窗口里登录 GitHub(一次即可,之后无头运行复用这个配置)`,
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const summary = {
|
|
588
|
+
ok: checks.filter((check) => check.status === "ok").length,
|
|
589
|
+
warn: checks.filter((check) => check.status === "warn").length,
|
|
590
|
+
fail: checks.filter((check) => check.status === "fail").length,
|
|
591
|
+
};
|
|
592
|
+
return { at: new Date(now).toISOString(), root, repos, checks, summary };
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export function formatDoctor(report) {
|
|
596
|
+
const lines = [];
|
|
597
|
+
for (const check of report.checks) {
|
|
598
|
+
lines.push(`${DOCTOR_MARKS[check.status] ?? "····"} ${check.title}`);
|
|
599
|
+
if (check.detail) {
|
|
600
|
+
for (const line of String(check.detail).split("\n")) lines.push(` ${line}`);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
const { ok, warn, fail } = report.summary;
|
|
604
|
+
lines.push("", `${ok} ok · ${warn} warn · ${fail} fail`);
|
|
605
|
+
lines.push(
|
|
606
|
+
fail > 0
|
|
607
|
+
? "fail 是“它现在确实做不到”:先修它,否则队列会一直是空的。"
|
|
608
|
+
: warn > 0
|
|
609
|
+
? "warn 是“可能让你疑惑,但还不一定坏”:多数是还没发生的事。"
|
|
610
|
+
: "没有发现问题。",
|
|
611
|
+
);
|
|
612
|
+
return lines.join("\n");
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Why one key is (or is not) in front of an agent. Reads only local state, so
|
|
617
|
+
* it is safe to run at any time; the delivery decision is reconstructed from
|
|
618
|
+
* runtime.json (identity, repositories, roles, delivery) and the queue.
|
|
619
|
+
*/
|
|
620
|
+
export function explainKey(root, key, options = {}) {
|
|
621
|
+
const readJson = options.readJson ?? readJsonFile;
|
|
622
|
+
const now = options.now ?? Date.now();
|
|
623
|
+
const runtime = readJson(resolve(root, RUNTIME_REL));
|
|
624
|
+
const source = readJson(resolve(root, SOURCE_STATE_REL));
|
|
625
|
+
const queue = readState(stateFileOf(root)).events ?? {};
|
|
626
|
+
const cut = typeof key === "string" ? key.indexOf("#") : -1;
|
|
627
|
+
const repo = cut > 0 ? key.slice(0, cut) : null;
|
|
628
|
+
const inner = cut > 0 ? key.slice(cut + 1) : String(key ?? "");
|
|
629
|
+
const entry = queue[key] ?? null;
|
|
630
|
+
const slice =
|
|
631
|
+
repo && source?.repos && typeof source.repos === "object" ? (source.repos[repo] ?? null) : null;
|
|
632
|
+
const seenAt = slice?.seen?.[inner] ?? slice?.seen?.[key] ?? null;
|
|
633
|
+
const role = inner.split(":").find((part) => ROLE_WORDS.has(part)) ?? null;
|
|
634
|
+
const subscribed =
|
|
635
|
+
Array.isArray(runtime?.repos) && runtime.repos.length > 0 ? runtime.repos.includes(repo) : null;
|
|
636
|
+
const roleFilter = Array.isArray(runtime?.roles) ? runtime.roles : [];
|
|
637
|
+
const wakes = Array.isArray(runtime?.wakeOn) ? runtime.wakeOn : [];
|
|
638
|
+
|
|
639
|
+
const notes = [];
|
|
640
|
+
if (repo && subscribed === false) {
|
|
641
|
+
notes.push(
|
|
642
|
+
`这个仓库不在这台实例的订阅里(repos: ${runtime.repos.join(", ") || "空"}),所以它永远不会被投递`,
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
if (role && roleFilter.length > 0 && role !== "any" && !roleFilter.includes(role)) {
|
|
646
|
+
notes.push(`角色门槛挡住了它:roles 只收 ${roleFilter.join(" / ")},而它是 ${role}`);
|
|
647
|
+
}
|
|
648
|
+
if (entry || seenAt) {
|
|
649
|
+
if (role && runtime?.delivery === "wakeup") {
|
|
650
|
+
if (wakes.includes(role) || wakes.includes("any")) {
|
|
651
|
+
notes.push(
|
|
652
|
+
`命中 wakeOn:会话空闲满 ${Math.round((runtime.wakeAfterIdleMs ?? 0) / 60_000)} 分钟后` +
|
|
653
|
+
`可以替你开一轮(每会话 ${runtime.maxConsecutiveWakes} 次、每小时 ${runtime.wakesPerHour} 次)`,
|
|
654
|
+
);
|
|
655
|
+
} else {
|
|
656
|
+
notes.push(`wakeOn 里没有 ${role},所以它只排队,等你下一次发消息时才进入上下文`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (runtime?.delivery && runtime.delivery !== "wakeup") {
|
|
660
|
+
notes.push("当前是只注入模式:会随你下一次发消息进入上下文,不会替你开轮");
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
if (!runtime) notes.push("插件还没在这个工作区运行过(没有 runtime.json),下面的判断只基于本地状态");
|
|
664
|
+
if (!slice && repo) notes.push(`来源状态里没有 ${repo} 的分片:这台实例还没有轮询过它`);
|
|
665
|
+
|
|
666
|
+
let verdict;
|
|
667
|
+
let next;
|
|
668
|
+
if (entry) {
|
|
669
|
+
const status = entry.status;
|
|
670
|
+
const at = entry.at ?? null;
|
|
671
|
+
if (status === "pending") {
|
|
672
|
+
verdict = "在队列里等投递";
|
|
673
|
+
next = "下一次轮询(回合开始 / 进行中 / 结束)会把它交给仓库匹配的会话";
|
|
674
|
+
} else if (status === "delivered") {
|
|
675
|
+
const attempts = entry.attempts ?? 1;
|
|
676
|
+
verdict = `已投递 ${attempts} 次`;
|
|
677
|
+
const due = Date.parse(at ?? "");
|
|
678
|
+
if (attempts >= 2) {
|
|
679
|
+
next = "已经重提过一次仍没人处理,下一次轮询会把它收口成 done";
|
|
680
|
+
} else {
|
|
681
|
+
next =
|
|
682
|
+
"6 小时内没人收口的话会再提一次,第二次之后自动收口" +
|
|
683
|
+
(Number.isFinite(due) ? `;最早重提时间 ${new Date(due + RESURFACE_MS).toISOString()}` : "");
|
|
684
|
+
}
|
|
685
|
+
} else {
|
|
686
|
+
verdict = "已收口(done)";
|
|
687
|
+
next = "不会再被通知;事实仍然成立的话,只有 key 变化(新的失败、新的评审决定)才会重新出现";
|
|
688
|
+
}
|
|
689
|
+
if (repo && !seenAt && slice) next += ";来源这次没有报出它,下一次轮询会把它收口";
|
|
690
|
+
} else if (seenAt) {
|
|
691
|
+
verdict = "报过,但已经不在队列里";
|
|
692
|
+
next = "它被收口了:事实不再成立,或被显式 ack";
|
|
693
|
+
} else {
|
|
694
|
+
verdict = "这台实例没有报出过它";
|
|
695
|
+
next = "key 拼写不对,或者它来自别的仓库 / 别的身份";
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
return {
|
|
699
|
+
at: new Date(now).toISOString(),
|
|
700
|
+
key,
|
|
701
|
+
repo,
|
|
702
|
+
inner,
|
|
703
|
+
role,
|
|
704
|
+
entry,
|
|
705
|
+
seenAt,
|
|
706
|
+
runtime: runtime
|
|
707
|
+
? { delivery: runtime.delivery, repos: runtime.repos ?? [], roles: roleFilter, wakeOn: wakes }
|
|
708
|
+
: null,
|
|
709
|
+
verdict,
|
|
710
|
+
next,
|
|
711
|
+
notes,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
export function formatExplanation(info) {
|
|
716
|
+
const lines = [`key ${info.key}`];
|
|
717
|
+
if (info.repo) lines.push(`repo ${info.repo}`);
|
|
718
|
+
if (info.role) lines.push(`role ${info.role}`);
|
|
719
|
+
if (info.entry) {
|
|
720
|
+
const attempts = info.entry.attempts ? `(投递 ${info.entry.attempts} 次)` : "";
|
|
721
|
+
lines.push(`status ${info.entry.status}${attempts} · ${info.entry.at ?? "时间未知"}`);
|
|
722
|
+
} else if (info.seenAt) {
|
|
723
|
+
lines.push(`status 收口过 · 首次出现 ${info.seenAt}`);
|
|
724
|
+
} else {
|
|
725
|
+
lines.push("status 队列与来源状态里都没有它");
|
|
726
|
+
}
|
|
727
|
+
lines.push("", info.verdict, info.next);
|
|
728
|
+
if (info.notes.length > 0) {
|
|
729
|
+
lines.push("", "还要注意:");
|
|
730
|
+
for (const note of info.notes) lines.push(` - ${note}`);
|
|
731
|
+
}
|
|
732
|
+
return lines.join("\n");
|
|
733
|
+
}
|
|
734
|
+
|
|
393
735
|
function main(argv) {
|
|
394
736
|
const root = process.cwd();
|
|
395
737
|
const stateFile = stateFileOf(root);
|
|
@@ -439,6 +781,25 @@ function main(argv) {
|
|
|
439
781
|
return 0;
|
|
440
782
|
}
|
|
441
783
|
|
|
784
|
+
if (command === "doctor") {
|
|
785
|
+
const report = describeDoctor(root, { repo });
|
|
786
|
+
process.stdout.write(`${json ? JSON.stringify(report, null, 2) : formatDoctor(report)}\n`);
|
|
787
|
+
// A failing check is a real "it cannot work": say so in the exit code so a
|
|
788
|
+
// script (or an agent) can tell "healthy" from "looks fine but isn't".
|
|
789
|
+
return report.summary.fail > 0 ? 1 : 0;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
if (command === "explain") {
|
|
793
|
+
const key = flags.find((flag) => !flag.startsWith("--"));
|
|
794
|
+
if (!key) {
|
|
795
|
+
process.stderr.write("usage: node scripts/inbox-bridge.mjs explain <key>\n");
|
|
796
|
+
return 2;
|
|
797
|
+
}
|
|
798
|
+
const info = explainKey(root, key);
|
|
799
|
+
process.stdout.write(`${json ? JSON.stringify(info, null, 2) : formatExplanation(info)}\n`);
|
|
800
|
+
return 0;
|
|
801
|
+
}
|
|
802
|
+
|
|
442
803
|
if (command === "list") {
|
|
443
804
|
const result = pollOnce(root, { at, repo });
|
|
444
805
|
if (result.skipped) {
|
|
@@ -478,7 +839,9 @@ function main(argv) {
|
|
|
478
839
|
}
|
|
479
840
|
|
|
480
841
|
process.stderr.write(
|
|
481
|
-
"usage: node scripts/inbox-bridge.mjs [poll|list|status|ack] [--json] [--done] [--all-delivered]\n" +
|
|
842
|
+
"usage: node scripts/inbox-bridge.mjs [poll|list|status|doctor|explain|ack] [--json] [--done] [--all-delivered]\n" +
|
|
843
|
+
" doctor 体检:身份、仓库可读、轮询新鲜度、队列自洽、清理是否登录(有 fail 时退出码 1)\n" +
|
|
844
|
+
" explain <key>:这条事实现在在哪一态、会被谁收到、被哪道门挡住\n" +
|
|
482
845
|
" ack 收口:`ack --done -- <key>`;只写 `--done` 之前的写法会被包装脚本吞掉\n",
|
|
483
846
|
);
|
|
484
847
|
return 2;
|
|
@@ -9,8 +9,12 @@ import {
|
|
|
9
9
|
autoDone,
|
|
10
10
|
classify,
|
|
11
11
|
closeResolved,
|
|
12
|
+
describeDoctor,
|
|
12
13
|
describeEvent,
|
|
13
14
|
describeStatus,
|
|
15
|
+
explainKey,
|
|
16
|
+
formatDoctor,
|
|
17
|
+
formatExplanation,
|
|
14
18
|
formatStatus,
|
|
15
19
|
readState,
|
|
16
20
|
transition,
|
|
@@ -262,3 +266,168 @@ test("status explains a wakeup that cannot wake anyone", () => {
|
|
|
262
266
|
assert.match(text, /wakeup,但 wakeOn 为空(仍是只排队)/u);
|
|
263
267
|
});
|
|
264
268
|
});
|
|
269
|
+
|
|
270
|
+
// ---------------------------------------------------------------------------
|
|
271
|
+
// doctor: what this install can and cannot see
|
|
272
|
+
// ---------------------------------------------------------------------------
|
|
273
|
+
|
|
274
|
+
test("doctor says which identity can read which repository, and what is stale", () => {
|
|
275
|
+
withWorkspace((root) => {
|
|
276
|
+
writeFileSync(
|
|
277
|
+
join(root, ".work", "inbox-bridge", "runtime.json"),
|
|
278
|
+
JSON.stringify({
|
|
279
|
+
cwd: root,
|
|
280
|
+
repo: "owner/one",
|
|
281
|
+
repos: ["owner/one", "owner/two"],
|
|
282
|
+
delivery: "quiet",
|
|
283
|
+
intervalMs: 60000,
|
|
284
|
+
roles: [],
|
|
285
|
+
identity: { kind: "user", login: "c3115644151", token: null },
|
|
286
|
+
sweep: null,
|
|
287
|
+
}),
|
|
288
|
+
);
|
|
289
|
+
writeFileSync(
|
|
290
|
+
join(root, ".work", "inbox-bridge", "state.json"),
|
|
291
|
+
JSON.stringify({ events: { "owner/one#run:1": { status: "pending", at: AT } } }),
|
|
292
|
+
);
|
|
293
|
+
writeFileSync(
|
|
294
|
+
join(root, ".work", "github-inbox", "state.json"),
|
|
295
|
+
JSON.stringify({
|
|
296
|
+
version: 2,
|
|
297
|
+
repos: {
|
|
298
|
+
"owner/one": { lastPoll: { at: new Date(Date.now() - 60_000).toISOString() } },
|
|
299
|
+
"owner/two": { lastPoll: { at: new Date(Date.now() - 90 * 60_000).toISOString() } },
|
|
300
|
+
},
|
|
301
|
+
}),
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const report = describeDoctor(root, {
|
|
305
|
+
readGitRepo: () => null,
|
|
306
|
+
probeGh: (argv) => {
|
|
307
|
+
if (argv[0] === "api" && argv[1] === "user") return { ok: true, value: "c3115644151" };
|
|
308
|
+
const repo = String(argv[1] ?? "").replace(/^repos\//u, "");
|
|
309
|
+
return repo === "owner/two"
|
|
310
|
+
? { ok: false, reason: "HTTP 404: Not Found" }
|
|
311
|
+
: { ok: true, value: repo };
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
const byId = Object.fromEntries(report.checks.map((check) => [check.id, check]));
|
|
316
|
+
assert.equal(byId.identity.status, "ok");
|
|
317
|
+
assert.equal(byId["repo:owner/one"].status, "ok");
|
|
318
|
+
assert.equal(byId["repo:owner/two"].status, "fail");
|
|
319
|
+
assert.match(byId["repo:owner/two"].detail, /没有被授权/u);
|
|
320
|
+
assert.equal(byId["poll:owner/one"].status, "ok");
|
|
321
|
+
assert.equal(byId["poll:owner/two"].status, "warn");
|
|
322
|
+
assert.match(byId["poll:owner/two"].title, /上次轮询在 90 分钟前/u);
|
|
323
|
+
assert.equal(byId.queue.status, "ok");
|
|
324
|
+
assert.equal(report.summary.fail, 1);
|
|
325
|
+
|
|
326
|
+
const text = formatDoctor(report);
|
|
327
|
+
assert.match(text, /fail owner\/two 读不到/u);
|
|
328
|
+
assert.match(text, /fail 是“它现在确实做不到”/u);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("doctor calls a lapsed App token a failure, not a warning", () => {
|
|
333
|
+
withWorkspace((root) => {
|
|
334
|
+
writeFileSync(
|
|
335
|
+
join(root, ".work", "inbox-bridge", "runtime.json"),
|
|
336
|
+
JSON.stringify({
|
|
337
|
+
cwd: root,
|
|
338
|
+
repos: ["owner/one"],
|
|
339
|
+
intervalMs: 60000,
|
|
340
|
+
identity: { kind: "app", login: "agent[bot]", token: "configured" },
|
|
341
|
+
}),
|
|
342
|
+
);
|
|
343
|
+
const report = describeDoctor(root, {
|
|
344
|
+
readGitRepo: () => null,
|
|
345
|
+
probeGh: () => ({ ok: false, reason: "HTTP 401: Bad credentials" }),
|
|
346
|
+
});
|
|
347
|
+
const identity = report.checks.find((check) => check.id === "identity");
|
|
348
|
+
assert.equal(identity.status, "fail");
|
|
349
|
+
assert.match(identity.detail, /安装令牌一小时过期/u);
|
|
350
|
+
assert.equal(report.summary.fail > 0, true);
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// ---------------------------------------------------------------------------
|
|
355
|
+
// explain: why one key is (or is not) in front of an agent
|
|
356
|
+
// ---------------------------------------------------------------------------
|
|
357
|
+
|
|
358
|
+
test("explain says a role filter is what keeps a fact out of the session", () => {
|
|
359
|
+
withWorkspace((root) => {
|
|
360
|
+
writeFileSync(
|
|
361
|
+
join(root, ".work", "inbox-bridge", "runtime.json"),
|
|
362
|
+
JSON.stringify({
|
|
363
|
+
repos: ["owner/one"],
|
|
364
|
+
roles: ["author", "reviewer"],
|
|
365
|
+
delivery: "quiet",
|
|
366
|
+
wakeOn: [],
|
|
367
|
+
}),
|
|
368
|
+
);
|
|
369
|
+
writeFileSync(
|
|
370
|
+
join(root, ".work", "inbox-bridge", "state.json"),
|
|
371
|
+
JSON.stringify({ events: { "owner/one#pr:9:assignee:x": { status: "pending", at: AT } } }),
|
|
372
|
+
);
|
|
373
|
+
const info = explainKey(root, "owner/one#pr:9:assignee:x");
|
|
374
|
+
assert.equal(info.role, "assignee");
|
|
375
|
+
assert.equal(info.entry.status, "pending");
|
|
376
|
+
assert.match(info.verdict, /在队列里等投递/u);
|
|
377
|
+
assert.ok(info.notes.some((note) => /角色门槛挡住了它/u.test(note)));
|
|
378
|
+
assert.ok(info.notes.some((note) => /只注入模式/u.test(note)));
|
|
379
|
+
assert.match(formatExplanation(info), /key owner\/one#pr:9:assignee:x/u);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test("explain names the repository that is not subscribed, and the next resurface", () => {
|
|
384
|
+
withWorkspace((root) => {
|
|
385
|
+
writeFileSync(
|
|
386
|
+
join(root, ".work", "inbox-bridge", "runtime.json"),
|
|
387
|
+
JSON.stringify({
|
|
388
|
+
repos: ["owner/one"],
|
|
389
|
+
roles: [],
|
|
390
|
+
delivery: "wakeup",
|
|
391
|
+
wakeOn: ["reviewer"],
|
|
392
|
+
wakeAfterIdleMs: 900000,
|
|
393
|
+
wakesPerHour: 2,
|
|
394
|
+
maxConsecutiveWakes: 3,
|
|
395
|
+
}),
|
|
396
|
+
);
|
|
397
|
+
writeFileSync(
|
|
398
|
+
join(root, ".work", "inbox-bridge", "state.json"),
|
|
399
|
+
JSON.stringify({
|
|
400
|
+
events: {
|
|
401
|
+
"owner/two#run:1": { status: "delivered", at: AT, attempts: 1, kind: "ci" },
|
|
402
|
+
"owner/one#pr:5:reviewer:review-requested": {
|
|
403
|
+
status: "delivered",
|
|
404
|
+
at: AT,
|
|
405
|
+
attempts: 2,
|
|
406
|
+
kind: "pr",
|
|
407
|
+
},
|
|
408
|
+
},
|
|
409
|
+
}),
|
|
410
|
+
);
|
|
411
|
+
const unsubscribed = explainKey(root, "owner/two#run:1");
|
|
412
|
+
assert.ok(unsubscribed.notes.some((note) => /不在这台实例的订阅里/u.test(note)));
|
|
413
|
+
assert.match(unsubscribed.next, /最早重提时间/u);
|
|
414
|
+
|
|
415
|
+
const twice = explainKey(root, "owner/one#pr:5:reviewer:review-requested");
|
|
416
|
+
assert.match(twice.next, /收口成 done/u);
|
|
417
|
+
assert.ok(twice.notes.some((note) => /命中 wakeOn/u.test(note)));
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test("explain distinguishes never-reported from already-closed", () => {
|
|
422
|
+
withWorkspace((root) => {
|
|
423
|
+
writeFileSync(
|
|
424
|
+
join(root, ".work", "github-inbox", "state.json"),
|
|
425
|
+
JSON.stringify({
|
|
426
|
+
version: 2,
|
|
427
|
+
repos: { "owner/one": { seen: { "run:7": AT } } },
|
|
428
|
+
}),
|
|
429
|
+
);
|
|
430
|
+
assert.match(explainKey(root, "owner/one#run:7").verdict, /报过,但已经不在队列里/u);
|
|
431
|
+
assert.match(explainKey(root, "owner/one#run:8").verdict, /没有报出过它/u);
|
|
432
|
+
});
|
|
433
|
+
});
|