dsh-inbox-bridge 2.17.0 → 2.18.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 CHANGED
@@ -1,8 +1,18 @@
1
+ ## 2.18.0
2
+
3
+ - 归档不再让你去终端登录:把「消息清理」切到归档,插件自己弹出登录窗口;会话失效而选项仍在归档上时,下一次归档失败会再开一次(signInCooldownMs 默认 6 小时,防打扰)。
4
+ - 卡片里还没登录时会写「归档还没登录 GitHub」,旁边是「打开登录窗口」按钮。
5
+ - scripts/clear-inbox.mjs --check 只回答「登录了没」(没登录退出码 2);没有 cookie 库时不启动浏览器。
6
+ - 归档起的是独立进程,宿主的轮询不会被一个二十分钟的登录挡住。
7
+ ## 2.17.1
8
+
9
+ - 安全告警改成每个来源一条:一个依赖就可能带二十条开着的告警,逐条报告会把队列淹掉、把一次修复变成二十条通知。现在一条里写明条数、严重度分布和涉及的两三个包名,修完最后一条自动收口。
10
+ - `code-scanning` 读不到时不再复述 gh 那句误导性的 `admin:repo_hook` 提示,改为指出真正需要的 `security_events` 权限。
1
11
  ## 2.17.0
2
12
 
3
13
  - 新命令 `doctor`:逐项自检身份(App 安装令牌一小时过期,过期时这里直接 fail)、订阅的仓库是否可读、每个仓库上次轮询离现在多久、队列积压与过期投递、归档登录是否还在。有 fail 时退出码 1,适合放进脚本。
4
14
  - 新命令 `explain <key>`:回答「这件事走到哪一步了」——没被报出、被 `roles` 挡住、仓库不在订阅里、在等你这一轮、已投递还在重提窗口里,或者已经收口。
5
- - 事件来源多了两类:开着的 Dependabot 与 code scanning 告警(按告警编号做 key,修掉后下一次轮询自动收口);我作为作者或指派人的 PR 与基分支冲突或落后。仓库没开 Dependabot、或令牌没有 `security_events` 权限时只记一笔,不会跳过整次轮询。
15
+ - 事件来源多了两类:开着的 Dependabot 与 code scanning 告警(每个来源一条,带条数与严重度分布,修完最后一条后下一次轮询自动收口);我作为作者或指派人的 PR 与基分支冲突或落后。仓库没开 Dependabot、或令牌没有 `security_events` 权限时只记一笔,不会跳过整次轮询。
6
16
  - 干净的 PR 的 key 不变,新增的合并状态不会让已投递的事实重新提醒。
7
17
 
8
18
  ## 2.16.4
@@ -23,10 +33,10 @@
23
33
  ## 2.16.0
24
34
 
25
35
  - 回合进行中的轮询间隔默认值从 10 分钟改为 1 分钟:CI 跑完一两分钟内就能进上下文,赶在 agent 还没走远时返工。仍只在回合内轮询,空闲不发请求;需要更快可以改 intervalMs(下限 5 秒)。
26
- # Changelog
27
-
28
- Format: keep a short entry per released version. Dates are UTC.
29
-
36
+ # Changelog
37
+
38
+ Format: keep a short entry per released version. Dates are UTC.
39
+
30
40
  ## 2.15.3
31
41
 
32
42
  - 为插件市场准备:新增 screenshots.json(指向 docs/assets/panel.png)与 180px 方形图标 docs/assets/icon-180.png,便于目录与商店类市场展示卡片与截图。
@@ -189,91 +199,91 @@ Format: keep a short entry per released version. Dates are UTC.
189
199
  - CI 不再只看默认分支:我自己开的 PR 所在分支也会被读,分支上的失败同样会成为事件;别人分支上的失败仍然不打扰。
190
200
  - 为此 gh run list 改为一次抓全部分支(上限 40 条),再按「默认分支 + 我的 PR 分支」过滤。
191
201
 
