dsh-inbox-bridge 2.18.2 → 2.19.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,3 +1,12 @@
1
+ ## 2.19.0
2
+
3
+ - 唤醒要先说清「谁负责」:同一个工作区里可以开多个会话,它们看的是同一个仓库,于是「这个仓库的会话」不再是一个确定的答案。现在一个仓库只有一个会话在看时,它就是负责的那个;有多个时,谁都不叫,直到你在面板里指定某一个负责(`primary`)。插件没有资格替你挑谈话对象。
4
+ - 新增第五道门:`wakePlan` 在角色、空闲、两个预算之外,先看负责关系;日志会写 `no wakeup: ambiguous`(多人看同一个仓库)或 `no wakeup: not-primary`。
5
+ - `primary` 与其它设置一样会被校验:键必须是 `owner/name`,值必须是会话 id,写错直接报出来而不是悄悄失效。
6
+ ## 2.18.3
7
+
8
+ - 登录一次就够:归档结束后让浏览器自己关掉,等它真的退出(Chromium 只在退出时把 cookie 写进磁盘),而不是 1.5 秒后强杀。以前每次运行都丢掉刚登录的会话,于是看起来「才登录过又要登录」。
9
+ - 修掉文档里一句错话:GitHub 的 `user_session` 带约两周有效期,不是会话级 cookie;真正的原因是强杀进程。
1
10
  ## 2.18.2
2
11
 
3
12
  - 归档再加一道行级防护:每行都按它自己的链接核对仓库,明确属于别的仓库的行一律不动;一行都认不出来时宁可什么都不归档,也不会把整个账号的收件箱带走。搜索视图的 `repo:` 限定不再是唯一保险。
@@ -6,7 +15,7 @@
6
15
  - 归档只碰订阅的仓库:按仓库逐个打开 GitHub 的通知搜索视图(`repo:owner/name`),只归档这些视图里的线程。以前它选中整个收件箱,会把账号里其它仓库的通知一起归档。
7
16
  - 没有订阅时不再归档任何东西(`--all` 才动整个收件箱),所以后台轮询不会替别人做决定。
8
17
  - 登录窗口结束后的那次归档也带上同一份订阅。
9
- - 登录现在能留住:GitHub 的会话 cookie 是会话级的,插件在浏览器配置里打开「恢复上次会话」,不再一次运行后就被登出。
18
+ - 登录不再一次运行后就丢:会话写在浏览器配置里,退出时落盘,下次直接可用。
10
19
  - `--check` 与 `doctor` 的登录痕迹改看 `Default/Network/Cookies`(Chromium 96 之后的位置)。
11
20
  ## 2.18.0
12
21
 
package/README.en.md CHANGED
@@ -27,7 +27,7 @@ That is also why it only reads: its job is to make the agent aware. The work hap
27
27
  - **It reads repositories, not the notification inbox.** GitHub's notification inbox pushes per account and cannot tell one session or repository from another; querying repository state directly keeps two repositories on the same account apart.
28
28
  - **Polling follows turns.** Once when a session starts, every minute while a turn runs, once when it ends; an idle session makes no request. Only with `delivery: wakeup` does it also read on that interval while idle — without that it could never wake you while you are away.
29
29
  - **It also watches security and merge state.** Open Dependabot and code-scanning alerts, and a pull request of yours that conflicts with the base branch or is behind it, matter as much as a red check.
30
- - **It goes into the context, and opens a turn only when it has to.** By default a notice arrives at the next safe injection point and does not interrupt the tool loop; with `delivery: wakeup` it opens a turn only for a listed `wakeOn` role, with the session idle for 15 minutes, at most 3 times in a row per session, and at most 2 times an hour — anything else keeps queueing. A notice is marked `delivered`, and unhandled events come back once after six hours.
30
+ - **It goes into the context, and opens a turn only when it has to.** By default a notice arrives at the next safe injection point and does not interrupt the tool loop; with `delivery: wakeup` it opens a turn only for a listed `wakeOn` role, in the one session responsible for that repository (or the one you named), idle for 15 minutes, at most 3 times in a row per session, and at most 2 times an hour — anything else keeps queueing. A notice is marked `delivered`, and unhandled events come back once after six hours.
31
31
 
