dsh-inbox-bridge 2.18.1 → 2.18.3

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,9 +1,16 @@
1
+ ## 2.18.3
2
+
3
+ - 登录一次就够:归档结束后让浏览器自己关掉,等它真的退出(Chromium 只在退出时把 cookie 写进磁盘),而不是 1.5 秒后强杀。以前每次运行都丢掉刚登录的会话,于是看起来「才登录过又要登录」。
4
+ - 修掉文档里一句错话:GitHub 的 `user_session` 带约两周有效期,不是会话级 cookie;真正的原因是强杀进程。
5
+ ## 2.18.2
6
+
7
+ - 归档再加一道行级防护:每行都按它自己的链接核对仓库,明确属于别的仓库的行一律不动;一行都认不出来时宁可什么都不归档,也不会把整个账号的收件箱带走。搜索视图的 `repo:` 限定不再是唯一保险。
1
8
  ## 2.18.1
2
9
 
3
10
  - 归档只碰订阅的仓库:按仓库逐个打开 GitHub 的通知搜索视图(`repo:owner/name`),只归档这些视图里的线程。以前它选中整个收件箱,会把账号里其它仓库的通知一起归档。
4
11
  - 没有订阅时不再归档任何东西(`--all` 才动整个收件箱),所以后台轮询不会替别人做决定。
5
12
  - 登录窗口结束后的那次归档也带上同一份订阅。
6
- - 登录现在能留住:GitHub 的会话 cookie 是会话级的,插件在浏览器配置里打开「恢复上次会话」,不再一次运行后就被登出。
13
+ - 登录不再一次运行后就丢:会话写在浏览器配置里,退出时落盘,下次直接可用。
7
14
  - `--check` 与 `doctor` 的登录痕迹改看 `Default/Network/Cookies`(Chromium 96 之后的位置)。
8
15
  ## 2.18.0
9
16
 
@@ -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
 
package/docs/index.json CHANGED
@@ -50,12 +50,12 @@
50
50
  },
