dsh-inbox-bridge 2.17.0 → 2.17.1

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,12 @@
1
+ ## 2.17.1
2
+
3
+ - 安全告警改成每个来源一条:一个依赖就可能带二十条开着的告警,逐条报告会把队列淹掉、把一次修复变成二十条通知。现在一条里写明条数、严重度分布和涉及的两三个包名,修完最后一条自动收口。
4
+ - `code-scanning` 读不到时不再复述 gh 那句误导性的 `admin:repo_hook` 提示,改为指出真正需要的 `security_events` 权限。
1
5
  ## 2.17.0
2
6
 
3
7
  - 新命令 `doctor`:逐项自检身份(App 安装令牌一小时过期,过期时这里直接 fail)、订阅的仓库是否可读、每个仓库上次轮询离现在多久、队列积压与过期投递、归档登录是否还在。有 fail 时退出码 1,适合放进脚本。
4
8
  - 新命令 `explain <key>`:回答「这件事走到哪一步了」——没被报出、被 `roles` 挡住、仓库不在订阅里、在等你这一轮、已投递还在重提窗口里,或者已经收口。
5
- - 事件来源多了两类:开着的 Dependabot 与 code scanning 告警(按告警编号做 key,修掉后下一次轮询自动收口);我作为作者或指派人的 PR 与基分支冲突或落后。仓库没开 Dependabot、或令牌没有 `security_events` 权限时只记一笔,不会跳过整次轮询。
9
+ - 事件来源多了两类:开着的 Dependabot 与 code scanning 告警(每个来源一条,带条数与严重度分布,修完最后一条后下一次轮询自动收口);我作为作者或指派人的 PR 与基分支冲突或落后。仓库没开 Dependabot、或令牌没有 `security_events` 权限时只记一笔,不会跳过整次轮询。
6
10
  - 干净的 PR 的 key 不变,新增的合并状态不会让已投递的事实重新提醒。
7
11
 
8
12
  ## 2.16.4
@@ -23,10 +27,10 @@
23
27
  ## 2.16.0
24
28
 
25
29
  - 回合进行中的轮询间隔默认值从 10 分钟改为 1 分钟:CI 跑完一两分钟内就能进上下文,赶在 agent 还没走远时返工。仍只在回合内轮询,空闲不发请求;需要更快可以改 intervalMs(下限 5 秒)。
26
- # Changelog
27
-
28
- Format: keep a short entry per released version. Dates are UTC.
29
-
30
+ # Changelog
31
+
32
+ Format: keep a short entry per released version. Dates are UTC.
33
+
30
34
  ## 2.15.3
31
35
 
32
36
  - 为插件市场准备:新增 screenshots.json(指向 docs/assets/panel.png)与 180px 方形图标 docs/assets/icon-180.png,便于目录与商店类市场展示卡片与截图。
@@ -189,91 +193,91 @@ Format: keep a short entry per released version. Dates are UTC.
189
193
  - CI 不再只看默认分支:我自己开的 PR 所在分支也会被读,分支上的失败同样会成为事件;别人分支上的失败仍然不打扰。
190
194
  - 为此 gh run list 改为一次抓全部分支(上限 40 条),再按「默认分支 + 我的 PR 分支」过滤。
