dsh-inbox-bridge 2.17.1 → 2.18.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 +13 -0
- package/README.en.md +3 -2
- package/README.md +3 -2
- package/client.js +52 -0
- package/docs/configuration.md +15 -2
- package/docs/how-it-works.md +2 -1
- package/docs/index.json +3 -3
- package/index.js +114 -5
- package/package.json +2 -2
- package/scripts/clear-inbox.mjs +170 -20
- package/scripts/clear-inbox.test.mjs +59 -0
- package/scripts/inbox-bridge.mjs +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## 2.18.1
|
|
2
|
+
|
|
3
|
+
- 归档只碰订阅的仓库:按仓库逐个打开 GitHub 的通知搜索视图(`repo:owner/name`),只归档这些视图里的线程。以前它选中整个收件箱,会把账号里其它仓库的通知一起归档。
|
|
4
|
+
- 没有订阅时不再归档任何东西(`--all` 才动整个收件箱),所以后台轮询不会替别人做决定。
|
|
5
|
+
- 登录窗口结束后的那次归档也带上同一份订阅。
|
|
6
|
+
- 登录现在能留住:GitHub 的会话 cookie 是会话级的,插件在浏览器配置里打开「恢复上次会话」,不再一次运行后就被登出。
|
|
7
|
+
- `--check` 与 `doctor` 的登录痕迹改看 `Default/Network/Cookies`(Chromium 96 之后的位置)。
|
|
8
|
+
## 2.18.0
|
|
9
|
+
|
|
10
|
+
- 归档不再让你去终端登录:把「消息清理」切到归档,插件自己弹出登录窗口;会话失效而选项仍在归档上时,下一次归档失败会再开一次(signInCooldownMs 默认 6 小时,防打扰)。
|
|
11
|
+
- 卡片里还没登录时会写「归档还没登录 GitHub」,旁边是「打开登录窗口」按钮。
|
|
12
|
+
- scripts/clear-inbox.mjs --check 只回答「登录了没」(没登录退出码 2);没有 cookie 库时不启动浏览器。
|
|
13
|
+
- 归档起的是独立进程,宿主的轮询不会被一个二十分钟的登录挡住。
|
|
1
14
|
## 2.17.1
|
|
2
15
|
|
|
3
16
|
- 安全告警改成每个来源一条:一个依赖就可能带二十条开着的告警,逐条报告会把队列淹掉、把一次修复变成二十条通知。现在一条里写明条数、严重度分布和涉及的两三个包名,修完最后一条自动收口。
|
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
|
|
94
|
+
| `sweep` | off | archive the threads of the **repositories you subscribe to** 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,8 @@ 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
|
-
- **
|
|
104
|
+
- **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
|
+
- **Archiving touches only the repositories you subscribe to.** It opens GitHub's notification search per repository (`repo:owner/name`) and archives what is in that view; with no subscription it archives nothing. The whole inbox needs an explicit `--all`.
|
|
105
106
|
- **State is local.** It lives under `.work/` in the working directory and is not synced across machines.
|
|
106
107
|
|
|
107
108
|
## 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` | 关 |
|
|
94
|
+
| `sweep` | 关 | 有发现的回合把**订阅的仓库**的通知归档到 Done;缺登录时插件自己弹窗口让你登录一次 |
|
|
95
95
|
|
|
96
96
|
面板里的「消息清理」一档同时管这两件事:**关闭**(都不做)、**已读**(清蓝点)、**归档**(标已读并存进 Done)。
|
|
97
97
|
|
|
@@ -101,7 +101,8 @@ dsh plugin add dsh-inbox-bridge
|
|
|
101
101
|
|
|
102
102
|
- **只读。** 不合并、不评论、不修改仓库。
|
|
103
103
|
- **默认不主动开启对话。** 只有显式设置 `delivery: wakeup` 且命中 `wakeOn`、会话足够空闲、两个预算都还有余额时才会;任何一道门不过,就退回只排队。
|
|
104
|
-
- **Done
|
|
104
|
+
- **Done 归档依赖一次浏览器登录,但不用你敲命令。** GitHub 没有归档 API,`scripts/clear-inbox.mjs` 通过本机浏览器(Edge / Chrome / Chromium)完成。把「消息清理」切到归档,插件会自己弹出登录窗口;会话失效时会再弹一次。
|
|
105
|
+
- **归档只碰你订阅的仓库。** 它按仓库逐个打开 GitHub 的通知搜索视图(`repo:owner/name`),只归档这些视图里的线程;没有订阅就什么都不归档。整个收件箱要显式 `--all` 才会动。
|
|
105
106
|
- **状态在本机。** 存放在工作目录的 `.work/` 下,不跨机器同步。
|
|
106
107
|
|
|
107
108
|
## 更多
|
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 },
|
package/docs/configuration.md
CHANGED
|
@@ -34,6 +34,18 @@ 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` 只报数量,`--repo owner/name`(可重复,插件通过 `INBOX_REPO` 传)指定范围,`--all` 才是整个收件箱。
|
|
46
|
+
|
|
47
|
+
登录状态能活下来,靠的是插件在浏览器配置里打开「恢复上次会话」——GitHub 的会话 cookie 本身是会话级的,Chromium 默认在关闭时丢掉它。
|
|
48
|
+
|
|
37
49
|
## 全部配置项
|
|
38
50
|
|
|
39
51
|
| 键 | 默认 | 作用 |
|
|
@@ -56,7 +68,8 @@ DSH 的插件配置里,一个 `dsh-inbox-bridge` 条目即可;等价写法
|
|
|
56
68
|
| `identity` | `{ kind: "user" }` | 用哪个身份读 GitHub,见下 |
|
|
57
69
|
| `roles` | `[]` | 只接收这些角色的事件;空 = 全收 |
|
|
58
70
|
| `clear` | `"repo"` | 把这一轮读过的通知线程标为已读:`repo` 只清订阅的仓库,`off` 不碰收件箱。整个账号不在范围内——清别人的仓库属于人的决定,不是后台轮询的决定。旧配置里的 `"all"` 按 `"repo"` 载入。GitHub 没有「完成」API,所以清的是未读角标,历史仍在收件箱里 |
|
|
59
|
-
| `sweep` | `null` | 抓到东西后把收件箱归档进 Done:`{ args: ["scripts/clear-inbox.mjs"], when: "events" }`。`when: "events"` 只在有发现的回合跑,`"always"`
|
|
71
|
+
| `sweep` | `null` | 抓到东西后把收件箱归档进 Done:`{ args: ["scripts/clear-inbox.mjs"], when: "events" }`。`when: "events"` 只在有发现的回合跑,`"always"` 每轮都跑。**只归档订阅的仓库**(按仓库逐个走 `repo:` 搜索视图),没有订阅时什么都不归档;整个收件箱要显式 `--all`。归档要有插件的浏览器配置里的一次登录;没有就让面板替你打开窗口,见下 |
|
|
72
|
+
| `signInCooldownMs` | `21600000`(6 小时) | 归档缺登录时,两次「替你打开登录窗口」之间至少隔多久。长到不打扰,短到会话失效后的下一个事件还能恢复 |
|
|
60
73
|
| `debug` | `false` | 把每个边界事件写进 `plugin.log`,用来排查「没轮询」还是「轮询了没结果」 |
|
|
61
74
|
| `poll` | 插件自带 CLI 的 `poll` | 换掉抓取命令:`{ command, args }`,只要能输出约定的 JSON,来源可以不是 GitHub |
|
|
62
75
|
| `ack` | 插件自带 CLI 的 `ack` | 同上,换掉收口命令 |
|
|
@@ -94,7 +107,7 @@ node scripts/inbox-bridge.mjs poll # 立刻抓一次
|
|
|
94
107
|
node scripts/inbox-bridge.mjs ack --done -- <key> # 划掉一条,并停止提醒
|
|
95
108
|
node scripts/inbox-bridge.mjs ack --all-delivered --done # 把所有 delivered 一次划掉
|
|
96
109
|
node scripts/inbox-bridge.mjs doctor # 逐项自检:身份、仓库可读性、上次轮询、队列、归档登录
|
|
97
|
-
node scripts/inbox-bridge.mjs explain <key> # 某件事走到哪一步了,为什么没到你眼前
|
|
110
|
+
node scripts/inbox-bridge.mjs explain <key> # 某件事走到哪一步了,为什么没到你眼前
|
|
98
111
|
```
|
|
99
112
|
|
|
100
113
|
`ack` 不带 `--done` 只把它们标成 delivered,意思是「给过了但还没处理」——6 小时后会再提。经 `npm run` 转发时,`--done` 必须写在 `--` 之后,否则被 npm 吞掉。
|
package/docs/how-it-works.md
CHANGED
|
@@ -36,7 +36,7 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
|
|
|
36
36
|
7. 投递:`quiet` 时注入给空闲的会话、等它下一轮;`wakeup` 时先过四道门。
|
|
37
37
|
8. 只把**真正投出去**的 key 标 delivered。没投出去的下次还有机会,不会被误标。
|
|
38
38
|
9. 把这些线程标为已读(`clear`,默认只清订阅的仓库;整个账号不在范围内)。GitHub 没有「完成」的公开接口,所以清掉的是未读角标,收件箱里的历史还在——在你自己的界面上一切照旧可查。
|
|
39
|
-
10. 如果配了 `sweep`,在**这一轮真的抓到东西**时顺手把它们归档进 Done(`scripts/clear-inbox.mjs` 用一次浏览器完成,约 3–5
|
|
39
|
+
10. 如果配了 `sweep`,在**这一轮真的抓到东西**时顺手把它们归档进 Done(`scripts/clear-inbox.mjs` 用一次浏览器完成,约 3–5 秒)。它按仓库逐个打开 GitHub 的通知搜索视图(`repo:owner/name`),只归档订阅的这些视图里的线程;没有订阅就一条也不归档(整个收件箱要显式 `--all`)。没抓到就什么也不做,空回合不花这笔钱。
|
|
40
40
|
|
|
41
41
|
## 页面怎么读这份状态
|
|
42
42
|
|
|
@@ -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
|
## 「跟我有关」怎么判断
|
package/docs/index.json
CHANGED
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
},
|
|
51
51
|
"versions": [
|
|
52
52
|
{
|
|
53
|
-
"version": "2.
|
|
54
|
-
"publishTimestamp":
|
|
53
|
+
"version": "2.18.1",
|
|
54
|
+
"publishTimestamp": 1794916042,
|
|
55
55
|
"source": {
|
|
56
56
|
"type": "git",
|
|
57
57
|
"url": "https://github.com/c3115644151/dsh-inbox-bridge",
|
|
58
|
-
"commit": "
|
|
58
|
+
"commit": "0fbc3f3afd5af257321d253c4061165a7ee00ba2"
|
|
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,80 @@ 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: {
|
|
484
|
+
...process.env,
|
|
485
|
+
// The window finishes the sweep after a sign-in; give it the same
|
|
486
|
+
// subscription the poll uses, or it would not know what to archive.
|
|
487
|
+
...(options.repos?.length > 0
|
|
488
|
+
? { INBOX_REPO: options.repos.join(",") }
|
|
489
|
+
: options.repo
|
|
490
|
+
? { INBOX_REPO: options.repo }
|
|
491
|
+
: {}),
|
|
492
|
+
ELECTRON_RUN_AS_NODE: "1",
|
|
493
|
+
},
|
|
494
|
+
// Detached so a twenty-minute sign-in never holds a poll open; visible
|
|
495
|
+
// because there has to be a window to sign in.
|
|
496
|
+
detached: true,
|
|
497
|
+
windowsHide: false,
|
|
498
|
+
stdio: "ignore",
|
|
499
|
+
});
|
|
500
|
+
child.once("exit", () => {
|
|
501
|
+
signIn.open = false;
|
|
502
|
+
});
|
|
503
|
+
child.unref?.();
|
|
504
|
+
} catch (error) {
|
|
505
|
+
signIn.open = false;
|
|
506
|
+
log(`could not open the sign-in window: ${describe(error)}`);
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
log(`opened the sign-in window (${reason}); archiving resumes once you sign in`);
|
|
510
|
+
return true;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
const checkSignIn = async () => {
|
|
514
|
+
const script = sweepScript();
|
|
515
|
+
if (!script) return;
|
|
516
|
+
try {
|
|
517
|
+
await runCommand({ command: "node", args: [script, "--check", "--json"] }, options);
|
|
518
|
+
signIn.signedIn = true;
|
|
519
|
+
} catch (error) {
|
|
520
|
+
if (error?.exitCode === 2) signIn.signedIn = false;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
439
524
|
const sweepInbox = async (freshCount) => {
|
|
440
525
|
if (!options.sweep) return;
|
|
441
526
|
if (options.sweep.when === "events" && freshCount === 0) return;
|
|
@@ -443,13 +528,15 @@ export function apply(ctx, config) {
|
|
|
443
528
|
try {
|
|
444
529
|
const stdout = await runCommand(options.sweep, options);
|
|
445
530
|
const line = String(stdout ?? "").trim().split(/\r?\n/u).pop() ?? "";
|
|
531
|
+
signIn.signedIn = true;
|
|
446
532
|
log(`swept the notification inbox: ${line || "done"} (${Date.now() - began}ms)`);
|
|
447
533
|
} catch (error) {
|
|
448
534
|
if (error?.exitCode === 2) {
|
|
449
|
-
|
|
450
|
-
log
|
|
451
|
-
|
|
452
|
-
);
|
|
535
|
+
// The command says "sign-in required"; raise the window rather than
|
|
536
|
+
// asking the operator to copy a command out of the log.
|
|
537
|
+
signIn.signedIn = false;
|
|
538
|
+
log("the archive needs a browser sign-in");
|
|
539
|
+
openSignIn("the archive found no sign-in");
|
|
453
540
|
} else {
|
|
454
541
|
log(`sweep failed: ${describe(error)}`);
|
|
455
542
|
}
|
|
@@ -616,6 +703,9 @@ export function apply(ctx, config) {
|
|
|
616
703
|
`wakeOn ${options.wakeOn.join(",")} is idle: delivery is ${options.delivery}, so those roles only queue`,
|
|
617
704
|
);
|
|
618
705
|
}
|
|
706
|
+
// Archiving only works with a browser session; find out once at start whether
|
|
707
|
+
// there is one, so the panel can say so before the first event arrives.
|
|
708
|
+
if (options.sweep) void checkSignIn();
|
|
619
709
|
|
|
620
710
|
// A turn is the only thing that makes the inbox worth reading: poll when one
|
|
621
711
|
// starts, re-poll while a long one runs, poll once more when it ends. An idle
|
|
@@ -776,10 +866,20 @@ export function apply(ctx, config) {
|
|
|
776
866
|
sessionId,
|
|
777
867
|
sessionRepo,
|
|
778
868
|
});
|
|
869
|
+
if (action === "signin") {
|
|
870
|
+
// Not a setting: open the window that archiving needs.
|
|
871
|
+
const opened = openSignIn("you asked for it in the panel");
|
|
872
|
+
return reply(200, { ok: true, opened, status: uiPayload(sessionId) });
|
|
873
|
+
}
|
|
779
874
|
if (next === null) {
|
|
780
875
|
return reply(400, { ok: false, error: `unknown setting: ${action || "-"}` });
|
|
781
876
|
}
|
|
782
877
|
applyPrefs(next);
|
|
878
|
+
// Choosing the archive mode is also the request for a sign-in when
|
|
879
|
+
// there is none: the mode does nothing without one.
|
|
880
|
+
const wantsArchive =
|
|
881
|
+
(action === "clean" && value === "done") || (action === "archive" && value === "on");
|
|
882
|
+
if (wantsArchive && signIn.signedIn !== true) openSignIn("archive was turned on");
|
|
783
883
|
} catch (error) {
|
|
784
884
|
return reply(400, { ok: false, error: describe(error) });
|
|
785
885
|
}
|
|
@@ -1065,9 +1165,16 @@ export function mergeConfig(config) {
|
|
|
1065
1165
|
}
|
|
1066
1166
|
sweepSpec = { command: sweep.command ?? "node", args: sweep.args ?? [], when };
|
|
1067
1167
|
}
|
|
1168
|
+
const signInCooldownMs = given.signInCooldownMs ?? DEFAULTS.signInCooldownMs;
|
|
1169
|
+
if (!Number.isInteger(signInCooldownMs) || signInCooldownMs < 0) {
|
|
1170
|
+
throw new Error(
|
|
1171
|
+
`inbox-bridge: \`signInCooldownMs\` must be a non-negative integer, got ${JSON.stringify(signInCooldownMs)}`,
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1068
1174
|
return {
|
|
1069
1175
|
...DEFAULTS,
|
|
1070
1176
|
...given,
|
|
1177
|
+
signInCooldownMs,
|
|
1071
1178
|
repo,
|
|
1072
1179
|
repos: watched,
|
|
1073
1180
|
delivery,
|
|
@@ -1288,6 +1395,7 @@ export function buildUiPayload({
|
|
|
1288
1395
|
recent = new Map(),
|
|
1289
1396
|
now = Date.now(),
|
|
1290
1397
|
session = null,
|
|
1398
|
+
signIn = null,
|
|
1291
1399
|
}) {
|
|
1292
1400
|
const configured = options.repos?.length > 0 ? options.repos : options.repo ? [options.repo] : [];
|
|
1293
1401
|
// A session sees exactly what a poll would deliver to it: the repositories it
|
|
@@ -1344,6 +1452,7 @@ export function buildUiPayload({
|
|
|
1344
1452
|
delivery: options.delivery ?? DEFAULTS.delivery,
|
|
1345
1453
|
clear: options.clear ?? DEFAULTS.clear,
|
|
1346
1454
|
sweep: options.sweep?.when ?? null,
|
|
1455
|
+
signIn: signIn ?? { signedIn: null, open: false, attemptedAt: null },
|
|
1347
1456
|
intervalMs: options.intervalMs ?? DEFAULTS.intervalMs,
|
|
1348
1457
|
queue: counts,
|
|
1349
1458
|
events: events.slice(0, 20),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-inbox-bridge",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.1",
|
|
4
4
|
"displayName": "GitHub inbox",
|
|
5
5
|
"description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
|
|
6
6
|
"type": "module",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"screenshots.json"
|
|
46
46
|
],
|
|
47
47
|
"scripts": {
|
|
48
|
-
"test": "node --test index.test.mjs scripts/github-inbox.test.mjs scripts/inbox-bridge.test.mjs",
|
|
48
|
+
"test": "node --test index.test.mjs scripts/github-inbox.test.mjs scripts/inbox-bridge.test.mjs scripts/clear-inbox.test.mjs",
|
|
49
49
|
"market": "node scripts/build-market-index.mjs",
|
|
50
50
|
"market:check": "node scripts/build-market-index.mjs --check",
|
|
51
51
|
"market:release": "node scripts/build-market-index.mjs --check --release"
|
package/scripts/clear-inbox.mjs
CHANGED
|
@@ -15,13 +15,31 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { spawn } from "node:child_process";
|
|
18
|
-
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
|
19
|
-
import { join, resolve } from "node:path";
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { dirname, join, resolve } from "node:path";
|
|
20
|
+
import { pathToFileURL } from "node:url";
|
|
20
21
|
|
|
21
22
|
const DEFAULT_PORT = 9333;
|
|
22
23
|
const NOTIFICATIONS = "https://github.com/notifications";
|
|
23
24
|
const PROFILE_REL = join(".work", "browser-profile");
|
|
24
25
|
|
|
26
|
+
/** The notification view for one repository, or the whole inbox for `null`. */
|
|
27
|
+
export function inboxUrlFor(repo) {
|
|
28
|
+
return repo ? `${NOTIFICATIONS}?query=${encodeURIComponent(`repo:${repo}`)}` : NOTIFICATIONS;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Which notification views to archive. The default is the subscription the
|
|
33
|
+
* plugin watches — never the whole account, because a background poll must not
|
|
34
|
+
* decide what to do with another repository's mail.
|
|
35
|
+
*/
|
|
36
|
+
export function archiveTargets(options = {}) {
|
|
37
|
+
if (options.all) return { ok: true, targets: [null] };
|
|
38
|
+
const repos = options.repos ?? [];
|
|
39
|
+
if (repos.length === 0) return { ok: false, reason: "no-subscription", targets: [] };
|
|
40
|
+
return { ok: true, targets: repos };
|
|
41
|
+
}
|
|
42
|
+
|
|
25
43
|
const WINDOWS_CANDIDATES = [
|
|
26
44
|
"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
|
|
27
45
|
"C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe",
|
|
@@ -59,13 +77,28 @@ function onPath(command) {
|
|
|
59
77
|
return dirs.some((dir) => dir && names.some((name) => existsSync(join(dir, name))));
|
|
60
78
|
}
|
|
61
79
|
|
|
62
|
-
function parseArgs(argv = []) {
|
|
63
|
-
const options = {
|
|
80
|
+
export function parseArgs(argv = []) {
|
|
81
|
+
const options = {
|
|
82
|
+
json: false,
|
|
83
|
+
login: false,
|
|
84
|
+
dryRun: false,
|
|
85
|
+
check: false,
|
|
86
|
+
all: false,
|
|
87
|
+
repos: [],
|
|
88
|
+
port: DEFAULT_PORT,
|
|
89
|
+
keepOpen: false,
|
|
90
|
+
};
|
|
64
91
|
for (const argument of argv) {
|
|
65
92
|
if (argument === "--json") options.json = true;
|
|
66
93
|
else if (argument === "--login") options.login = true;
|
|
67
94
|
else if (argument === "--dry-run") options.dryRun = true;
|
|
68
|
-
else if (argument === "--
|
|
95
|
+
else if (argument === "--check") options.check = true;
|
|
96
|
+
else if (argument === "--all") options.all = true;
|
|
97
|
+
else if (argument === "--repo") options.expectRepo = true;
|
|
98
|
+
else if (options.expectRepo) {
|
|
99
|
+
options.repos.push(...argument.split(/[,\s]+/u).filter(Boolean));
|
|
100
|
+
options.expectRepo = false;
|
|
101
|
+
} else if (argument === "--keep-open") options.keepOpen = true;
|
|
69
102
|
else if (argument === "--port") options.expectPort = true;
|
|
70
103
|
else if (options.expectPort) {
|
|
71
104
|
options.port = Number(argument);
|
|
@@ -74,6 +107,14 @@ function parseArgs(argv = []) {
|
|
|
74
107
|
else throw new Error(`unknown option: ${argument}`);
|
|
75
108
|
}
|
|
76
109
|
if (options.expectPort) throw new Error("`--port` needs a value");
|
|
110
|
+
if (options.expectRepo) throw new Error("`--repo` needs a value");
|
|
111
|
+
// The plugin passes its subscription in INBOX_REPO, so a configured sweep is
|
|
112
|
+
// scoped without repeating the list in `sweep.args`.
|
|
113
|
+
const fromEnv = (process.env.INBOX_REPO ?? "").split(/[,\s]+/u).filter(Boolean);
|
|
114
|
+
const repos = options.repos.length > 0 ? options.repos : fromEnv;
|
|
115
|
+
options.repos = repos.filter((repo) => /^[\w.-]+\/[\w.-]+$/u.test(repo));
|
|
116
|
+
const bad = repos.filter((repo) => !/^[\w.-]+\/[\w.-]+$/u.test(repo));
|
|
117
|
+
if (bad.length > 0) throw new Error(`not an owner/name repository: ${bad.join(", ")}`);
|
|
77
118
|
return options;
|
|
78
119
|
}
|
|
79
120
|
|
|
@@ -168,10 +209,13 @@ async function main(argv) {
|
|
|
168
209
|
if (options.help) {
|
|
169
210
|
console.log(
|
|
170
211
|
[
|
|
171
|
-
"clear-inbox — archive
|
|
212
|
+
"clear-inbox — archive the GitHub notification threads of the repositories you watch, then close the browser",
|
|
172
213
|
"",
|
|
214
|
+
" --repo <owner/name> archive only this repository's threads (repeatable; defaults to INBOX_REPO)",
|
|
215
|
+
" --all archive the whole notification inbox instead of one repository at a time",
|
|
173
216
|
" --json machine-readable summary",
|
|
174
217
|
" --dry-run report how many threads would be archived",
|
|
218
|
+
" --check only say whether this profile is signed in (exit 2 if not)",
|
|
175
219
|
" --login open a visible window so you can sign in once",
|
|
176
220
|
" --keep-open leave the browser running after the sweep",
|
|
177
221
|
" --port N DevTools port (default 9333)",
|
|
@@ -182,7 +226,36 @@ async function main(argv) {
|
|
|
182
226
|
|
|
183
227
|
const root = process.cwd();
|
|
184
228
|
const profileDir = resolve(root, PROFILE_REL);
|
|
229
|
+
// Chromium keeps cookies under Network/ since v96; older builds used Default/.
|
|
230
|
+
const cookieFiles = [
|
|
231
|
+
join(profileDir, "Default", "Network", "Cookies"),
|
|
232
|
+
join(profileDir, "Default", "Cookies"),
|
|
233
|
+
];
|
|
234
|
+
// A profile with no cookie database has never been signed in. Answering that
|
|
235
|
+
// here keeps `--check` from launching a browser just to learn it is useless.
|
|
236
|
+
if (options.check && !cookieFiles.some((file) => existsSync(file))) {
|
|
237
|
+
if (options.json) console.log(JSON.stringify({ ok: false, reason: "sign-in-required" }));
|
|
238
|
+
else console.log("not signed in: archiving cannot run yet");
|
|
239
|
+
return 2;
|
|
240
|
+
}
|
|
185
241
|
mkdirSync(profileDir, { recursive: true });
|
|
242
|
+
// GitHub's session cookie is a session cookie, and Chromium only keeps those
|
|
243
|
+
// across restarts when the profile restores its last session. Without this the
|
|
244
|
+
// sign-in survives exactly one run — which looks like "it forgot me again".
|
|
245
|
+
try {
|
|
246
|
+
const file = join(profileDir, "Default", "Preferences");
|
|
247
|
+
let prefs = {};
|
|
248
|
+
try {
|
|
249
|
+
prefs = JSON.parse(readFileSync(file, "utf8"));
|
|
250
|
+
} catch {
|
|
251
|
+
prefs = {};
|
|
252
|
+
}
|
|
253
|
+
prefs.session = { ...(prefs.session ?? {}), restore_on_startup: 1 };
|
|
254
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
255
|
+
writeFileSync(file, JSON.stringify(prefs), "utf8");
|
|
256
|
+
} catch {
|
|
257
|
+
// A profile we cannot pre-seed still works for one run.
|
|
258
|
+
}
|
|
186
259
|
const browser = findBrowser();
|
|
187
260
|
const base = `http://127.0.0.1:${options.port}`;
|
|
188
261
|
const headless = !options.login;
|
|
@@ -276,20 +349,94 @@ async function main(argv) {
|
|
|
276
349
|
}
|
|
277
350
|
}
|
|
278
351
|
|
|
279
|
-
|
|
352
|
+
// `--check` answers one question and touches nothing: is this profile
|
|
353
|
+
// signed in? The panel and `doctor` need that without archiving anything.
|
|
354
|
+
if (options.check) {
|
|
280
355
|
const rows = await read(
|
|
281
356
|
`document.querySelectorAll('input[type=checkbox][name="notification_ids[]"]').length`,
|
|
282
357
|
);
|
|
283
|
-
if (options.json) console.log(JSON.stringify({ ok: true,
|
|
284
|
-
else console.log(
|
|
358
|
+
if (options.json) console.log(JSON.stringify({ ok: true, signedIn: true, rows }));
|
|
359
|
+
else console.log("signed in: archiving can run");
|
|
360
|
+
return 0;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// One view per subscribed repository: GitHub's notification search takes
|
|
364
|
+
// `repo:`, and Done applies to the rows in view — so this archives what
|
|
365
|
+
// the plugin watches instead of everything the account ever received.
|
|
366
|
+
const plan = archiveTargets(options);
|
|
367
|
+
if (!plan.ok) {
|
|
368
|
+
if (options.json) console.log(JSON.stringify({ ok: false, reason: plan.reason }));
|
|
369
|
+
else
|
|
370
|
+
console.error(
|
|
371
|
+
"nothing archived: pass --repo owner/name (or INBOX_REPO), or --all for the whole inbox",
|
|
372
|
+
);
|
|
373
|
+
return 2;
|
|
374
|
+
}
|
|
375
|
+
const targets = plan.targets;
|
|
376
|
+
const urlFor = inboxUrlFor;
|
|
377
|
+
|
|
378
|
+
const waitForList = async () => {
|
|
379
|
+
const deadline = Date.now() + 30_000;
|
|
380
|
+
let view = null;
|
|
381
|
+
while (Date.now() < deadline) {
|
|
382
|
+
view = await read(`(() => ({
|
|
383
|
+
ready: document.readyState,
|
|
384
|
+
rows: document.querySelectorAll('input[type=checkbox][name="notification_ids[]"]').length,
|
|
385
|
+
caughtUp: document.body.innerText.includes('All caught up'),
|
|
386
|
+
signIn: /\\/login|\\/session/.test(location.pathname),
|
|
387
|
+
}))()`);
|
|
388
|
+
if (view.signIn) return view;
|
|
389
|
+
if (view.ready === "complete" && (view.rows > 0 || view.caughtUp)) return view;
|
|
390
|
+
await sleep(400);
|
|
391
|
+
}
|
|
392
|
+
return view;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const unsorted = async () => {
|
|
396
|
+
if (options.json) console.log(JSON.stringify({ ok: false, reason: "sign-in-required" }));
|
|
397
|
+
else
|
|
398
|
+
console.error(
|
|
399
|
+
"not signed in: run `node scripts/clear-inbox.mjs --login` once, sign in, and it will finish the sweep",
|
|
400
|
+
);
|
|
401
|
+
return 2;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
if (options.dryRun) {
|
|
405
|
+
const perRepo = [];
|
|
406
|
+
let total = 0;
|
|
407
|
+
for (const repo of targets) {
|
|
408
|
+
await devtools.send("Page.navigate", { url: urlFor(repo) });
|
|
409
|
+
const view = await waitForList();
|
|
410
|
+
if (view?.signIn) return await unsorted();
|
|
411
|
+
perRepo.push({ repo, rows: view?.rows ?? 0 });
|
|
412
|
+
total += view?.rows ?? 0;
|
|
413
|
+
}
|
|
414
|
+
if (options.json) console.log(JSON.stringify({ ok: true, dryRun: true, rows: total, perRepo }));
|
|
415
|
+
else console.log(`would archive ${total} thread(s) (${perRepo.map((each) => `${each.repo ?? "everything"}: ${each.rows}`).join(", ")})`);
|
|
285
416
|
return 0;
|
|
286
417
|
}
|
|
287
418
|
|
|
288
|
-
const
|
|
289
|
-
const
|
|
419
|
+
const started = Date.now();
|
|
420
|
+
const perRepo = [];
|
|
421
|
+
for (const repo of targets) {
|
|
422
|
+
await devtools.send("Page.navigate", { url: urlFor(repo) });
|
|
423
|
+
const view = await waitForList();
|
|
424
|
+
if (view?.signIn) return await unsorted();
|
|
425
|
+
const result = await read(SWEEP);
|
|
426
|
+
perRepo.push({ repo, archived: result.archived ?? 0, before: result.before ?? 0 });
|
|
427
|
+
}
|
|
428
|
+
const archived = perRepo.reduce((sum, each) => sum + each.archived, 0);
|
|
429
|
+
const summary = {
|
|
430
|
+
ok: true,
|
|
431
|
+
archived,
|
|
432
|
+
repos: perRepo.map((each) => each.repo).filter(Boolean),
|
|
433
|
+
perRepo,
|
|
434
|
+
ms: Date.now() - started,
|
|
435
|
+
empty: archived === 0 && perRepo.every((each) => each.before === 0),
|
|
436
|
+
};
|
|
290
437
|
if (options.json) console.log(JSON.stringify(summary));
|
|
291
|
-
else if (
|
|
292
|
-
else console.log(`archived ${
|
|
438
|
+
else if (summary.empty) console.log("nothing to archive in the repositories you watch");
|
|
439
|
+
else console.log(`archived ${archived} thread(s) in ${Math.round(summary.ms / 100) / 10}s`);
|
|
293
440
|
return 0;
|
|
294
441
|
} finally {
|
|
295
442
|
devtools.close();
|
|
@@ -320,10 +467,13 @@ async function main(argv) {
|
|
|
320
467
|
}
|
|
321
468
|
}
|
|
322
469
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
);
|
|
470
|
+
// Importable for tests; only a direct run drives a browser.
|
|
471
|
+
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
|
|
472
|
+
main(process.argv.slice(2)).then(
|
|
473
|
+
(code) => process.exit(code ?? 0),
|
|
474
|
+
(error) => {
|
|
475
|
+
console.error(`clear-inbox: ${error.message}`);
|
|
476
|
+
process.exit(1);
|
|
477
|
+
},
|
|
478
|
+
);
|
|
479
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { archiveTargets, inboxUrlFor, parseArgs } from "./clear-inbox.mjs";
|
|
4
|
+
|
|
5
|
+
test("the sweep archives the repositories the plugin watches, one view each", () => {
|
|
6
|
+
const plan = archiveTargets({ repos: ["owner/one", "owner/two"] });
|
|
7
|
+
assert.deepEqual(plan.targets, ["owner/one", "owner/two"]);
|
|
8
|
+
assert.equal(plan.ok, true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("a sweep with no subscription refuses instead of taking the whole account", () => {
|
|
12
|
+
const plan = archiveTargets({ repos: [] });
|
|
13
|
+
assert.equal(plan.ok, false);
|
|
14
|
+
assert.equal(plan.reason, "no-subscription");
|
|
15
|
+
assert.deepEqual(plan.targets, []);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("`--all` is the one way to archive the whole inbox", () => {
|
|
19
|
+
assert.deepEqual(archiveTargets({ all: true }).targets, [null]);
|
|
20
|
+
assert.deepEqual(archiveTargets({ all: true, repos: ["owner/one"] }).targets, [null]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("each repository is a notification search view", () => {
|
|
24
|
+
assert.equal(
|
|
25
|
+
inboxUrlFor("owner/one"),
|
|
26
|
+
"https://github.com/notifications?query=repo%3Aowner%2Fone",
|
|
27
|
+
);
|
|
28
|
+
assert.equal(inboxUrlFor(null), "https://github.com/notifications");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("--repo is repeatable and also accepts a comma-joined list", () => {
|
|
32
|
+
const one = parseArgs(["--repo", "owner/one", "--repo", "owner/two"]);
|
|
33
|
+
assert.deepEqual(one.repos, ["owner/one", "owner/two"]);
|
|
34
|
+
const joined = parseArgs(["--repo", "owner/one,owner/two"]);
|
|
35
|
+
assert.deepEqual(joined.repos, ["owner/one", "owner/two"]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("a malformed repository name is refused rather than half-used", () => {
|
|
39
|
+
assert.throws(() => parseArgs(["--repo", "not-a-repo"]), /not an owner\/name repository/u);
|
|
40
|
+
assert.throws(() => parseArgs(["--repo"]), /`--repo` needs a value/u);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("the plugin's subscription arrives through INBOX_REPO", () => {
|
|
44
|
+
process.env.INBOX_REPO = "owner/one,owner/two";
|
|
45
|
+
try {
|
|
46
|
+
assert.deepEqual(parseArgs(["--json"]).repos, ["owner/one", "owner/two"]);
|
|
47
|
+
// An explicit --repo wins over the environment, so a manual run can narrow it.
|
|
48
|
+
assert.deepEqual(parseArgs(["--repo", "owner/three"]).repos, ["owner/three"]);
|
|
49
|
+
assert.equal(parseArgs(["--all"]).all, true);
|
|
50
|
+
} finally {
|
|
51
|
+
delete process.env.INBOX_REPO;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("--check and --dry-run are separate switches", () => {
|
|
56
|
+
const both = parseArgs(["--check", "--dry-run"]);
|
|
57
|
+
assert.equal(both.check, true);
|
|
58
|
+
assert.equal(both.dryRun, true);
|
|
59
|
+
});
|
package/scripts/inbox-bridge.mjs
CHANGED
|
@@ -565,21 +565,23 @@ export function describeDoctor(root, options = {}) {
|
|
|
565
565
|
}
|
|
566
566
|
|
|
567
567
|
if (runtime?.sweep && runtime.sweep !== "off" && runtime.sweep !== null) {
|
|
568
|
-
const
|
|
568
|
+
const profile = join(resolve(root), ".work", "browser-profile", "Default");
|
|
569
|
+
// Chromium keeps cookies under Network/ since v96; older builds used Default/.
|
|
570
|
+
const cookies = [join(profile, "Network", "Cookies"), join(profile, "Cookies")];
|
|
569
571
|
const cli = join(dirname(fileURLToPath(import.meta.url)), "clear-inbox.mjs");
|
|
570
|
-
if (existsSync(
|
|
572
|
+
if (cookies.some((file) => existsSync(file))) {
|
|
571
573
|
add(
|
|
572
574
|
"sweep",
|
|
573
575
|
"ok",
|
|
574
576
|
"清理收件箱用的浏览器配置里有登录痕迹",
|
|
575
|
-
"
|
|
577
|
+
`这只是痕迹,不代表会话还有效;真失效时插件会自己再开一次登录窗口(node "${cli}" --check 能直接问)`,
|
|
576
578
|
);
|
|
577
579
|
} else {
|
|
578
580
|
add(
|
|
579
581
|
"sweep",
|
|
580
582
|
"warn",
|
|
581
583
|
"清理收件箱还没有登录过",
|
|
582
|
-
|
|
584
|
+
`把面板的「消息清理」切到归档,插件会自己弹出登录窗口;命令行也行:node "${cli}" --login`,
|
|
583
585
|
);
|
|
584
586
|
}
|
|
585
587
|
}
|