51
51
  "versions": [
52
52
  {
53
- "version": "2.18.1",
54
- "publishTimestamp": 1794916042,
53
+ "version": "2.18.3",
54
+ "publishTimestamp": 1794916776,
55
55
  "source": {
56
56
  "type": "git",
57
57
  "url": "https://github.com/c3115644151/dsh-inbox-bridge",
58
- "commit": "0fbc3f3afd5af257321d253c4061165a7ee00ba2"
58
+ "commit": "a927124d858a2b1c23f9a9f2686a0a06560f11ad"
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.18.1",
3
+ "version": "2.18.3",
4
4
  "displayName": "GitHub inbox",
5
5
  "description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
6
6
  "type": "module",
@@ -177,17 +177,58 @@ async function connect(wsUrl) {
177
177
  }
178
178
 
179
179
  /**
180
- * Runs in the page. Selects everything in the inbox and presses Done, then
181
- * reports what happened. Retries the click because the toolbar renders lazily.
180
+ * Runs in the page. Selects the rows that belong to `repo` (everything when
181
+ * `repo` is null) and presses Done, then reports what happened. Retries the
182
+ * click because the toolbar renders lazily.
183
+ *
184
+ * The view is already narrowed by a `repo:` search, but that alone is a thin
185
+ * guarantee: if GitHub ever ignores the qualifier, the page would hand us the
186
+ * whole account and this script would archive it. So each row is also checked
187
+ * against its own links — a row that clearly belongs to another repository is
188
+ * left alone. A row whose repository cannot be read is kept, because the view
189
+ * is the only evidence available at that point.
182
190
  */
183
- const SWEEP = `(async () => {
184
- const rows = () => [...document.querySelectorAll('input[type=checkbox][name="notification_ids[]"]')];
191
+ export const sweepScript = (repo) => `(async () => {
192
+ const boxes = () => [...document.querySelectorAll('input[type=checkbox][name="notification_ids[]"]')];
193
+ const owner = ${JSON.stringify(repo ?? null)};
194
+ const pathOf = (link) => {
195
+ try { return new URL(link.href).pathname; } catch { return ""; }
196
+ };
197
+ const repoPaths = (node) =>
198
+ [...node.querySelectorAll('a[href]')]
199
+ .map(pathOf)
200
+ .filter((path) => /^\\/[^/]+\\/[^/]+\\//.test(path));
201
+ const rowOf = (box) => {
202
+ let node = box;
203
+ let found = null;
204
+ for (let depth = 0; depth < 10 && node; depth += 1) {
205
+ const count = node.querySelectorAll?.('input[type=checkbox][name="notification_ids[]"]').length ?? 0;
206
+ if (count > 1) break;
207
+ if (count === 1 && repoPaths(node).length > 0) found = node;
208
+ node = node.parentElement;
209
+ }
210
+ return found;
211
+ };
212
+ const foreign = (box) => {
213
+ if (!owner) return false;
214
+ const row = rowOf(box);
215
+ if (!row) return false;
216
+ const paths = repoPaths(row);
217
+ if (paths.length === 0) return false;
218
+ return !paths.some((path) => path.startsWith('/' + owner + '/'));
219
+ };
185
220
  const started = Date.now();
186
- const before = rows().length;
221
+ const all = boxes();
222
+ const before = all.length;
187
223
  if (before === 0) {
188
- return { archived: 0, before: 0, after: 0, empty: true };
224
+ return { archived: 0, before: 0, after: 0, skipped: 0, empty: true };
225
+ }
226
+ const mine = all.filter((box) => !foreign(box));
227
+ const skipped = before - mine.length;
228
+ if (mine.length === 0) {
229
+ return { archived: 0, before, after: before, skipped, unscoped: true };
189
230
  }
190
- for (const box of rows()) box.click();
231
+ for (const box of mine) box.click();
191
232
  await new Promise((r) => setTimeout(r, 700));
192
233
  for (let attempt = 0; attempt < 10; attempt += 1) {
193
234
  const done = [...document.querySelectorAll('button')].find((b) => b.textContent.trim() === 'Done');
@@ -199,9 +240,9 @@ const SWEEP = `(async () => {
199
240
  }
200
241
  for (let waited = 0; waited < 30; waited += 1) {
201
242
  await new Promise((r) => setTimeout(r, 300));
202
- if (rows().length === 0) break;
243
+ if (boxes().length === 0) break;
203
244
  }
204
- return { archived: before - rows().length, before, after: rows().length, empty: false, ms: Date.now() - started };
245
+ return { archived: before - boxes().length, before, after: boxes().length, skipped, empty: false, ms: Date.now() - started };
205
246
  })()`;
206
247
 
207
248
  async function main(argv) {
@@ -271,8 +312,28 @@ async function main(argv) {
271
312
  "about:blank",
272
313
  ];
273
314
  const child = spawn(browser, args, { detached: false, stdio: "ignore" });
274
- 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 () => {
275
332
  if (options.keepOpen) return;
333
+ for (let waited = 0; waited < 40; waited += 1) {
334
+ if (await browserGone()) return;
335
+ await sleep(250);
336
+ }
276
337
  try {
277
338
  child.kill();
278
339
  } catch {
@@ -422,13 +483,16 @@ async function main(argv) {
422
483
  await devtools.send("Page.navigate", { url: urlFor(repo) });
423
484
  const view = await waitForList();
424
485
  if (view?.signIn) return await unsorted();
425
- const result = await read(SWEEP);
426
- perRepo.push({ repo, archived: result.archived ?? 0, before: result.before ?? 0 });
486
+ const result = await read(sweepScript(repo));
487
+ perRepo.push({ repo, archived: result.archived ?? 0, before: result.before ?? 0, skipped: result.skipped ?? 0 });
488
+ if (result.unscoped) perRepo[perRepo.length - 1].unscoped = true;
427
489
  }
428
490
  const archived = perRepo.reduce((sum, each) => sum + each.archived, 0);
491
+ const skipped = perRepo.reduce((sum, each) => sum + (each.skipped ?? 0), 0);
429
492
  const summary = {
430
493
  ok: true,
431
494
  archived,
495
+ skipped,
432
496
  repos: perRepo.map((each) => each.repo).filter(Boolean),
433
497
  perRepo,
434
498
  ms: Date.now() - started,
@@ -436,7 +500,11 @@ async function main(argv) {
436
500
  };
437
501
  if (options.json) console.log(JSON.stringify(summary));
438
502
  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`);
503
+ else {
504
+ const guarded = skipped > 0 ? `, left ${skipped} thread(s) of other repositories alone` : "";
505
+ const confused = perRepo.some((each) => each.unscoped) ? "; the page did not name the rows it showed, so nothing was archived" : "";
506
+ console.log(`archived ${archived} thread(s) in ${Math.round(summary.ms / 100) / 10}s${guarded}${confused}`);
507
+ }
440
508
  return 0;
441
509
  } finally {
442
510
  devtools.close();
@@ -455,7 +523,7 @@ async function main(argv) {
455
523
  }
456
524
  await sleep(1500);
457
525
  }
458
- cleanup();
526
+ await cleanup();
459
527
  if (!options.keepOpen) {
460
528
  // A graceful close removes the lock; a kill can leave it behind.
461
529
  try {
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
- import { archiveTargets, inboxUrlFor, parseArgs } from "./clear-inbox.mjs";
3
+ import { archiveTargets, inboxUrlFor, parseArgs, sweepScript } from "./clear-inbox.mjs";
4
4
 
5
5
  test("the sweep archives the repositories the plugin watches, one view each", () => {
6
6
  const plan = archiveTargets({ repos: ["owner/one", "owner/two"] });
@@ -56,4 +56,17 @@ test("--check and --dry-run are separate switches", () => {
56
56
  const both = parseArgs(["--check", "--dry-run"]);
57
57
  assert.equal(both.check, true);
58
58
  assert.equal(both.dryRun, true);
59
+ });
60
+
61
+ test("the page script refuses rows that belong to another repository", () => {
62
+ // The search view is narrowed by `repo:`, but the page script checks each row
63
+ // against its own links too: if GitHub ignored the qualifier, an unfiltered
64
+ // row must never be archived. The guard is generated per repository, so this
65
+ // test keeps it from being removed without a trace.
66
+ const scoped = sweepScript("owner/repo");
67
+ assert.match(scoped, /const owner = "owner\/repo";/u);
68
+ assert.match(scoped, /\.startsWith\('\/' \+ owner \+ '\/'\)/u);
69
+ assert.match(scoped, /unscoped: true/u);
70
+ // `--all` is the only mode that keeps every row.
71
+ assert.match(sweepScript(null), /const owner = null;/u);
59
72
  });