191
195
 
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.
196
+ ## 2.4.2
197
+
198
+ - 启动日志与通知里的轮询间隔改成可读写法:不足一分钟显示秒(poll every 20 秒),不再出现 poll 0 min。
199
+
200
+ ## 2.4.1
201
+
202
+ - 修复 2.3.0 引入的读取缺陷:多仓库状态文件被当成单仓库状态读回,于是每次轮询都从空的 已见 列表开始,lastRun 也每次重算。表现为旧的红运行反复被当成新事件、恢复通知无法触发。现在读回整个文件再按仓库取分片,并加了回归测试。
203
+ - 测试清理在 Windows 上遇到仍被占用目录时会重试,不再偶发 EBUSY。
204
+
205
+ ## 2.4.0
206
+
207
+ - README 改成产品向叙述:讲它替你挡住什么、你会看到什么、默认有多安静;版本变更、配置全表、已知边界不再堆在首页。
208
+ - 新增两份深入文档:[如何工作](docs/how-it-works.md)、[配置与命令](docs/configuration.md),`README.en.md` 同步改写。
209
+ - 通知里的收口命令默认带上插件自身的绝对路径,新装用户照抄即可执行(以前是个裸命令)。
210
+ - 命令行帮助与 `list` 脚注不再引用宿主项目的 npm 脚本写法。
211
+
212
+ ## 2.3.1
213
+
214
+ - 一次轮询失败会在 `plugin.log` 里留一行 `poll skipped: <reason>`。以前它和「收件箱是空的」长得一模一样。
215
+ - 新增 `debug` 开关(默认关):打开后 `plugin.log` 记录每个边界事件(会话注册、回合开始/结束、用户消息、每次轮询的进出),用来判断是没触发还是触发后没结果。
216
+
217
+ ## 2.3.0
218
+
219
+ - `repos`:一个实例订阅一组仓库。队列共用,状态按仓库分片(`state.json` 的 `repos`),事件 key 带仓库前缀 `owner/name#…`——同一个 PR 号在不同仓库是两个事件。
220
+ - `--repo` 可重复、`INBOX_REPO` 接受逗号或空格分隔的列表;`status` 逐个仓库显示上次轮询的身份、耗时与事件数。
221
+ - 2.0/2.1 的旧单仓库状态文件按它上次轮询的仓库自动收编,不会把历史事件重发一遍。
222
+ - 启动时写一行日志(注册的会话数、回合内轮询间隔、投递方式、仓库),装完能直接确认插件活着。
223
+
224
+ ## 2.2.0
225
+
226
+ - 轮询改成跟回合走:回合开始一次、进行中每 `intervalMs` 一次、结束一次;空闲时不轮询、不留下定时器。`intervalMs` 因此从「固定轮询间隔」变成「回合内间隔」,默认 45 秒 → 10 分钟。
227
+ - `wakeup` 重做为可审计的四道门:`wakeOn` 角色白名单(默认空 = 永不唤醒)、`wakeAfterIdleMs`(默认 15 分钟)、`wakesPerHour`(默认 2)、每会话 `maxConsecutiveWakes`。每次唤醒写 `woke <session> because <role>:<key>`,被拒时写 `no wakeup: <why>`。
228
+ - 删掉唤醒文案里那句不存在的空闲承诺:现在文案复述的是同一个判断所用的规则。
229
+ - 新增 `status` 子命令:仓库、身份、角色、投递方式、队列计数、上次轮询(身份 / 耗时 / 事件数),只读本地文件。
230
+ - `.work/inbox-bridge/runtime.json` 记录插件本轮生效的配置,`status` 因此能看到插件真实生效值而不是默认值。
231
+ - 仓库状态里记下 `lastPoll`:谁读的、多久、几个事件。
232
+ - 首次轮询只按分支当前状态报一次:新工作区的第一次 poll 不再把窗口里几天前的红运行逐个翻出来。
233
+ - 删掉 Windows 通知弹窗与 `--no-toast`:通知只走 DSH 会话。
234
+ - 环境变量统一为 `INBOX_REPO` / `INBOX_GH` / `INBOX_IDENTITY_*`。
235
+ - 文档重写为按定位叙述(运输层通用、来源当前只有 GitHub),不再讲项目来历。
236
+
237
+ ## 2.1.0
238
+
239
+ - 新增 `identity`:poller 以某个身份读 GitHub(本机 `gh` 登录,或 App 安装令牌),并从身份推导每条事件的角色。
240
+ - 新增 `roles`:本机只接受哪些角色(`author` / `reviewer` / `assignee` / `mention` / `ci`);空数组表示全部接受。
241
+ - 事件按角色过滤:别人欠的评审、别人作者的 PR 失败不再变成我的通知;`REVIEW_REQUIRED` 单独不再成事件,只有**我被请求评审**才提醒。
242
+ - 事件 key 带角色段(`pr:131:author:…`、`comment:6885266487:mention`、`issue:150:assignee:…`);`repo` 与 `role` 写进每条事件,投递侧不再从会话 cwd 猜。
243
+ - 修复:只 ack 真正投出去的 key,之前没投出去的事件会被误标 `delivered`,因此永远不再重投。
244
+ - 修复:`delivery: wakeup` 的通知文案不再承诺「长时间没人发言才开一轮」——当前没有空闲门槛,文案改为如实描述。
245
+ - App 身份跳过 `/notifications`(App 没有用户收件箱,该接口返回 403),只读仓库状态。
246
+ - 新增 `ROADMAP.md`;README 明确定位:运输层通用、来源层当前只有 GitHub。
247
+
248
+ ## 2.0.4
249
+
250
+ - 描述以「队列 + 回合边界投递」为主语,轮询只作为采集实现写进「工作原理」:2.0.0 之后的产品语义是事件收件箱,不是“轮询一个外部来源”。
251
+
252
+ ## 2.0.3
253
+
254
+ - 统一对外描述:插件只读 GitHub(CI、PR、issue),不再宣称“任意外部来源 / 邮件 / 本地命令”;标题、描述、README 与市场索引使用同一句话,版本与用例数同步。
255
+
256
+ ## 2.0.2
257
+
258
+ - PR 事件摘要只看“需要你处理的状态”(失败检查 + 评审决定):进行中/成功完成的检查不再进入事件 key,同一个 PR 在检查跑完前不会反复触发通知与唤醒。
259
+
260
+ ## 2.0.1
261
+
262
+ - 轮询直接抓取仓库的 open issues:GitHub notifications 只覆盖你订阅的线程,别人新开的 issue 以前会被静默漏掉(#156 / #152)。
263
+
264
+ ## 2.0.0
265
+
266
+ - 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.
267
+ - 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.
268
+ - 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.
269
+ - The "no repository to watch" reminder only reaches sessions that cannot name a repository themselves.
270
+
271
+ ## 1.5.1
272
+
273
+ - Fix: wake messages now hand the whole message to `followup()` and `inject()`, so the session log keeps `role` and the conversation can be reopened.
274
+
275
+ ## 1.5.0
276
+
277
+ - Wake one idle session (configurable) with `followup()` instead of only injecting context.
278
+ - Poll every 45 seconds by default instead of 120 seconds.
279
+
280
+ ## 1.4.0
281
+
282
+ - Standalone project: plugin, CLI and GitHub collector ship as one package.
283
+ - Three-state bookkeeping (pending / delivered / done), resurfacing after six hours, and automatic closing of resolved failures.
@@ -66,7 +66,7 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
66
66
  | 评论 | 不是我自己发的,且 @我 |
67
67
  | CI | 默认分支,以及我自己 PR 那条分支;红的才出声,恢复时给一条「已恢复」 |
68
68
  | 基础设施失败 | 只提醒一次,因为再改代码也修不好它 |
69
- | 安全告警 | 开着的 Dependabot 与 code scanning 告警;按告警编号做 key,修掉后下一次轮询就收口 |
69
+ | 安全告警 | 开着的 Dependabot 与 code scanning 告警;每个来源合成一条(条数与严重度分布),修完最后一条后下一次轮询就收口 |
70
70
  | PR 变脏 | 我是作者或指派人,且 PR 与基分支冲突或落后;评审人不算,合并是作者的事 |
71
71
 
72
72
  同一条事实不会因为检查状态变来变去就变成好几条通知: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.17.1",
54
+ "publishTimestamp": 1794913490,
55
55
  "source": {
56
56
  "type": "git",
57
57
  "url": "https://github.com/c3115644151/dsh-inbox-bridge",
58
- "commit": "44dc921ec4ad7afbcda547c6907ca6231ba7e351"
58
+ "commit": "d2191625a4e1c02b1e4d5e1b79fa8e8d8198f6e5"
59
59
  },
60
60
  "engines": {
61
61
  "dsh": ">=0.1.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-inbox-bridge",
3
- "version": "2.17.0",
3
+ "version": "2.17.1",
4
4
  "displayName": "GitHub inbox",
5
5
  "description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
6
6
  "type": "module",
@@ -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({}),