192
- ## 2.4.2
193
-
194
- - 启动日志与通知里的轮询间隔改成可读写法:不足一分钟显示秒(poll every 20 秒),不再出现 poll 0 min。
195
-
196
- ## 2.4.1
197
-
198
- - 修复 2.3.0 引入的读取缺陷:多仓库状态文件被当成单仓库状态读回,于是每次轮询都从空的 已见 列表开始,lastRun 也每次重算。表现为旧的红运行反复被当成新事件、恢复通知无法触发。现在读回整个文件再按仓库取分片,并加了回归测试。
199
- - 测试清理在 Windows 上遇到仍被占用目录时会重试,不再偶发 EBUSY。
200
-
201
- ## 2.4.0
202
-
203
- - README 改成产品向叙述:讲它替你挡住什么、你会看到什么、默认有多安静;版本变更、配置全表、已知边界不再堆在首页。
204
- - 新增两份深入文档:[如何工作](docs/how-it-works.md)、[配置与命令](docs/configuration.md),`README.en.md` 同步改写。
205
- - 通知里的收口命令默认带上插件自身的绝对路径,新装用户照抄即可执行(以前是个裸命令)。
206
- - 命令行帮助与 `list` 脚注不再引用宿主项目的 npm 脚本写法。
207
-
208
- ## 2.3.1
209
-
210
- - 一次轮询失败会在 `plugin.log` 里留一行 `poll skipped: <reason>`。以前它和「收件箱是空的」长得一模一样。
211
- - 新增 `debug` 开关(默认关):打开后 `plugin.log` 记录每个边界事件(会话注册、回合开始/结束、用户消息、每次轮询的进出),用来判断是没触发还是触发后没结果。
212
-
213
- ## 2.3.0
214
-
215
- - `repos`:一个实例订阅一组仓库。队列共用,状态按仓库分片(`state.json` 的 `repos`),事件 key 带仓库前缀 `owner/name#…`——同一个 PR 号在不同仓库是两个事件。
216
- - `--repo` 可重复、`INBOX_REPO` 接受逗号或空格分隔的列表;`status` 逐个仓库显示上次轮询的身份、耗时与事件数。
217
- - 2.0/2.1 的旧单仓库状态文件按它上次轮询的仓库自动收编,不会把历史事件重发一遍。
218
- - 启动时写一行日志(注册的会话数、回合内轮询间隔、投递方式、仓库),装完能直接确认插件活着。
219
-
220
- ## 2.2.0
221
-
222
- - 轮询改成跟回合走:回合开始一次、进行中每 `intervalMs` 一次、结束一次;空闲时不轮询、不留下定时器。`intervalMs` 因此从「固定轮询间隔」变成「回合内间隔」,默认 45 秒 → 10 分钟。
223
- - `wakeup` 重做为可审计的四道门:`wakeOn` 角色白名单(默认空 = 永不唤醒)、`wakeAfterIdleMs`(默认 15 分钟)、`wakesPerHour`(默认 2)、每会话 `maxConsecutiveWakes`。每次唤醒写 `woke <session> because <role>:<key>`,被拒时写 `no wakeup: <why>`。
224
- - 删掉唤醒文案里那句不存在的空闲承诺:现在文案复述的是同一个判断所用的规则。
225
- - 新增 `status` 子命令:仓库、身份、角色、投递方式、队列计数、上次轮询(身份 / 耗时 / 事件数),只读本地文件。
226
- - `.work/inbox-bridge/runtime.json` 记录插件本轮生效的配置,`status` 因此能看到插件真实生效值而不是默认值。
227
- - 仓库状态里记下 `lastPoll`:谁读的、多久、几个事件。
228
- - 首次轮询只按分支当前状态报一次:新工作区的第一次 poll 不再把窗口里几天前的红运行逐个翻出来。
229
- - 删掉 Windows 通知弹窗与 `--no-toast`:通知只走 DSH 会话。
230
- - 环境变量统一为 `INBOX_REPO` / `INBOX_GH` / `INBOX_IDENTITY_*`。
231
- - 文档重写为按定位叙述(运输层通用、来源当前只有 GitHub),不再讲项目来历。
232
-
233
- ## 2.1.0
234
-
235
- - 新增 `identity`:poller 以某个身份读 GitHub(本机 `gh` 登录,或 App 安装令牌),并从身份推导每条事件的角色。
236
- - 新增 `roles`:本机只接受哪些角色(`author` / `reviewer` / `assignee` / `mention` / `ci`);空数组表示全部接受。
237
- - 事件按角色过滤:别人欠的评审、别人作者的 PR 失败不再变成我的通知;`REVIEW_REQUIRED` 单独不再成事件,只有**我被请求评审**才提醒。
238
- - 事件 key 带角色段(`pr:131:author:…`、`comment:6885266487:mention`、`issue:150:assignee:…`);`repo` 与 `role` 写进每条事件,投递侧不再从会话 cwd 猜。
239
- - 修复:只 ack 真正投出去的 key,之前没投出去的事件会被误标 `delivered`,因此永远不再重投。
240
- - 修复:`delivery: wakeup` 的通知文案不再承诺「长时间没人发言才开一轮」——当前没有空闲门槛,文案改为如实描述。
241
- - App 身份跳过 `/notifications`(App 没有用户收件箱,该接口返回 403),只读仓库状态。
242
- - 新增 `ROADMAP.md`;README 明确定位:运输层通用、来源层当前只有 GitHub。
243
-
244
- ## 2.0.4
245
-
246
- - 描述以「队列 + 回合边界投递」为主语,轮询只作为采集实现写进「工作原理」:2.0.0 之后的产品语义是事件收件箱,不是“轮询一个外部来源”。
247
-
248
- ## 2.0.3
249
-
250
- - 统一对外描述:插件只读 GitHub(CI、PR、issue),不再宣称“任意外部来源 / 邮件 / 本地命令”;标题、描述、README 与市场索引使用同一句话,版本与用例数同步。
251
-
252
- ## 2.0.2
253
-
254
- - PR 事件摘要只看“需要你处理的状态”(失败检查 + 评审决定):进行中/成功完成的检查不再进入事件 key,同一个 PR 在检查跑完前不会反复触发通知与唤醒。
255
-
256
- ## 2.0.1
257
-
258
- - 轮询直接抓取仓库的 open issues:GitHub notifications 只覆盖你订阅的线程,别人新开的 issue 以前会被静默漏掉(#156 / #152)。
259
-
260
- ## 2.0.0
261
-
262
- - Breaking: `wake` became `delivery` (`quiet` by default). A notice now only queues for the session's next turn; `wakeup` opts into opening a turn, bounded by `maxConsecutiveWakes` and reset by any human-authored message. The old `wake` key fails loudly instead of changing behaviour silently.
263
- - Notices only go to sessions whose workspace `origin` matches the watched repository, so an idle session in another repository no longer receives this repository's CI.
264
- - PR event keys no longer contain completion timestamps: an unchanged check set no longer mints a new key on every poll and re-reports the same PR.
265
- - The "no repository to watch" reminder only reaches sessions that cannot name a repository themselves.
266
-
267
- ## 1.5.1
268
-
269
- - Fix: wake messages now hand the whole message to `followup()` and `inject()`, so the session log keeps `role` and the conversation can be reopened.
270
-
271
- ## 1.5.0
272
-
273
- - Wake one idle session (configurable) with `followup()` instead of only injecting context.
274
- - Poll every 45 seconds by default instead of 120 seconds.
275
-
276
- ## 1.4.0
277
-
278
- - Standalone project: plugin, CLI and GitHub collector ship as one package.
279
- - Three-state bookkeeping (pending / delivered / done), resurfacing after six hours, and automatic closing of resolved failures.
202
+ ## 2.4.2
203
+
204
+ - 启动日志与通知里的轮询间隔改成可读写法:不足一分钟显示秒(poll every 20 秒),不再出现 poll 0 min。
205
+
206
+ ## 2.4.1
207
+
208
+ - 修复 2.3.0 引入的读取缺陷:多仓库状态文件被当成单仓库状态读回,于是每次轮询都从空的 已见 列表开始,lastRun 也每次重算。表现为旧的红运行反复被当成新事件、恢复通知无法触发。现在读回整个文件再按仓库取分片,并加了回归测试。
209
+ - 测试清理在 Windows 上遇到仍被占用目录时会重试,不再偶发 EBUSY。
210
+
211
+ ## 2.4.0
212
+
213
+ - README 改成产品向叙述:讲它替你挡住什么、你会看到什么、默认有多安静;版本变更、配置全表、已知边界不再堆在首页。
214
+ - 新增两份深入文档:[如何工作](docs/how-it-works.md)、[配置与命令](docs/configuration.md),`README.en.md` 同步改写。
215
+ - 通知里的收口命令默认带上插件自身的绝对路径,新装用户照抄即可执行(以前是个裸命令)。
216
+ - 命令行帮助与 `list` 脚注不再引用宿主项目的 npm 脚本写法。
217
+
218
+ ## 2.3.1
219
+
220
+ - 一次轮询失败会在 `plugin.log` 里留一行 `poll skipped: <reason>`。以前它和「收件箱是空的」长得一模一样。
221
+ - 新增 `debug` 开关(默认关):打开后 `plugin.log` 记录每个边界事件(会话注册、回合开始/结束、用户消息、每次轮询的进出),用来判断是没触发还是触发后没结果。
222
+
223
+ ## 2.3.0
224
+
225
+ - `repos`:一个实例订阅一组仓库。队列共用,状态按仓库分片(`state.json` 的 `repos`),事件 key 带仓库前缀 `owner/name#…`——同一个 PR 号在不同仓库是两个事件。
226
+ - `--repo` 可重复、`INBOX_REPO` 接受逗号或空格分隔的列表;`status` 逐个仓库显示上次轮询的身份、耗时与事件数。
227
+ - 2.0/2.1 的旧单仓库状态文件按它上次轮询的仓库自动收编,不会把历史事件重发一遍。
228
+ - 启动时写一行日志(注册的会话数、回合内轮询间隔、投递方式、仓库),装完能直接确认插件活着。
229
+
230
+ ## 2.2.0
231
+
232
+ - 轮询改成跟回合走:回合开始一次、进行中每 `intervalMs` 一次、结束一次;空闲时不轮询、不留下定时器。`intervalMs` 因此从「固定轮询间隔」变成「回合内间隔」,默认 45 秒 → 10 分钟。
233
+ - `wakeup` 重做为可审计的四道门:`wakeOn` 角色白名单(默认空 = 永不唤醒)、`wakeAfterIdleMs`(默认 15 分钟)、`wakesPerHour`(默认 2)、每会话 `maxConsecutiveWakes`。每次唤醒写 `woke <session> because <role>:<key>`,被拒时写 `no wakeup: <why>`。
234
+ - 删掉唤醒文案里那句不存在的空闲承诺:现在文案复述的是同一个判断所用的规则。
235
+ - 新增 `status` 子命令:仓库、身份、角色、投递方式、队列计数、上次轮询(身份 / 耗时 / 事件数),只读本地文件。
236
+ - `.work/inbox-bridge/runtime.json` 记录插件本轮生效的配置,`status` 因此能看到插件真实生效值而不是默认值。
237
+ - 仓库状态里记下 `lastPoll`:谁读的、多久、几个事件。
238
+ - 首次轮询只按分支当前状态报一次:新工作区的第一次 poll 不再把窗口里几天前的红运行逐个翻出来。
239
+ - 删掉 Windows 通知弹窗与 `--no-toast`:通知只走 DSH 会话。
240
+ - 环境变量统一为 `INBOX_REPO` / `INBOX_GH` / `INBOX_IDENTITY_*`。
241
+ - 文档重写为按定位叙述(运输层通用、来源当前只有 GitHub),不再讲项目来历。
242
+
243
+ ## 2.1.0
244
+
245
+ - 新增 `identity`:poller 以某个身份读 GitHub(本机 `gh` 登录,或 App 安装令牌),并从身份推导每条事件的角色。
246
+ - 新增 `roles`:本机只接受哪些角色(`author` / `reviewer` / `assignee` / `mention` / `ci`);空数组表示全部接受。
247
+ - 事件按角色过滤:别人欠的评审、别人作者的 PR 失败不再变成我的通知;`REVIEW_REQUIRED` 单独不再成事件,只有**我被请求评审**才提醒。
248
+ - 事件 key 带角色段(`pr:131:author:…`、`comment:6885266487:mention`、`issue:150:assignee:…`);`repo` 与 `role` 写进每条事件,投递侧不再从会话 cwd 猜。
249
+ - 修复:只 ack 真正投出去的 key,之前没投出去的事件会被误标 `delivered`,因此永远不再重投。
250
+ - 修复:`delivery: wakeup` 的通知文案不再承诺「长时间没人发言才开一轮」——当前没有空闲门槛,文案改为如实描述。
251
+ - App 身份跳过 `/notifications`(App 没有用户收件箱,该接口返回 403),只读仓库状态。
252
+ - 新增 `ROADMAP.md`;README 明确定位:运输层通用、来源层当前只有 GitHub。
253
+
254
+ ## 2.0.4
255
+
256
+ - 描述以「队列 + 回合边界投递」为主语,轮询只作为采集实现写进「工作原理」:2.0.0 之后的产品语义是事件收件箱,不是“轮询一个外部来源”。
257
+
258
+ ## 2.0.3
259
+
260
+ - 统一对外描述:插件只读 GitHub(CI、PR、issue),不再宣称“任意外部来源 / 邮件 / 本地命令”;标题、描述、README 与市场索引使用同一句话,版本与用例数同步。
261
+
262
+ ## 2.0.2
263
+
264
+ - PR 事件摘要只看“需要你处理的状态”(失败检查 + 评审决定):进行中/成功完成的检查不再进入事件 key,同一个 PR 在检查跑完前不会反复触发通知与唤醒。
265
+
266
+ ## 2.0.1
267
+
268
+ - 轮询直接抓取仓库的 open issues:GitHub notifications 只覆盖你订阅的线程,别人新开的 issue 以前会被静默漏掉(#156 / #152)。
269
+
270
+ ## 2.0.0
271
+
272
+ - Breaking: `wake` became `delivery` (`quiet` by default). A notice now only queues for the session's next turn; `wakeup` opts into opening a turn, bounded by `maxConsecutiveWakes` and reset by any human-authored message. The old `wake` key fails loudly instead of changing behaviour silently.
273
+ - Notices only go to sessions whose workspace `origin` matches the watched repository, so an idle session in another repository no longer receives this repository's CI.
274
+ - PR event keys no longer contain completion timestamps: an unchanged check set no longer mints a new key on every poll and re-reports the same PR.
275
+ - The "no repository to watch" reminder only reaches sessions that cannot name a repository themselves.
276
+
277
+ ## 1.5.1
278
+
279
+ - Fix: wake messages now hand the whole message to `followup()` and `inject()`, so the session log keeps `role` and the conversation can be reopened.
280
+
281
+ ## 1.5.0
282
+
283
+ - Wake one idle session (configurable) with `followup()` instead of only injecting context.
284
+ - Poll every 45 seconds by default instead of 120 seconds.
285
+
286
+ ## 1.4.0
287
+
288
+ - Standalone project: plugin, CLI and GitHub collector ship as one package.
289
+ - Three-state bookkeeping (pending / delivered / done), resurfacing after six hours, and automatic closing of resolved failures.
package/README.en.md CHANGED
@@ -91,7 +91,7 @@ To see what it can actually see: `node scripts/inbox-bridge.mjs doctor` walks th
91
91
  | `delivery` | `quiet` | `quiet` queues only; `wakeup` may start a turn while the session is idle |
92
92
  | `wakeOn` | empty | roles allowed to wake under `wakeup`; empty never wakes |
93
93
  | `clear` | `repo` | mark read after a poll: `repo` / `off`. Only the subscribed repositories, never the whole account |
94
- | `sweep` | off | archive the inbox into Done on turns that found something; needs a one-time browser sign-in |
94
+ | `sweep` | off | archive the inbox into Done on turns that found something; the plugin opens a sign-in window when one is missing |
95
95
 
96
96
  The panel's "message clearing" choice sets both: **off** (neither), **read** (clear the blue dot), **archive** (mark read and move to Done).
97
97
 
@@ -101,7 +101,7 @@ Full configuration, CLI and state files: [configuration](docs/configuration.md).
101
101
 
102
102
  - **Read-only.** It does not merge, comment, or change anything.
103
103
  - **No turn by default.** Only `delivery: wakeup` with a matching `wakeOn` role, enough idle time, and room in both budgets may start one; any gate that fails falls back to queueing.
104
- - **Done archiving needs one browser sign-in.** GitHub has no archive API; `scripts/clear-inbox.mjs` drives a local Chromium-based browser (Edge, Chrome or Chromium) and needs a single `--login`.
104
+ - **Done archiving needs one browser sign-in, but you do not type a command for it.** GitHub has no archive API; `scripts/clear-inbox.mjs` drives a local Chromium-based browser (Edge, Chrome or Chromium). Switching "message clearing" to archive opens the sign-in window by itself, and it opens again if the session expires.
105
105
  - **State is local.** It lives under `.work/` in the working directory and is not synced across machines.
106
106
 
107
107
  ## Further reading
package/README.md CHANGED
@@ -91,7 +91,7 @@ dsh plugin add dsh-inbox-bridge
91
91
  | `delivery` | `quiet` | `quiet` 只入队;`wakeup` 可在会话空闲时主动开启一轮 |
92
92
  | `wakeOn` | 空 | `wakeup` 下允许唤醒的角色白名单;为空则永不唤醒 |
93
93
  | `clear` | `repo` | 将订阅仓库里读过的通知标为已读:`repo` / `off`。只清订阅的仓库,不动整个账号 |
94
- | `sweep` | 关 | 有发现的回合把收件箱归档到 Done,需要先登录一次浏览器 |
94
+ | `sweep` | 关 | 有发现的回合把收件箱归档到 Done;缺登录时插件自己弹窗口让你登录一次 |
95
95
 
96
96
  面板里的「消息清理」一档同时管这两件事:**关闭**(都不做)、**已读**(清蓝点)、**归档**(标已读并存进 Done)。
97
97
 
@@ -101,7 +101,7 @@ dsh plugin add dsh-inbox-bridge
101
101
 
102
102
  - **只读。** 不合并、不评论、不修改仓库。
103
103
  - **默认不主动开启对话。** 只有显式设置 `delivery: wakeup` 且命中 `wakeOn`、会话足够空闲、两个预算都还有余额时才会;任何一道门不过,就退回只排队。
104
- - **Done 归档依赖一次浏览器登录。** GitHub 没有归档 API,`scripts/clear-inbox.mjs` 通过本机浏览器(Edge / Chrome / Chromium)完成,需要执行一次 `--login`。
104
+ - **Done 归档依赖一次浏览器登录,但不用你敲命令。** GitHub 没有归档 API,`scripts/clear-inbox.mjs` 通过本机浏览器(Edge / Chrome / Chromium)完成。把「消息清理」切到归档,插件会自己弹出登录窗口;会话失效时会再弹一次。
105
105
  - **状态在本机。** 存放在工作目录的 `.work/` 下,不跨机器同步。
106
106
 
107
107
  ## 更多
package/client.js CHANGED
@@ -128,6 +128,10 @@ window.__ModuleLoader__.load({
128
128
  readTip: "把通知标为已读,清掉圆点;不进 Done。",
129
129
  done: "归档",
130
130
  doneTip: "标为已读并移入 Done。归档需要一次浏览器登录。",
131
+ signInNeeded: "归档还没登录 GitHub,事件不会进 Done。",
132
+ signInWaiting: "已打开登录窗口,登录后自动生效。",
133
+ signInOpen: "打开登录窗口",
134
+ signInTip: "在插件自己的浏览器配置里登录一次;之后归档会自动运行,失效时会再打开这个窗口。",
131
135
  subscribe: "订阅仓库",
132
136
  subscribeTip: "此会话关注的 GitHub 仓库;事件只按这里的仓库投递。",
133
137
  typeRepo: "owner/repo 或链接",
@@ -180,6 +184,10 @@ window.__ModuleLoader__.load({
180
184
  readTip: "Clear the unread dot without moving the thread to Done.",
181
185
  done: "done",
182
186
  doneTip: "Mark read and move the thread to Done. Archiving needs a one-time browser sign-in.",
187
+ signInNeeded: "Archiving is not signed in yet, so nothing reaches Done.",
188
+ signInWaiting: "The sign-in window is open; archiving resumes when you finish.",
189
+ signInOpen: "open sign-in",
190
+ signInTip: "Sign in once in this plugin's own browser profile; afterwards archiving runs on its own and reopens this window if the session expires.",
183
191
  subscribe: "repositories",
184
192
  subscribeTip: "The repositories this session follows; events are delivered only for them.",
185
193
  typeRepo: "owner/repo or link",
@@ -417,6 +425,23 @@ window.__ModuleLoader__.load({
417
425
  warnValue: {
418
426
  color: "var(--dsw-alias-label-warning, var(--dsw-alias-label-secondary))",
419
427
  },
428
+ signInRow: {
429
+ display: "flex",
430
+ alignItems: "center",
431
+ justifyContent: "space-between",
432
+ gap: "8px",
433
+ marginTop: "2px",
434
+ paddingLeft: "2px",
435
+ },
436
+ signInText: {
437
+ color: "var(--dsw-alias-label-warning, var(--dsw-alias-label-secondary))",
438
+ fontSize: "11px",
439
+ lineHeight: "18px",
440
+ minWidth: 0,
441
+ overflow: "hidden",
442
+ textOverflow: "ellipsis",
443
+ whiteSpace: "nowrap",
444
+ },
420
445
  metaValue: {
421
446
  color: "var(--dsw-alias-label-secondary)",
422
447
  textAlign: "right",
@@ -768,6 +793,33 @@ window.__ModuleLoader__.load({
768
793
  "clean",
769
794
  ),
770
795
  ),
796
+ // Archiving is a page action in GitHub, so it needs a browser session in
797
+ // the plugin's own profile. Say that here, and open the window from here —
798
+ // the operator should not have to run a command to make the mode work.
799
+ cleanLevel === "done" && status.signIn?.signedIn !== true
800
+ ? h(
801
+ "div",
802
+ { style: styles.signInRow },
803
+ h(
804
+ "span",
805
+ { style: styles.signInText },
806
+ status.signIn?.open ? pick.signInWaiting : pick.signInNeeded,
807
+ ),
808
+ status.signIn?.open
809
+ ? null
810
+ : h(
811
+ "button",
812
+ {
813
+ type: "button",
814
+ disabled: busy,
815
+ title: pick.signInTip,
816
+ onClick: () => void send("signin", "1"),
817
+ style: styles.seg,
818
+ },
819
+ pick.signInOpen,
820
+ ),
821
+ )
822
+ : null,
771
823
  h(
772
824
  "div",
773
825
  { style: styles.controlRow },
@@ -34,6 +34,16 @@ DSH 的插件配置里,一个 `dsh-inbox-bridge` 条目即可;等价写法
34
34
  { "delivery": "wakeup", "wakeOn": ["reviewer"], "repos": ["owner/one", "owner/two"] }
35
35
  ```
36
36
 
37
+ ### 归档需要一次登录
38
+
39
+ GitHub 的 Done 只有网页端点,所以归档要用插件自己的浏览器配置(`.work/browser-profile`)登录一次。这件事不用你去终端敲命令:
40
+
41
+ - 在卡片上把「消息清理」切到 **归档**,插件立刻弹出一个登录窗口;登录完它就自己归档。
42
+ - 之后会话失效,而选项还停在归档上——下一次归档失败时,插件自己再弹一次窗口(两次之间至少隔 `signInCooldownMs`)。
43
+ - 还没登录时卡片里会写着一行「归档还没登录 GitHub」,旁边有「打开登录窗口」按钮。
44
+
45
+ 窗口是独立进程,宿主的轮询不会被它挡住。命令行里 `scripts/clear-inbox.mjs --check` 只回答「登录了没」(没登录时退出码 2),`--login` 打开窗口等你登录,`--dry-run` 只报数量。
46
+
37
47
  ## 全部配置项
38
48
 
39
49
  | 键 | 默认 | 作用 |
@@ -56,7 +66,8 @@ DSH 的插件配置里,一个 `dsh-inbox-bridge` 条目即可;等价写法
56
66
  | `identity` | `{ kind: "user" }` | 用哪个身份读 GitHub,见下 |
57
67
  | `roles` | `[]` | 只接收这些角色的事件;空 = 全收 |
58
68
  | `clear` | `"repo"` | 把这一轮读过的通知线程标为已读:`repo` 只清订阅的仓库,`off` 不碰收件箱。整个账号不在范围内——清别人的仓库属于人的决定,不是后台轮询的决定。旧配置里的 `"all"` 按 `"repo"` 载入。GitHub 没有「完成」API,所以清的是未读角标,历史仍在收件箱里 |
59
- | `sweep` | `null` | 抓到东西后把收件箱归档进 Done:`{ args: ["scripts/clear-inbox.mjs"], when: "events" }`。`when: "events"` 只在有发现的回合跑,`"always"` 每轮都跑。需要先 `scripts/clear-inbox.mjs --login` 登录一次 |
69
+ | `sweep` | `null` | 抓到东西后把收件箱归档进 Done:`{ args: ["scripts/clear-inbox.mjs"], when: "events" }`。`when: "events"` 只在有发现的回合跑,`"always"` 每轮都跑。归档要有插件的浏览器配置里的一次登录;没有就让面板替你打开窗口,见下 |
70
+ | `signInCooldownMs` | `21600000`(6 小时) | 归档缺登录时,两次「替你打开登录窗口」之间至少隔多久。长到不打扰,短到会话失效后的下一个事件还能恢复 |
60
71
  | `debug` | `false` | 把每个边界事件写进 `plugin.log`,用来排查「没轮询」还是「轮询了没结果」 |
61
72
  | `poll` | 插件自带 CLI 的 `poll` | 换掉抓取命令:`{ command, args }`,只要能输出约定的 JSON,来源可以不是 GitHub |
62
73
  | `ack` | 插件自带 CLI 的 `ack` | 同上,换掉收口命令 |
@@ -94,7 +105,7 @@ node scripts/inbox-bridge.mjs poll # 立刻抓一次
94
105
  node scripts/inbox-bridge.mjs ack --done -- <key> # 划掉一条,并停止提醒
95
106
  node scripts/inbox-bridge.mjs ack --all-delivered --done # 把所有 delivered 一次划掉
96
107
  node scripts/inbox-bridge.mjs doctor # 逐项自检:身份、仓库可读性、上次轮询、队列、归档登录
97
- node scripts/inbox-bridge.mjs explain <key> # 某件事走到哪一步了,为什么没到你眼前 # 把所有 delivered 一次划掉
108
+ node scripts/inbox-bridge.mjs explain <key> # 某件事走到哪一步了,为什么没到你眼前
98
109
  ```
99
110
 
100
111
  `ack` 不带 `--done` 只把它们标成 delivered,意思是「给过了但还没处理」——6 小时后会再提。经 `npm run` 转发时,`--done` 必须写在 `--` 之后,否则被 npm 吞掉。
@@ -52,6 +52,7 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
52
52
  - 它不写回任何状态,也不替你 ack;读的就是 `scripts/inbox-bridge.mjs status` 那份事实。
53
53
  - 客户端代码是在页面里执行的:更新插件后要**重新打开一次应用**(桌面版没有刷新键),胶囊才会重新装上;在那之前它会先消失(不是坏了,是没有执行者)。
54
54
  - 卡片里的三组开关(提醒方式、消息清理、订阅)也走同源路由:`GET /inbox-bridge/prefs?token=…&set=…&value=…`。改动写进插件自己的覆盖层 `<cwd>/.work/inbox-bridge/prefs.json`,然后重新读一遍状态——显示的就是下一次轮询真要执行的东西,不做乐观更新。token 每次进程启动重新生成,随状态一起下发,防止别的本地页面替你改设置。
55
+ - 「消息清理」选到归档时,插件会把缺的那次登录替你补上:它自己起一个可见的浏览器窗口等你在插件的浏览器配置里登录,登录完归档接着跑。会话失效而选项还停在归档上时,下一次归档失败会再开一次窗口(至少间隔 `signInCooldownMs`);还没登录时卡片里会写「归档还没登录 GitHub」,旁边是「打开登录窗口」。
55
56
  - 页面第一次挂载时会往 `GET /inbox-bridge/client-log?m=…` 报一行容器尺寸,写进 `plugin.log`(`client: …`)。宿主的资源只应答 GET/HEAD,POST 会变成 405,所以诊断改走查询串。它只在排查「为什么浮层位置不对」时有用,平常不用管。
56
57
 
57
58
  ## 「跟我有关」怎么判断
@@ -66,7 +67,7 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
66
67
  | 评论 | 不是我自己发的,且 @我 |
67
68
  | CI | 默认分支,以及我自己 PR 那条分支;红的才出声,恢复时给一条「已恢复」 |
68
69
  | 基础设施失败 | 只提醒一次,因为再改代码也修不好它 |
69
- | 安全告警 | 开着的 Dependabot 与 code scanning 告警;按告警编号做 key,修掉后下一次轮询就收口 |
70
+ | 安全告警 | 开着的 Dependabot 与 code scanning 告警;每个来源合成一条(条数与严重度分布),修完最后一条后下一次轮询就收口 |
70
71
  | PR 变脏 | 我是作者或指派人,且 PR 与基分支冲突或落后;评审人不算,合并是作者的事 |
71
72
 
72
73
  同一条事实不会因为检查状态变来变去就变成好几条通知:key 只由「需要你处理的状态」构成,`QUEUED → IN_PROGRESS → SUCCESS` 全程同一个 key。
package/docs/index.json CHANGED
@@ -50,12 +50,12 @@
50
50
  },
51
51
  "versions": [
52
52
  {
53
- "version": "2.17.0",
54
- "publishTimestamp": 1794912854,
53
+ "version": "2.18.0",
54
+ "publishTimestamp": 1794914970,
55
55
  "source": {
56
56
  "type": "git",
57
57
  "url": "https://github.com/c3115644151/dsh-inbox-bridge",
58
- "commit": "44dc921ec4ad7afbcda547c6907ca6231ba7e351"
58
+ "commit": "bc5558499c2936c2c92cf8d452804e53189be719"
59
59
  },
60
60
  "engines": {
61
61
  "dsh": ">=0.1.0"
package/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
  * run goes idle. Does not own: fetching the source (the configured poller does)
18
18
  * or the meaning of "handled" (the ack command decides).
19
19
  */
20
- import { execFile, execFileSync } from "node:child_process";
20
+ import { execFile, execFileSync, spawn } from "node:child_process";
21
21
  import { randomUUID } from "node:crypto";
22
22
  import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
23
23
  import { dirname, join } from "node:path";
@@ -208,6 +208,12 @@ const DEFAULTS = Object.freeze({
208
208
  * `when: "events"` (default) only runs it on a turn that found something.
209
209
  */
210
210
  sweep: null,
211
+ /**
212
+ * How long to wait before the sign-in window may open again after it was left
213
+ * unsigned. Six hours: long enough not to interrupt, short enough that
214
+ * archiving comes back on the next event after a session expires.
215
+ */
216
+ signInCooldownMs: 6 * 60 * 60 * 1000,
211
217
  /**
212
218
  * Which GitHub identity the poller reads as. `kind: "user"` uses the ambient
213
219
  * `gh` login; `kind: "app"` needs a token (`token` or `tokenEnv`) and has no
@@ -369,6 +375,11 @@ export function apply(ctx, config) {
369
375
  // and shows which choices came from it rather than from the profile.
370
376
  token: uiToken,
371
377
  overlay: Object.keys(prefs),
378
+ signIn: {
379
+ signedIn: signIn.signedIn,
380
+ open: signIn.open,
381
+ attemptedAt: signIn.attemptedAt ? new Date(signIn.attemptedAt).toISOString() : null,
382
+ },
372
383
  sweepOn: Boolean(options.sweep),
373
384
  sessionId,
374
385
  };
@@ -436,6 +447,70 @@ export function apply(ctx, config) {
436
447
  // Archiving the notification inbox ("Done") has no API: it is a page action.
437
448
  // A configured sweep command does it through a browser, and this is where the
438
449
  // plugin calls it. `when: "events"` keeps a quiet turn at zero extra cost.
450
+ // Archiving needs a browser session, and a browser session expires. The
451
+ // operator should never have to run a command in a terminal to fix that:
452
+ // choosing the archive mode — or the archive finding no sign-in on its own —
453
+ // opens the window that asks for it.
454
+ const signIn = { signedIn: null, open: false, attemptedAt: 0 };
455
+
456
+ const sweepScript = () => {
457
+ const args = options.sweep?.args ?? [];
458
+ const script = args.find((arg) => String(arg).endsWith(".mjs"));
459
+ return typeof script === "string" ? script : null;
460
+ };
461
+
462
+ const minutesSince = (at) => Math.max(1, Math.round((Date.now() - at) / 60_000));
463
+
464
+ const openSignIn = (reason) => {
465
+ const script = sweepScript();
466
+ if (!script) return false;
467
+ if (signIn.open) {
468
+ log("sign-in window is already open");
469
+ return false;
470
+ }
471
+ if (signIn.attemptedAt && Date.now() - signIn.attemptedAt < options.signInCooldownMs) {
472
+ log(
473
+ `sign-in window not reopened: one was opened ${minutesSince(signIn.attemptedAt)} minutes ago`,
474
+ );
475
+ return false;
476
+ }
477
+ signIn.attemptedAt = Date.now();
478
+ signIn.open = true;
479
+ signIn.signedIn = false;
480
+ try {
481
+ const child = spawn(process.execPath, [script, "--login", "--json"], {
482
+ cwd: options.cwd,
483
+ env: { ...process.env, ELECTRON_RUN_AS_NODE: "1" },
484
+ // Detached so a twenty-minute sign-in never holds a poll open; visible
485
+ // because there has to be a window to sign in.
486
+ detached: true,
487
+ windowsHide: false,
488
+ stdio: "ignore",
489
+ });
490
+ child.once("exit", () => {
491
+ signIn.open = false;
492
+ });
493
+ child.unref?.();
494
+ } catch (error) {
495
+ signIn.open = false;
496
+ log(`could not open the sign-in window: ${describe(error)}`);
497
+ return false;
498
+ }
499
+ log(`opened the sign-in window (${reason}); archiving resumes once you sign in`);
500
+ return true;
501
+ };
502
+
503
+ const checkSignIn = async () => {
504
+ const script = sweepScript();
505
+ if (!script) return;
506
+ try {
507
+ await runCommand({ command: "node", args: [script, "--check", "--json"] }, options);
508
+ signIn.signedIn = true;
509
+ } catch (error) {
510
+ if (error?.exitCode === 2) signIn.signedIn = false;
511
+ }
512
+ };
513
+
439
514
  const sweepInbox = async (freshCount) => {
440
515
  if (!options.sweep) return;
441
516
  if (options.sweep.when === "events" && freshCount === 0) return;
@@ -443,13 +518,15 @@ export function apply(ctx, config) {
443
518
  try {
444
519
  const stdout = await runCommand(options.sweep, options);
445
520
  const line = String(stdout ?? "").trim().split(/\r?\n/u).pop() ?? "";
521
+ signIn.signedIn = true;
446
522
  log(`swept the notification inbox: ${line || "done"} (${Date.now() - began}ms)`);
447
523
  } catch (error) {
448
524
  if (error?.exitCode === 2) {
449
- const script = (options.sweep.args ?? []).find((arg) => String(arg).endsWith(".mjs"));
450
- log(
451
- `sweep needs a one-time sign-in: node "${script ?? "scripts/clear-inbox.mjs"}" --login`,
452
- );
525
+ // The command says "sign-in required"; raise the window rather than
526
+ // asking the operator to copy a command out of the log.
527
+ signIn.signedIn = false;
528
+ log("the archive needs a browser sign-in");
529
+ openSignIn("the archive found no sign-in");
453
530
  } else {
454
531
  log(`sweep failed: ${describe(error)}`);
455
532
  }
@@ -616,6 +693,9 @@ export function apply(ctx, config) {
616
693
  `wakeOn ${options.wakeOn.join(",")} is idle: delivery is ${options.delivery}, so those roles only queue`,
617
694
  );
618
695
  }
696
+ // Archiving only works with a browser session; find out once at start whether
697
+ // there is one, so the panel can say so before the first event arrives.
698
+ if (options.sweep) void checkSignIn();
619
699
 
620
700
  // A turn is the only thing that makes the inbox worth reading: poll when one
621
701
  // starts, re-poll while a long one runs, poll once more when it ends. An idle
@@ -776,10 +856,20 @@ export function apply(ctx, config) {
776
856
  sessionId,
777
857
  sessionRepo,
778
858
  });
859
+ if (action === "signin") {
860
+ // Not a setting: open the window that archiving needs.
861
+ const opened = openSignIn("you asked for it in the panel");
862
+ return reply(200, { ok: true, opened, status: uiPayload(sessionId) });
863
+ }
779
864
  if (next === null) {
780
865
  return reply(400, { ok: false, error: `unknown setting: ${action || "-"}` });
781
866
  }
782
867
  applyPrefs(next);
868
+ // Choosing the archive mode is also the request for a sign-in when
869
+ // there is none: the mode does nothing without one.
870
+ const wantsArchive =
871
+ (action === "clean" && value === "done") || (action === "archive" && value === "on");
872
+ if (wantsArchive && signIn.signedIn !== true) openSignIn("archive was turned on");
783
873
  } catch (error) {
784
874
  return reply(400, { ok: false, error: describe(error) });
785
875
  }
@@ -1065,9 +1155,16 @@ export function mergeConfig(config) {
1065
1155
  }
1066
1156
  sweepSpec = { command: sweep.command ?? "node", args: sweep.args ?? [], when };
1067
1157
  }
1158
+ const signInCooldownMs = given.signInCooldownMs ?? DEFAULTS.signInCooldownMs;
1159
+ if (!Number.isInteger(signInCooldownMs) || signInCooldownMs < 0) {
1160
+ throw new Error(
1161
+ `inbox-bridge: \`signInCooldownMs\` must be a non-negative integer, got ${JSON.stringify(signInCooldownMs)}`,
1162
+ );
1163
+ }
1068
1164
  return {
1069
1165
  ...DEFAULTS,
1070
1166
  ...given,
1167
+ signInCooldownMs,
1071
1168
  repo,
1072
1169
  repos: watched,
1073
1170
  delivery,
@@ -1288,6 +1385,7 @@ export function buildUiPayload({
1288
1385
  recent = new Map(),
1289
1386
  now = Date.now(),
1290
1387
  session = null,
1388
+ signIn = null,
1291
1389
  }) {
1292
1390
  const configured = options.repos?.length > 0 ? options.repos : options.repo ? [options.repo] : [];
1293
1391
  // A session sees exactly what a poll would deliver to it: the repositories it
@@ -1344,6 +1442,7 @@ export function buildUiPayload({
1344
1442
  delivery: options.delivery ?? DEFAULTS.delivery,
1345
1443
  clear: options.clear ?? DEFAULTS.clear,
1346
1444
  sweep: options.sweep?.when ?? null,
1445
+ signIn: signIn ?? { signedIn: null, open: false, attemptedAt: null },
1347
1446
  intervalMs: options.intervalMs ?? DEFAULTS.intervalMs,
1348
1447
  queue: counts,
1349
1448
  events: events.slice(0, 20),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-inbox-bridge",
3
- "version": "2.17.0",
3
+ "version": "2.18.0",
4
4
  "displayName": "GitHub inbox",
5
5
  "description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
6
6
  "type": "module",
@@ -65,6 +65,7 @@ function parseArgs(argv = []) {
65
65
  if (argument === "--json") options.json = true;
66
66
  else if (argument === "--login") options.login = true;
67
67
  else if (argument === "--dry-run") options.dryRun = true;
68
+ else if (argument === "--check") options.check = true;
68
69
  else if (argument === "--keep-open") options.keepOpen = true;
69
70
  else if (argument === "--port") options.expectPort = true;
70
71
  else if (options.expectPort) {
@@ -172,6 +173,7 @@ async function main(argv) {
172
173
  "",
173
174
  " --json machine-readable summary",
174
175
  " --dry-run report how many threads would be archived",
176
+ " --check only say whether this profile is signed in (exit 2 if not)",
175
177
  " --login open a visible window so you can sign in once",
176
178
  " --keep-open leave the browser running after the sweep",
177
179
  " --port N DevTools port (default 9333)",
@@ -182,6 +184,13 @@ async function main(argv) {
182
184
 
183
185
  const root = process.cwd();
184
186
  const profileDir = resolve(root, PROFILE_REL);
187
+ // A profile with no cookie database has never been signed in. Answering that
188
+ // here keeps `--check` from launching a browser just to learn it is useless.
189
+ if (options.check && !existsSync(join(profileDir, "Default", "Cookies"))) {
190
+ if (options.json) console.log(JSON.stringify({ ok: false, reason: "sign-in-required" }));
191
+ else console.log("not signed in: archiving cannot run yet");
192
+ return 2;
193
+ }
185
194
  mkdirSync(profileDir, { recursive: true });
186
195
  const browser = findBrowser();
187
196
  const base = `http://127.0.0.1:${options.port}`;
@@ -285,6 +294,17 @@ async function main(argv) {
285
294
  return 0;
286
295
  }
287
296
 
297
+ // `--check` answers one question and touches nothing: is this profile
298
+ // signed in? The panel and `doctor` need that without archiving anything.
299
+ if (options.check) {
300
+ const rows = await read(
301
+ `document.querySelectorAll('input[type=checkbox][name="notification_ids[]"]').length`,
302
+ );
303
+ if (options.json) console.log(JSON.stringify({ ok: true, signedIn: true, rows }));
304
+ else console.log("signed in: archiving can run");
305
+ return 0;
306
+ }
307
+
288
308
  const result = await read(SWEEP);
289
309
  const summary = { ok: true, ...result };
290
310
  if (options.json) console.log(JSON.stringify(summary));
@@ -555,56 +555,81 @@ export function extractIssueEvents(issues = [], state = {}, { me = null } = {})
555
555
  return events;
556
556
  }
557
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
-
558
+ const SEVERITY_ORDER = ["critical", "high", "medium", "low"];
559
+
560
+ function severityRank(word) {
561
+ const index = SEVERITY_ORDER.indexOf(word);
562
+ return index < 0 ? SEVERITY_ORDER.length : index;
563
+ }
564
+
565
+ /**
566
+ * Open advisories for the watched repository, one line per source.
567
+ *
568
+ * A real repository can carry dozens of open alerts at once (a single
569
+ * dependency can account for twenty), so listing them one by one buries the
570
+ * queue and turns one fix into twenty notices. What a maintainer needs to know
571
+ * is that the repository has open advisories, how bad the worst of them are,
572
+ * and what they are about — so each source collapses into one entry with a
573
+ * stable key, and it closes by itself once no open alert of that source is
574
+ * left.
575
+ */
576
+ export function extractSecurityEvents(alerts = []) {
577
+ const groups = new Map();
578
+ for (const entry of Array.isArray(alerts) ? alerts : []) {
579
+ const alert = entry?.alert;
580
+ if (!alert) continue;
581
+ const source = entry?.source === "code-scanning" ? "code-scanning" : "dependabot";
582
+ const group = groups.get(source) ?? {
583
+ source,
584
+ count: 0,
585
+ severity: new Map(),
586
+ names: [],
587
+ at: null,
588
+ url: `https://github.com/${activeRepo}/security/${source === "code-scanning" ? "code-scanning" : "dependabot"}`,
589
+ };
590
+ group.count += 1;
591
+ const severity =
592
+ source === "dependabot"
593
+ ? singleLine(alert?.security_advisory?.severity ?? "unknown").toLowerCase()
594
+ : singleLine(
595
+ alert?.rule?.security_severity_level ?? alert?.rule?.severity ?? "",
596
+ ).toLowerCase();
597
+ if (severity) group.severity.set(severity, (group.severity.get(severity) ?? 0) + 1);
598
+ const name =
599
+ source === "dependabot"
600
+ ? singleLine(alert?.dependency?.package?.name ?? "")
601
+ : singleLine(alert?.most_recent_instance?.location?.path ?? "");
602
+ if (name && !group.names.includes(name)) group.names.push(name);
603
+ const at = alert?.updated_at ?? alert?.created_at ?? null;
604
+ if (at && (!group.at || String(at).localeCompare(String(group.at)) > 0)) group.at = at;
605
+ groups.set(source, group);
606
+ }
607
+
608
+ const events = [];
609
+ for (const group of groups.values()) {
610
+ const severities = [...group.severity.entries()]
611
+ .sort((left, right) => severityRank(left[0]) - severityRank(right[0]))
612
+ .map(([word, count]) => `${count} ${word}`);
613
+ const shown = group.names.slice(0, 3).join(", ");
614
+ const names = group.names.length > 3 ? `${shown} …` : shown;
615
+ const count = `${group.count} open ${group.count === 1 ? "advisory" : "advisories"}`;
616
+ const spread = severities.length > 0 ? ` (${severities.join(", ")})` : "";
617
+ const what = names ? `: ${names}` : "";
618
+ events.push({
619
+ key: group.source,
620
+ kind: "security",
621
+ role: "any",
622
+ repo: activeRepo,
623
+ label: group.source === "code-scanning" ? "Code scanning" : "Dependabot",
624
+ ref: "",
625
+ title: `${count}${spread}${what}`,
626
+ url: group.url,
627
+ at: group.at,
628
+ });
629
+ }
630
+ return events;
631
+ }
632
+
608
633
  export function extractEvents(
609
634
  { runs = [], prs = [], notifications = [], comments = [], issues = [], security = [] } = {},
610
635
  state = {},
@@ -803,7 +828,7 @@ export function formatEvent(event) {
803
828
  case "issue":
804
829
  return compact([`[Issue${role}] ${event.ref ?? ""}:`, title, url]);
805
830
  case "security":
806
- return compact([`[${event.label ?? "Security"}] ${event.ref ?? ""}:`, title, url]);
831
+ return compact([`[${event.label ?? "Security"}]${event.ref ? ` ${event.ref}` : ""}`, title, url]);
807
832
  default:
808
833
  return compact([`[${event.label ?? event.kind ?? "event"}${role}]`, title, url]);
809
834
  }
@@ -1051,7 +1076,19 @@ export function fetchSecurityAlerts(cwd) {
1051
1076
  for (const { source, path } of wanted) {
1052
1077
  const result = ghJson(["api", `repos/${activeRepo}/${path}?state=open&per_page=20`], { cwd });
1053
1078
  if (!result.ok) {
1054
- notes.push(`${source} unavailable (${result.reason})`);
1079
+ const reason = String(result.reason ?? "");
1080
+ // gh reports a 404 "no analysis found" as a scope problem and suggests
1081
+ // admin:repo_hook, which cannot read code scanning. Say what actually
1082
+ // helps instead of repeating a hint that leads nowhere.
1083
+ const noAnalysis = reason.includes("no analysis found");
1084
+ const needsScope = !noAnalysis && reason.includes("admin:repo_hook");
1085
+ notes.push(
1086
+ noAnalysis
1087
+ ? `${source} is not set up in this repository (no analysis found)`
1088
+ : needsScope
1089
+ ? `${source} needs the security_events scope (gh auth refresh -h github.com -s security_events)`
1090
+ : `${source} unavailable (${reason})`,
1091
+ );
1055
1092
  continue;
1056
1093
  }
1057
1094
  for (const alert of Array.isArray(result.value) ? result.value : []) {
@@ -942,39 +942,54 @@ test("a clean pull request keeps the digest it had before", () => {
942
942
  assert.equal(prStatusDigest(clean), prStatusDigest(pullRequest()));
943
943
  });
944
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
-
945
+ test("open advisories collapse into one line per source", () => {
946
+ const alerts = [
947
+ {
948
+ source: "dependabot",
949
+ alert: {
950
+ number: 3,
951
+ html_url: "u3",
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: "dependabot",
959
+ alert: {
960
+ number: 4,
961
+ html_url: "u4",
962
+ security_advisory: { severity: "low", summary: "TLS client crash in bar" },
963
+ dependency: { package: { name: "bar" } },
964
+ updated_at: "2026-11-16T10:00:00Z",
965
+ },
966
+ },
967
+ {
968
+ source: "code-scanning",
969
+ alert: {
970
+ number: 7,
971
+ html_url: "u7",
972
+ rule: { description: "Unvalidated input reaches the shell", security_severity_level: "medium" },
973
+ most_recent_instance: { location: { path: "scripts/run.mjs" } },
974
+ },
975
+ },
976
+ ];
977
+ const events = extractSecurityEvents(alerts);
978
+ assert.deepEqual(
979
+ events.map((event) => event.key),
980
+ ["dependabot", "code-scanning"],
981
+ );
982
+ assert.equal(events[0].kind, "security");
983
+ assert.equal(events[0].role, "any");
984
+ assert.equal(events[0].at, "2026-11-16T10:00:00Z");
985
+ const dependabot = formatEvent(events[0]);
986
+ assert.match(dependabot, /^\[Dependabot\] 2 open advisories \(1 high, 1 low\): foo, bar https:\/\//u);
987
+ assert.match(dependabot, /security\/dependabot$/u);
988
+ const scanning = formatEvent(events[1]);
989
+ assert.match(scanning, /^\[Code scanning\] 1 open advisory \(1 medium\): scripts\/run\.mjs /u);
990
+ assert.ok(!scanning.includes("#7"), "an aggregated line carries no alert number");
991
+ });
992
+
978
993
  test("a repository without Dependabot still polls the rest", () => {
979
994
  const result = pollOnce({
980
995
  state: normalizeState({}),