32
32
  ## What you will see
33
33
 
@@ -100,7 +100,7 @@ Full configuration, CLI and state files: [configuration](docs/configuration.md).
100
100
  ## Boundaries
101
101
 
102
102
  - **Read-only.** It does not merge, comment, or change anything.
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.
103
+ - **No turn by default.** Only `delivery: wakeup` with a matching `wakeOn` role, one responsible session for that repository, 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
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`.
106
106
  - **State is local.** It lives under `.work/` in the working directory and is not synced across machines.
package/README.md CHANGED
@@ -27,7 +27,7 @@
27
27
  - **只看仓库,不看通知箱。** GitHub 的通知箱(`/notifications`)按账号推送,无法区分是哪个会话、哪个仓库;这里直接查仓库状态,因此同一个账号下的两个仓库互不干扰。
28
28
  - **轮询跟随回合。** 会话开始时一次、进行中每 1 分钟一次、结束时一次,空闲会话不发请求;开启 `delivery: wakeup` 后空闲时也按同一间隔读一次,否则它没机会在你不在时叫醒你。
29
29
  - **也看安全与合并状态。** 开着的 Dependabot 告警、code scanning 告警,以及我这些 PR 与基分支的冲突或落后,和 CI 失败一样是要紧的事。
30
- - **送进上下文,必要时才开一轮。** 默认只在这一轮的下一次安全注入点进入会话,不打断工具循环;开启 `delivery: wakeup` 后,只有命中 `wakeOn` 的角色、会话空闲满 15 分钟、每会话连续不超过 3 次、每小时不超过 2 次时才主动开一轮,其余情况仍然排队。送达后标为 `delivered`,未处理的 6 小时后重新提醒一次。
30
+ - **送进上下文,必要时才开一轮。** 默认只在这一轮的下一次安全注入点进入会话,不打断工具循环;开启 `delivery: wakeup` 后,只有命中 `wakeOn` 的角色、这个仓库只有它一个会话在看(或被你指定负责)、会话空闲满 15 分钟、每会话连续不超过 3 次、每小时不超过 2 次时才主动开一轮,其余情况仍然排队。送达后标为 `delivered`,未处理的 6 小时后重新提醒一次。
31
31
 
32
32
  ## 你会看到什么
33
33
 
@@ -100,7 +100,7 @@ dsh plugin add dsh-inbox-bridge
100
100
  ## 边界
101
101
 
102
102
  - **只读。** 不合并、不评论、不修改仓库。
103
- - **默认不主动开启对话。** 只有显式设置 `delivery: wakeup` 且命中 `wakeOn`、会话足够空闲、两个预算都还有余额时才会;任何一道门不过,就退回只排队。
103
+ - **默认不主动开启对话。** 只有显式设置 `delivery: wakeup` 且命中 `wakeOn`、这个仓库只由一个会话负责、会话足够空闲、两个预算都还有余额时才会;任何一道门不过,就退回只排队。
104
104
  - **Done 归档依赖一次浏览器登录,但不用你敲命令。** GitHub 没有归档 API,`scripts/clear-inbox.mjs` 通过本机浏览器(Edge / Chrome / Chromium)完成。把「消息清理」切到归档,插件会自己弹出登录窗口;会话失效时会再弹一次。
105
105
  - **归档只碰你订阅的仓库。** 它按仓库逐个打开 GitHub 的通知搜索视图(`repo:owner/name`),只归档这些视图里的线程;没有订阅就什么都不归档。整个收件箱要显式 `--all` 才会动。
106
106
  - **状态在本机。** 存放在工作目录的 `.work/` 下,不跨机器同步。
package/docs/DETAIL.md CHANGED
@@ -39,6 +39,6 @@ Then give it a working directory (`cwd`); the repository and the identity come f
39
39
  ## Boundaries
40
40
 
41
41
  - Read-only: no merging, commenting or changing repositories.
42
- - 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.
42
+ - No turn by default; only `delivery: wakeup` with a matching `wakeOn` role, one responsible session for that repository, enough idle time, and room in both budgets may start one; any gate that fails falls back to queueing.
43
43
  - Archiving to Done needs one browser sign-in (GitHub has no archive API).
44
44
  - State is local, under `<cwd>/.work/`, and is not synced across machines.
package/docs/DETAIL.zh.md CHANGED
@@ -39,6 +39,6 @@ dsh plugin add ./dsh-inbox-bridge
39
39
  ## 边界
40
40
 
41
41
  - 只读:不合并、不评论、不修改仓库。
42
- - 默认不主动开启对话;只有 `delivery: wakeup` 命中 `wakeOn`、会话足够空闲、两个预算都还有余额时才会,任何一道门不过就退回只排队。
42
+ - 默认不主动开启对话;只有 `delivery: wakeup` 命中 `wakeOn`、这个仓库由某个会话负责、会话足够空闲、两个预算都还有余额时才会,任何一道门不过就退回只排队。
43
43
  - 归档到 Done 依赖一次浏览器登录(GitHub 没有归档 API)。
44
44
  - 状态保存在本机 `<cwd>/.work/` 下,不跨机器同步。
@@ -44,7 +44,7 @@ GitHub 的 Done 只有网页端点,所以归档要用插件自己的浏览器
44
44
 
45
45
  窗口是独立进程,宿主的轮询不会被它挡住。命令行里 `scripts/clear-inbox.mjs --check` 只回答「登录了没」(没登录时退出码 2),`--login` 打开窗口等你登录,`--dry-run` 只报数量,`--repo owner/name`(可重复,插件通过 `INBOX_REPO` 传)指定范围,`--all` 才是整个收件箱。
46
46
 
47
- 登录状态能活下来,靠的是插件在浏览器配置里打开「恢复上次会话」——GitHub 的会话 cookie 本身是会话级的,Chromium 默认在关闭时丢掉它。
47
+ 登录状态能活下来,靠的是插件让浏览器自己关掉:Chromium 在退出时才把 cookie 写进磁盘,强行结束进程会丢掉刚登录的会话——这正是「刚登录过又让我登录」的原因。GitHub 的 `user_session` 本身带约两周的有效期,每次归档都会续上。
48
48
 
49
49
  ## 全部配置项
50
50
 
@@ -60,7 +60,7 @@ GitHub 的 Done 只有网页端点,所以归档要用插件自己的浏览器
60
60
  | `resurfaceMs` | `21600000`(6 小时) | 标了 delivered 但没处理的,多久后再提一次 |
61
61
  | `offlineReminderMs` | `43200000`(12 小时) | 工作区连不上仓库时,最多多久提醒一次 |
62
62
  | `injectWhileRunning` | `false` | 允许打断正在跑的工具循环;默认只在回合边界注入 |
63
- | `delivery` | `"quiet"` | `quiet` 只排队;`wakeup` 还会替你开一轮(受下面四道门约束) |
63
+ | `delivery` | `"quiet"` | `quiet` 只排队;`wakeup` 还会替你开一轮(受下面五道门约束) |
64
64
  | `wakeOn` | `[]` | 允许唤醒的角色白名单;空 = 永不唤醒。若设了非空值,`delivery` 必须是 `wakeup` |
65
65
  | `wakeAfterIdleMs` | `900000`(15 分钟) | 会话静默多久后才允许唤醒 |
66
66
  | `wakesPerHour` | `2` | 滚动一小时内最多唤醒几次;0 = 关闭 |
@@ -93,6 +93,8 @@ identity:
93
93
 
94
94
  区别在能看到什么:`user` 能看到账号的 `/notifications`(别人把事推给你),`app` 没有用户收件箱,只读仓库状态(PR、检查、评审请求、issue、评论)。两种都能判断「这件事跟我有关吗」,因为判断依据是仓库里的关系,不是通知流。
95
95
 
96
+ 谁来接这一轮:一个仓库只有一个会话在看时,那个会话就是负责的;同一仓库被多个会话看着(同一工作区开多个会话就会这样)时,谁都不叫,直到你在面板里把某个会话指定为负责——插件没有资格替你挑谈话对象。
97
+
96
98
  `roles` 与事件里的角色一致:`author`(你提交的)、`reviewer`(请你评审)、`assignee`(派给你的)、`mention`(@你)、`ci`(默认分支)。`wakeOn` 用同一套名字。
97
99
 
98
100
  ## 命令行
@@ -33,7 +33,7 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
33
33
  4. 队列里已有记录的 key 不重复投递;已经投出去但没有人收口的,6 小时后重提**一次**,再之后就当作已经说过了。
34
34
  5. 上一次轮询能报出、这一次报不出的 key,说明这条事实已经不再成立(检查变绿、PR 合了、issue 关了),直接收口——队列里只留「此刻仍然成立」的事。
35
35
  6. 按会话分组:会话自己的仓库 + 自己的角色都匹配,才进它那份。
36
- 7. 投递:`quiet` 时注入给空闲的会话、等它下一轮;`wakeup` 时先过四道门。
36
+ 7. 投递:`quiet` 时注入给空闲的会话、等它下一轮;`wakeup` 时先过五道门。
37
37
  8. 只把**真正投出去**的 key 标 delivered。没投出去的下次还有机会,不会被误标。
38
38
  9. 把这些线程标为已读(`clear`,默认只清订阅的仓库;整个账号不在范围内)。GitHub 没有「完成」的公开接口,所以清掉的是未读角标,收件箱里的历史还在——在你自己的界面上一切照旧可查。
39
39
  10. 如果配了 `sweep`,在**这一轮真的抓到东西**时顺手把它们归档进 Done(`scripts/clear-inbox.mjs` 用一次浏览器完成,约 3–5 秒)。它按仓库逐个打开 GitHub 的通知搜索视图(`repo:owner/name`),只归档订阅的这些视图里的线程;没有订阅就一条也不归档(整个收件箱要显式 `--all`)。没抓到就什么也不做,空回合不花这笔钱。
@@ -82,9 +82,10 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
82
82
 
83
83
  ## 唤醒(默认关闭)
84
84
 
85
- `delivery: quiet` 时插件永远不替你开一轮,只排队。改成 `wakeup` 后,要同时满足四道门才会开一轮:
85
+ `delivery: quiet` 时插件永远不替你开一轮,只排队。改成 `wakeup` 后,要同时满足五道门才会开一轮:
86
86
 
87
87
  1. `wakeOn` 列了这个角色(默认空 = 永不);
88
+ 2. 这个仓库只有一个会话在看,或者被指定的那个会话正是它(同一仓库多个会话时默认谁都不叫);
88
89
  2. 会话已经静默 `wakeAfterIdleMs`(默认 15 分钟)——所以这个模式在空闲时也按 `intervalMs` 取数,否则永远等不到这一刻;
89
90
  3. 这个会话自你上次发言起被唤醒不足 `maxConsecutiveWakes` 次;
90
91
  4. 滚动一小时内总唤醒数没超过 `wakesPerHour`(默认 2)。
package/docs/index.json CHANGED
@@ -50,12 +50,12 @@
50
50
  },
51
51
  "versions": [
52
52
  {
53
- "version": "2.18.2",
54
- "publishTimestamp": 1794916295,
53
+ "version": "2.19.0",
54
+ "publishTimestamp": 1794917805,
55
55
  "source": {
56
56
  "type": "git",
57
57
  "url": "https://github.com/c3115644151/dsh-inbox-bridge",
58
- "commit": "3a01898a1cbaa3b043fd674aa6c4ba91c7accd0a"
58
+ "commit": "544357cc92e222ae02858bdd560bf124e18961ad"
59
59
  },
60
60
  "engines": {
61
61
  "dsh": ">=0.1.0"
package/index.js CHANGED
@@ -115,6 +115,17 @@ export function preferenceNext(current = {}, action = "", value = "", options =
115
115
  }
116
116
  return next;
117
117
  }
118
+ if (action === "primary") {
119
+ // Who may be woken for this repository. An empty value releases the claim.
120
+ if (!sessionId) return null;
121
+ const repo = value ? repoFromInput(value) : sessionRepo;
122
+ if (!repo) return null;
123
+ const primary = { ...(next.primary ?? {}) };
124
+ if (value) primary[repo] = sessionId;
125
+ else delete primary[repo];
126
+ next.primary = primary;
127
+ return next;
128
+ }
118
129
  return null;
119
130
  }
120
131
 
@@ -228,6 +239,13 @@ const DEFAULTS = Object.freeze({
228
239
  * leaves the inbox alone. GitHub has no "done" API, so this is read, not done.
229
240
  */
230
241
  clear: "repo",
242
+ /**
243
+ * Which session is responsible for opening a turn on a repository:
244
+ * `{ "owner/name": "<session id>" }`. Without a claim, a repository whose
245
+ * events reach more than one session wakes nobody — the plugin may not choose
246
+ * which conversation starts working.
247
+ */
248
+ primary: {},
231
249
  poll: { command: process.execPath, args: [CLI, "poll"] },
232
250
  ack: { command: process.execPath, args: [CLI, "ack"] },
233
251
  });
@@ -601,7 +619,13 @@ export function apply(ctx, config) {
601
619
  );
602
620
  return;
603
621
  }
604
- const wake = wakePlan(batches, options, { streak: wakeStreak, lastActive, wakes, now });
622
+ const wake = wakePlan(batches, options, {
623
+ streak: wakeStreak,
624
+ lastActive,
625
+ wakes,
626
+ now,
627
+ primary: prefs.primary ?? {},
628
+ });
605
629
  if (!wake.agent && wake.considered > 0) log(`no wakeup: ${wake.why}`);
606
630
  const waking = wake.agent ? new Set([wake.agent]) : new Set();
607
631
  const deliveredKeys = new Set();
@@ -978,10 +1002,25 @@ export function wakePlan(batches, options, state = {}) {
978
1002
  const streak = state.streak ?? new Map();
979
1003
  const lastActive = state.lastActive ?? new Map();
980
1004
  const wakes = state.wakes ?? [];
1005
+ const primary = state.primary ?? {};
981
1006
  const perHour = options?.wakesPerHour ?? DEFAULTS.wakesPerHour;
982
1007
  const cap = options?.maxConsecutiveWakes ?? DEFAULTS.maxConsecutiveWakes;
983
1008
  const idleMs = options?.wakeAfterIdleMs ?? DEFAULTS.wakeAfterIdleMs;
984
1009
 
1010
+ // Opening a turn is expensive and public: whoever gets it suddenly starts
1011
+ // working. Several sessions can share one workspace, and then they all watch
1012
+ // the same repository, so "the session on this repository" is not an answer.
1013
+ // A repository therefore wakes its responsible session — claimed in the page —
1014
+ // and stays silent while more than one session watches it without a claim.
1015
+ const watchers = new Map();
1016
+ for (const [agent, events] of batches ?? []) {
1017
+ for (const event of events) {
1018
+ const repo = event.repo ?? "";
1019
+ if (!watchers.has(repo)) watchers.set(repo, new Set());
1020
+ watchers.get(repo).add(agent);
1021
+ }
1022
+ }
1023
+
985
1024
  const recentWakes = wakes.filter((at) => now - at < 60 * 60 * 1000).length;
986
1025
  let considered = 0;
987
1026
  let why = "no-match";
@@ -990,6 +1029,17 @@ export function wakePlan(batches, options, state = {}) {
990
1029
  const role = event.role ?? "any";
991
1030
  if (!wakeOn.includes(role)) continue;
992
1031
  considered += 1;
1032
+ const repo = event.repo ?? "";
1033
+ const owner = primary[repo] ?? null;
1034
+ const key = keyOf(agent);
1035
+ if (owner && key !== owner) {
1036
+ why = "not-primary";
1037
+ continue;
1038
+ }
1039
+ if (!owner && (watchers.get(repo)?.size ?? 0) > 1) {
1040
+ why = "ambiguous";
1041
+ continue;
1042
+ }
993
1043
  if (recentWakes >= perHour) {
994
1044
  why = "hourly-budget";
995
1045
  continue;
@@ -1171,10 +1221,25 @@ export function mergeConfig(config) {
1171
1221
  `inbox-bridge: \`signInCooldownMs\` must be a non-negative integer, got ${JSON.stringify(signInCooldownMs)}`,
