dsh-inbox-bridge 2.18.1 → 2.18.2
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 +3 -0
- package/docs/index.json +3 -3
- package/package.json +1 -1
- package/scripts/clear-inbox.mjs +60 -12
- package/scripts/clear-inbox.test.mjs +14 -1
package/CHANGELOG.md
CHANGED
package/docs/index.json
CHANGED
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
},
|
|
51
51
|
"versions": [
|
|
52
52
|
{
|
|
53
|
-
"version": "2.18.
|
|
54
|
-
"publishTimestamp":
|
|
53
|
+
"version": "2.18.2",
|
|
54
|
+
"publishTimestamp": 1794916295,
|
|
55
55
|
"source": {
|
|
56
56
|
"type": "git",
|
|
57
57
|
"url": "https://github.com/c3115644151/dsh-inbox-bridge",
|
|
58
|
-
"commit": "
|
|
58
|
+
"commit": "3a01898a1cbaa3b043fd674aa6c4ba91c7accd0a"
|
|
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.
|
|
3
|
+
"version": "2.18.2",
|
|
4
4
|
"displayName": "GitHub inbox",
|
|
5
5
|
"description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
|
|
6
6
|
"type": "module",
|
package/scripts/clear-inbox.mjs
CHANGED
|
@@ -177,17 +177,58 @@ async function connect(wsUrl) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
|
-
* Runs in the page. Selects
|
|
181
|
-
* reports what happened. Retries the
|
|
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
|
|
184
|
-
const
|
|
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
|
|
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
|
|
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 (
|
|
243
|
+
if (boxes().length === 0) break;
|
|
203
244
|
}
|
|
204
|
-
return { archived: before -
|
|
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) {
|
|
@@ -422,13 +463,16 @@ async function main(argv) {
|
|
|
422
463
|
await devtools.send("Page.navigate", { url: urlFor(repo) });
|
|
423
464
|
const view = await waitForList();
|
|
424
465
|
if (view?.signIn) return await unsorted();
|
|
425
|
-
const result = await read(
|
|
426
|
-
perRepo.push({ repo, archived: result.archived ?? 0, before: result.before ?? 0 });
|
|
466
|
+
const result = await read(sweepScript(repo));
|
|
467
|
+
perRepo.push({ repo, archived: result.archived ?? 0, before: result.before ?? 0, skipped: result.skipped ?? 0 });
|
|
468
|
+
if (result.unscoped) perRepo[perRepo.length - 1].unscoped = true;
|
|
427
469
|
}
|
|
428
470
|
const archived = perRepo.reduce((sum, each) => sum + each.archived, 0);
|
|
471
|
+
const skipped = perRepo.reduce((sum, each) => sum + (each.skipped ?? 0), 0);
|
|
429
472
|
const summary = {
|
|
430
473
|
ok: true,
|
|
431
474
|
archived,
|
|
475
|
+
skipped,
|
|
432
476
|
repos: perRepo.map((each) => each.repo).filter(Boolean),
|
|
433
477
|
perRepo,
|
|
434
478
|
ms: Date.now() - started,
|
|
@@ -436,7 +480,11 @@ async function main(argv) {
|
|
|
436
480
|
};
|
|
437
481
|
if (options.json) console.log(JSON.stringify(summary));
|
|
438
482
|
else if (summary.empty) console.log("nothing to archive in the repositories you watch");
|
|
439
|
-
else
|
|
483
|
+
else {
|
|
484
|
+
const guarded = skipped > 0 ? `, left ${skipped} thread(s) of other repositories alone` : "";
|
|
485
|
+
const confused = perRepo.some((each) => each.unscoped) ? "; the page did not name the rows it showed, so nothing was archived" : "";
|
|
486
|
+
console.log(`archived ${archived} thread(s) in ${Math.round(summary.ms / 100) / 10}s${guarded}${confused}`);
|
|
487
|
+
}
|
|
440
488
|
return 0;
|
|
441
489
|
} finally {
|
|
442
490
|
devtools.close();
|
|
@@ -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
|
});
|