1172
1222
  );
1173
1223
  }
1224
+ // Which session opens a turn for a repository. Written by the page, but it is
1225
+ // configuration like any other: a typo here would silently silence wakeups.
1226
+ const primary = given.primary ?? DEFAULTS.primary;
1227
+ if (primary === null || typeof primary !== "object" || Array.isArray(primary)) {
1228
+ throw new Error(`inbox-bridge: \`primary\` must be { "owner/name": sessionId }, got ${JSON.stringify(primary)}`);
1229
+ }
1230
+ for (const [repo, session] of Object.entries(primary)) {
1231
+ if (!/^[\w.-]+\/[\w.-]+$/u.test(repo)) {
1232
+ throw new Error(`inbox-bridge: \`primary\` has a key that is not owner/name: ${JSON.stringify(repo)}`);
1233
+ }
1234
+ if (typeof session !== "string" || session.length === 0) {
1235
+ throw new Error(`inbox-bridge: \`primary.${repo}\` must be a session id, got ${JSON.stringify(session)}`);
1236
+ }
1237
+ }
1174
1238
  return {
1175
1239
  ...DEFAULTS,
1176
1240
  ...given,
1177
1241
  signInCooldownMs,
1242
+ primary,
1178
1243
  repo,
1179
1244
  repos: watched,
1180
1245
  delivery,
@@ -1378,7 +1443,8 @@ function wakeNotice(options, delivery) {
1378
1443
  const idleMinutes = Math.max(1, Math.round((options.wakeAfterIdleMs ?? DEFAULTS.wakeAfterIdleMs) / 60_000));
1379
1444
  const perHour = options.wakesPerHour ?? DEFAULTS.wakesPerHour;
1380
1445
  return (
1381
- `插件可能替你开一轮:仅限 ${wakeOn.join("/")} 角色,会话空闲满 ${idleMinutes} 分钟后,` +
1446
+ `插件可能替你开一轮:仅限 ${wakeOn.join("/")} 角色,且只有被指定负责该仓库的会话;` +
1447
+ `会话空闲满 ${idleMinutes} 分钟后,` +
1382
1448
  `每小时最多 ${perHour} 次(另有每个会话 ${options.maxConsecutiveWakes ?? DEFAULTS.maxConsecutiveWakes} 次的连续上限)。`
1383
1449
  );
1384
1450
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-inbox-bridge",
3
- "version": "2.18.2",
3
+ "version": "2.19.0",
4
4
  "displayName": "GitHub inbox",
5
5
  "description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
6
6
  "type": "module",
@@ -312,8 +312,28 @@ async function main(argv) {
312
312
  "about:blank",
313
313
  ];
314
314
  const child = spawn(browser, args, { detached: false, stdio: "ignore" });
315
- const cleanup = () => {
315
+ // Chromium writes the cookie database on the way out. Killing it mid-run loses
316
+ // the GitHub session, which is what made every archive look like it had been
317
+ // signed out again. So the browser is asked to close and given time to finish;
318
+ // only a browser that refuses to go is killed, and that case is reported.
319
+ const stillRunning = () => child.exitCode === null && child.signalCode === null;
320
+ // The child process is not the browser itself — Edge/Chrome hand off to a new
321
+ // process — so the honest signal that the browser is gone is the DevTools
322
+ // endpoint no longer answering.
323
+ const browserGone = async () => {
324
+ try {
325
+ await fetch(`${base}/json/version`, { signal: AbortSignal.timeout(1000) });
326
+ return false;
327
+ } catch {
328
+ return true;
329
+ }
330
+ };
331
+ const cleanup = async () => {
316
332
  if (options.keepOpen) return;
333
+ for (let waited = 0; waited < 40; waited += 1) {
334
+ if (await browserGone()) return;
335
+ await sleep(250);
336
+ }
317
337
  try {
318
338
  child.kill();
319
339
  } catch {
@@ -503,7 +523,7 @@ async function main(argv) {
503
523
  }
504
524
  await sleep(1500);
505
525
  }
506
- cleanup();
526
+ await cleanup();
507
527
  if (!options.keepOpen) {
508
528
  // A graceful close removes the lock; a kill can leave it behind.
509
529
  try {