dsh-inbox-bridge 2.19.2 → 2.20.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 +11 -0
- package/README.en.md +3 -2
- package/README.md +3 -2
- package/client.js +105 -6
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +1 -1
- package/docs/configuration.md +3 -2
- package/docs/how-it-works.md +5 -1
- package/docs/index.json +3 -3
- package/index.js +113 -8
- package/package.json +1 -1
- package/scripts/clear-inbox.mjs +9 -1
- package/scripts/github-inbox.mjs +1484 -1386
- package/scripts/github-inbox.test.mjs +122 -48
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## 2.20.0
|
|
2
|
+
|
|
3
|
+
- **谁来接这一轮。** 同一仓库有多个会话在看时,谁都不唤醒,直到你在面板上指定负责的那个;只剩一个会话时它自动负责。判定放在唤醒的五道门里,测试覆盖「两个会话谁都没被叫」与「指定之后只叫指定的那个」。
|
|
4
|
+
- **节奏可以直接调。** 面板上的「空闲多久」(1 / 5 / 15 分钟)与「每小时次数」(1 / 2 / 4)写进覆盖层,不必改插件配置。
|
|
5
|
+
- **定时任务说得清自己。** 由 `schedule` 触发的运行失败时标为 `[Scheduled]`,恢复时同样标为定时任务,不再和「最后一次推送失败」混成一件事。
|
|
6
|
+
- **评审意见本身成为事实。** 我自己 PR 上别人写的评审评论会被报出来(文件:行号 + 首行);推了新提交、评论被代码回答之后它自动收口——GitHub 的评论没有「完成」状态,代码就是唯一的收口。
|
|
7
|
+
- **日志里的话要对得上。** 轮询间隔按整分钟或秒如实说(90 000 ms 是「90 秒」,不再是「2 分钟」);`sweep --json` 回答 `ok: true` 时即使进程退出码非零也按成功记,不再误报 `sweep failed`。
|
|
8
|
+
## 2.19.3
|
|
9
|
+
|
|
10
|
+
- 唤醒只差「会话还不够空闲」这一步时,事件不再被注入掉,而是继续留在队列里等空闲窗口。之前的顺序是:此刻不满足唤醒条件,就把它塞进下一轮对话——于是那条消息被用掉了,唤醒永远等不到它。现在只有真的叫不动(角色不对、多人看同一个仓库、预算用完)才退回注入,纯粹的「再等一会儿」会把事件留给它本来要开的那一轮。
|
|
11
|
+
- 回归测试:`a wakeup that is not idle yet holds the event instead of spending it`(关掉这一条判定后立刻红)。
|
|
1
12
|
## 2.19.2
|
|
2
13
|
|
|
3
14
|
- 被「留下」的事件现在会先记进队列(`attempts: 0` 表示记下来了但还没告诉任何人),下一次轮询即使来源已经不再报它,也会把它重新端上来。之前 issue 与评论这类只报一次的事实,在「所有会话都正忙」的那一轮被留下之后就永远消失了——唤醒因此永远等不到它要等的那条消息。
|
package/README.en.md
CHANGED
|
@@ -27,6 +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
|
+
- **The run that happens at night counts too.** A scheduled workflow that fails says it was scheduled, instead of reading as the last push failing; a review comment on your own pull request is reported as itself, and a push that answers it closes it.
|
|
30
31
|
- **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
32
|
|
|
32
33
|
## What you will see
|
|
@@ -39,7 +40,7 @@ At the top of a turn:
|
|
|
39
40
|
>
|
|
40
41
|
> Act only where it affects the current work; when done, run `node "...\dsh-inbox-bridge\scripts\inbox-bridge.mjs" ack --done -- <key>`.
|
|
41
42
|
|
|
42
|
-
`[Dependabot]` is an open dependency advisory
|
|
43
|
+
`[Dependabot]` is an open dependency advisory, `[Code scanning]` an open code-scanning alert, `[Scheduled]` a scheduled run that failed, and `[Review]` a review comment on your own pull request (with file and line). The rest of the bracket states the relation to that identity: `reviewer` means it waits for your review, `author` means you opened it, `assignee` means it is assigned to you, `mention` means a comment mentions you. Run the `ack` command when you are done; an unacknowledged event is repeated after six hours rather than piling up.
|
|
43
44
|
|
|
44
45
|
## The panel
|
|
45
46
|
|
|
@@ -47,7 +48,7 @@ The status row under the composer carries a chip: when something is waiting, a b
|
|
|
47
48
|
|
|
48
49
|
- the events: role, repository, title (link), time;
|
|
49
50
|
- the identity and the last poll;
|
|
50
|
-
-
|
|
51
|
+
- four controls: delivery (queue only / may wake), who takes it (when several sessions watch the same repository, say which one may be woken; a lone watcher owns it by itself), the rhythm (how idle is idle: 1 / 5 / 15 minutes; wakes per hour: 1 / 2 / 4), message clearing (off / mark read / archive to Done — one choice), and which repositories this session subscribes to (paste a repository link or type `owner/name`; one list per session).
|
|
51
52
|
|
|
52
53
|
Each control explains itself on hover. Changes apply immediately and are stored in `<cwd>/.work/inbox-bridge/prefs.json`; they do not rewrite the DSH plugin configuration, and a reset returns to the configured values. The panel is per session: switching sessions shows that session's repositories, and says so plainly when they are not subscribed.
|
|
53
54
|
|
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
- **只看仓库,不看通知箱。** GitHub 的通知箱(`/notifications`)按账号推送,无法区分是哪个会话、哪个仓库;这里直接查仓库状态,因此同一个账号下的两个仓库互不干扰。
|
|
28
28
|
- **轮询跟随回合。** 会话开始时一次、进行中每 1 分钟一次、结束时一次,空闲会话不发请求;开启 `delivery: wakeup` 后空闲时也按同一间隔读一次,否则它没机会在你不在时叫醒你。
|
|
29
29
|
- **也看安全与合并状态。** 开着的 Dependabot 告警、code scanning 告警,以及我这些 PR 与基分支的冲突或落后,和 CI 失败一样是要紧的事。
|
|
30
|
+
- **夜里跑的那次也算。** 定时工作流(`schedule`)失败时标明是定时任务,不与「最后一次推送失败」混在一起;我自己的 PR 收到评审意见时把那条意见本身报出来,推了新提交、意见被代码回答之后自然收口。
|
|
30
31
|
- **送进上下文,必要时才开一轮。** 默认只在这一轮的下一次安全注入点进入会话,不打断工具循环;开启 `delivery: wakeup` 后,只有命中 `wakeOn` 的角色、这个仓库只有它一个会话在看(或被你指定负责)、会话空闲满 15 分钟、每会话连续不超过 3 次、每小时不超过 2 次时才主动开一轮,其余情况仍然排队。送达后标为 `delivered`,未处理的 6 小时后重新提醒一次。
|
|
31
32
|
|
|
32
33
|
## 你会看到什么
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
>
|
|
40
41
|
> 只在它影响当前工作时处理;处理完运行 `node "...\dsh-inbox-bridge\scripts\inbox-bridge.mjs" ack --done -- <key>` 标记完成。
|
|
41
42
|
|
|
42
|
-
`[Dependabot]` 表示一条开着的依赖告警,`[Code scanning]`
|
|
43
|
+
`[Dependabot]` 表示一条开着的依赖告警,`[Code scanning]` 表示一条开着的代码告警,`[Scheduled]` 表示定时任务跑了并失败,`[Review]` 表示你自己的 PR 收到了评审意见(后面跟着文件:行号)。方括号里其余部分是该事件与该身份的关系:`reviewer` 表示你是评审人,`author` 表示你是作者,`assignee` 表示指派给你,`mention` 表示评论中提到你。处理完执行提示里的 `ack` 命令;未 ack 的事件在 6 小时后重新提示,不会重复累积。
|
|
43
44
|
|
|
44
45
|
## 界面
|
|
45
46
|
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
|
|
48
49
|
- 事件列表:角色、仓库、标题(可点开)、时间。
|
|
49
50
|
- 身份、上次轮询时间。
|
|
50
|
-
-
|
|
51
|
+
- 四组开关:提醒方式(仅注入 / 主动唤醒)、谁来接(同一仓库有多个会话在看时,指定由哪个会话接受唤醒;只有一个时它自动负责)、节奏(空闲多久算空闲:1 / 5 / 15 分钟;每小时最多几次:1 / 2 / 4)、消息清理(关闭 / 已读 / 归档,一档三态)、订阅仓库(粘贴仓库链接或写 `owner/name` 添加,每个会话各有一份)。
|
|
51
52
|
|
|
52
53
|
每个按钮的悬停提示写明了它的作用。改动立即生效,记录在 `<cwd>/.work/inbox-bridge/prefs.json`,不修改 DSH 的插件配置;重置后回到配置里的值。面板按会话取数:切换会话显示该会话订阅的仓库;仓库未订阅时直接说明。
|
|
53
54
|
|
package/client.js
CHANGED
|
@@ -110,7 +110,7 @@ window.__ModuleLoader__.load({
|
|
|
110
110
|
none: "未配置仓库",
|
|
111
111
|
open: "打开收件箱",
|
|
112
112
|
more: (n) => `还有 ${n} 条`,
|
|
113
|
-
kinds: { Dependabot: "依赖告警", "Code scanning": "代码告警" },
|
|
113
|
+
kinds: { Dependabot: "依赖告警", "Code scanning": "代码告警", Scheduled: "定时任务", Review: "评审意见" },
|
|
114
114
|
roles: { author: "作者", reviewer: "评审", assignee: "指派", mention: "提及", ci: "CI", any: "" },
|
|
115
115
|
ago: { now: "刚刚", minutes: (n) => `${n} 分钟前`, hours: (n) => `${n} 小时前`, days: (n) => `${n} 天前` },
|
|
116
116
|
pick: {
|
|
@@ -132,6 +132,16 @@ window.__ModuleLoader__.load({
|
|
|
132
132
|
signInWaiting: "已打开登录窗口,登录后自动生效。",
|
|
133
133
|
signInOpen: "打开登录窗口",
|
|
134
134
|
signInTip: "在插件自己的浏览器配置里登录一次;之后归档会自动运行,失效时会再打开这个窗口。",
|
|
135
|
+
owner: "谁来接",
|
|
136
|
+
ownerTip: "这个仓库的唤醒落到哪个会话。多个会话在看同一仓库时,没指定就不会叫任何人。",
|
|
137
|
+
ownerReleaseTip: "再点一次取消指定",
|
|
138
|
+
idle: "空闲多久",
|
|
139
|
+
idleTip: "会话安静满这么长时间,才允许唤醒;否则只把事件留下等下一轮。",
|
|
140
|
+
minute1: "1 分钟",
|
|
141
|
+
minute5: "5 分钟",
|
|
142
|
+
minute15: "15 分钟",
|
|
143
|
+
budget: "每小时",
|
|
144
|
+
budgetTip: "这个实例每小时最多唤醒几次,用完后只排队。",
|
|
135
145
|
subscribe: "订阅仓库",
|
|
136
146
|
subscribeTip: "此会话关注的 GitHub 仓库;事件只按这里的仓库投递。",
|
|
137
147
|
typeRepo: "owner/repo 或链接",
|
|
@@ -166,7 +176,7 @@ window.__ModuleLoader__.load({
|
|
|
166
176
|
none: "no repositories configured",
|
|
167
177
|
open: "open the inbox",
|
|
168
178
|
more: (n) => `${n} more`,
|
|
169
|
-
kinds: { Dependabot: "Dependabot", "Code scanning": "Code scan" },
|
|
179
|
+
kinds: { Dependabot: "Dependabot", "Code scanning": "Code scan", Scheduled: "scheduled", Review: "review" },
|
|
170
180
|
roles: { author: "author", reviewer: "reviewer", assignee: "assignee", mention: "mention", ci: "CI", any: "" },
|
|
171
181
|
ago: { now: "just now", minutes: (n) => `${n}m ago`, hours: (n) => `${n}h ago`, days: (n) => `${n}d ago` },
|
|
172
182
|
pick: {
|
|
@@ -188,6 +198,16 @@ window.__ModuleLoader__.load({
|
|
|
188
198
|
signInWaiting: "The sign-in window is open; archiving resumes when you finish.",
|
|
189
199
|
signInOpen: "open sign-in",
|
|
190
200
|
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.",
|
|
201
|
+
owner: "who takes it",
|
|
202
|
+
ownerTip: "Which session a wakeup for this repository reaches. With several sessions watching one repository, nobody is woken until you name one.",
|
|
203
|
+
ownerReleaseTip: "click again to clear",
|
|
204
|
+
idle: "quiet for",
|
|
205
|
+
idleTip: "A session must be this quiet before a wakeup may open a turn; otherwise the event waits for a later poll.",
|
|
206
|
+
minute1: "1 min",
|
|
207
|
+
minute5: "5 min",
|
|
208
|
+
minute15: "15 min",
|
|
209
|
+
budget: "per hour",
|
|
210
|
+
budgetTip: "How many wakeups this instance may spend each hour; past that, events only queue.",
|
|
191
211
|
subscribe: "repositories",
|
|
192
212
|
subscribeTip: "The repositories this session follows; events are delivered only for them.",
|
|
193
213
|
typeRepo: "owner/repo or link",
|
|
@@ -442,6 +462,14 @@ window.__ModuleLoader__.load({
|
|
|
442
462
|
textOverflow: "ellipsis",
|
|
443
463
|
whiteSpace: "nowrap",
|
|
444
464
|
},
|
|
465
|
+
ownerList: {
|
|
466
|
+
display: "flex",
|
|
467
|
+
alignItems: "center",
|
|
468
|
+
flexWrap: "wrap",
|
|
469
|
+
gap: "4px",
|
|
470
|
+
minWidth: 0,
|
|
471
|
+
justifyContent: "flex-end",
|
|
472
|
+
},
|
|
445
473
|
metaValue: {
|
|
446
474
|
color: "var(--dsw-alias-label-secondary)",
|
|
447
475
|
textAlign: "right",
|
|
@@ -688,15 +716,18 @@ window.__ModuleLoader__.load({
|
|
|
688
716
|
* One change at a time, through the host's own route. The token is the one
|
|
689
717
|
* this process handed out with the status, so another page cannot do this.
|
|
690
718
|
*/
|
|
691
|
-
async function change(status, set, value) {
|
|
719
|
+
async function change(status, set, value, target) {
|
|
692
720
|
const token = status?.token;
|
|
693
721
|
if (!token) return { ok: false, error: "no token" };
|
|
694
722
|
const session = status?.sessionId
|
|
695
723
|
? `&session=${encodeURIComponent(status.sessionId)}`
|
|
696
724
|
: "";
|
|
725
|
+
// A claim names the session that should own a repository, which need not be
|
|
726
|
+
// the session this page belongs to.
|
|
727
|
+
const named = target ? `&target=${encodeURIComponent(target)}` : "";
|
|
697
728
|
const url = `/inbox-bridge/prefs?token=${encodeURIComponent(token)}&set=${encodeURIComponent(
|
|
698
729
|
set,
|
|
699
|
-
)}&value=${encodeURIComponent(value)}${session}`;
|
|
730
|
+
)}&value=${encodeURIComponent(value)}${session}${named}`;
|
|
700
731
|
try {
|
|
701
732
|
const response = await fetch(url, { cache: "no-store" });
|
|
702
733
|
return await response.json();
|
|
@@ -717,11 +748,11 @@ window.__ModuleLoader__.load({
|
|
|
717
748
|
const [error, setError] = React.useState(null);
|
|
718
749
|
const [draft, setDraft] = React.useState("");
|
|
719
750
|
const pick = text.pick;
|
|
720
|
-
const send = async (set, value) => {
|
|
751
|
+
const send = async (set, value, target) => {
|
|
721
752
|
if (busy) return;
|
|
722
753
|
setBusy(true);
|
|
723
754
|
setError(null);
|
|
724
|
-
const result = await change(status, set, value);
|
|
755
|
+
const result = await change(status, set, value, target);
|
|
725
756
|
setBusy(false);
|
|
726
757
|
if (!result.ok) {
|
|
727
758
|
setError(result.error ?? "failed");
|
|
@@ -777,6 +808,74 @@ window.__ModuleLoader__.load({
|
|
|
777
808
|
"mode",
|
|
778
809
|
),
|
|
779
810
|
),
|
|
811
|
+
// A wakeup has to reach one session. When several sessions watch the same
|
|
812
|
+
// repository only the person can say which one is responsible, so the
|
|
813
|
+
// choice belongs next to the switch that makes wakeups possible at all.
|
|
814
|
+
status.delivery === "wakeup" && sessionRepo && (status.wake?.viewers?.length ?? 0) > 1
|
|
815
|
+
? h(
|
|
816
|
+
"div",
|
|
817
|
+
{ style: styles.controlRow },
|
|
818
|
+
h("span", { style: styles.controlLabel, title: pick.ownerTip }, pick.owner),
|
|
819
|
+
h(
|
|
820
|
+
"div",
|
|
821
|
+
{ style: styles.ownerList },
|
|
822
|
+
status.wake.viewers.map((viewer) =>
|
|
823
|
+
h(
|
|
824
|
+
"button",
|
|
825
|
+
{
|
|
826
|
+
key: viewer.id,
|
|
827
|
+
type: "button",
|
|
828
|
+
disabled: busy,
|
|
829
|
+
"aria-pressed": Boolean(viewer.primary),
|
|
830
|
+
title: viewer.primary ? `${viewer.label} · ${pick.ownerReleaseTip}` : viewer.label,
|
|
831
|
+
onClick: () => void send("primary", viewer.primary ? "" : sessionRepo, viewer.id),
|
|
832
|
+
style: { ...styles.seg, ...(viewer.primary ? styles.segOn : {}) },
|
|
833
|
+
},
|
|
834
|
+
viewer.label,
|
|
835
|
+
),
|
|
836
|
+
),
|
|
837
|
+
),
|
|
838
|
+
)
|
|
839
|
+
: null,
|
|
840
|
+
// How patient the wakeup is: quiet at least this long, at most this many
|
|
841
|
+
// times an hour. Both were file-only settings until a session could ask
|
|
842
|
+
// for them from here.
|
|
843
|
+
status.delivery === "wakeup"
|
|
844
|
+
? h(
|
|
845
|
+
"div",
|
|
846
|
+
{ style: styles.controlRow },
|
|
847
|
+
h("span", { style: styles.controlLabel, title: pick.idleTip }, pick.idle),
|
|
848
|
+
seg(
|
|
849
|
+
pick.idle,
|
|
850
|
+
[
|
|
851
|
+
[1, pick.minute1, pick.idleTip],
|
|
852
|
+
[5, pick.minute5, pick.idleTip],
|
|
853
|
+
[15, pick.minute15, pick.idleTip],
|
|
854
|
+
],
|
|
855
|
+
Math.round((status.wake?.idleMs ?? 900000) / 60000),
|
|
856
|
+
"idle",
|
|
857
|
+
"idle",
|
|
858
|
+
),
|
|
859
|
+
)
|
|
860
|
+
: null,
|
|
861
|
+
status.delivery === "wakeup"
|
|
862
|
+
? h(
|
|
863
|
+
"div",
|
|
864
|
+
{ style: styles.controlRow },
|
|
865
|
+
h("span", { style: styles.controlLabel, title: pick.budgetTip }, pick.budget),
|
|
866
|
+
seg(
|
|
867
|
+
pick.budget,
|
|
868
|
+
[
|
|
869
|
+
[1, "1", pick.budgetTip],
|
|
870
|
+
[2, "2", pick.budgetTip],
|
|
871
|
+
[4, "4", pick.budgetTip],
|
|
872
|
+
],
|
|
873
|
+
status.wake?.perHour ?? 2,
|
|
874
|
+
"budget",
|
|
875
|
+
"budget",
|
|
876
|
+
),
|
|
877
|
+
)
|
|
878
|
+
: null,
|
|
780
879
|
h(
|
|
781
880
|
"div",
|
|
782
881
|
{ style: styles.controlRow },
|
package/docs/DETAIL.md
CHANGED
|
@@ -17,7 +17,7 @@ That is also why it only reads: its job is to make the agent aware. The work hap
|
|
|
17
17
|
- **Relevance comes from your identity.** It queries the repositories as your local `gh` login (or a configured App identity) and keeps only events where you are the author, the reviewer, the assignee, or are mentioned.
|
|
18
18
|
- **It reads repositories, not the notification inbox.** The notification inbox pushes per account and cannot tell sessions or repositories apart; querying repository state keeps two repositories on the same account apart.
|
|
19
19
|
- **Polling follows turns.** Once at the start, every minute while a turn runs, once at the end; an idle session makes no request.
|
|
20
|
-
- **The panel is editable.** The chip shows a blue dot and a count when something waits; hovering opens the events and
|
|
20
|
+
- **The panel is editable.** The chip shows a blue dot and a count when something waits; hovering opens the events and a few controls: delivery, who takes a wakeup (when several sessions watch one repository), the rhythm (how idle is idle, wakes per hour), message clearing (off / mark read / archive to Done — one choice), and which repositories this session subscribes to (paste a link or type `owner/name`).
|
|
21
21
|
|
|
22
22
|
## Install
|
|
23
23
|
|
package/docs/DETAIL.zh.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
- **按身份判断相关性。** 用本机 `gh` 的登录身份(或配置的 App 身份)查询仓库,只保留以你为作者、评审人、指派对象或提及对象的事件。
|
|
18
18
|
- **只看仓库,不看通知箱。** 通知箱按账号推送,分不清会话与仓库;这里直接查仓库状态,同一账号下两个仓库互不干扰。
|
|
19
19
|
- **轮询跟随回合。** 会话开始一次、进行中每 1 分钟一次、结束一次;空闲不发请求。
|
|
20
|
-
- **面板可改。**
|
|
20
|
+
- **面板可改。** 状态行胶囊在有未处理事件时显示蓝点与数量;悬停展开事件列表与几组开关:提醒方式、谁来接(同仓库多会话时指定负责唤醒的那个)、节奏(空闲多久、每小时几次)、消息清理(关闭 / 已读 / 归档,一档三态)、订阅哪些仓库(粘贴仓库链接或写 `owner/name`)。
|
|
21
21
|
|
|
22
22
|
## 安装
|
|
23
23
|
|
package/docs/configuration.md
CHANGED
|
@@ -18,7 +18,7 @@ DSH 的插件配置里,一个 `dsh-inbox-bridge` 条目即可;等价写法
|
|
|
18
18
|
|
|
19
19
|
## 在页面上改(覆盖层)
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
输入框下面那颗胶囊浮出来的卡片里,可以直接改这几件事:提醒方式、谁来接这个仓库的唤醒、节奏(空闲多久、每小时几次)、消息清理、订阅哪些仓库。这些改动不写回 DSH 的插件配置,而是记在插件自己的覆盖层里:
|
|
22
22
|
|
|
23
23
|
```text
|
|
24
24
|
<cwd>/.work/inbox-bridge/prefs.json
|
|
@@ -65,6 +65,7 @@ GitHub 的 Done 只有网页端点,所以归档要用插件自己的浏览器
|
|
|
65
65
|
| `wakeAfterIdleMs` | `900000`(15 分钟) | 会话静默多久后才允许唤醒 |
|
|
66
66
|
| `wakesPerHour` | `2` | 滚动一小时内最多唤醒几次;0 = 关闭 |
|
|
67
67
|
| `maxConsecutiveWakes` | `3` | 一个会话在你下次发言前最多被唤醒几次,之后只排队 |
|
|
68
|
+
| `primary` | `{}` | 哪个会话负责哪个仓库的唤醒:`{ "owner/name": "<sessionId>" }`。同一仓库有两个会话在看而这里没指定时,谁都不唤醒——宁可让它们按回合读,也不要叫错人。面板上的「谁来接」写的就是这个键 |
|
|
68
69
|
| `identity` | `{ kind: "user" }` | 用哪个身份读 GitHub,见下 |
|
|
69
70
|
| `roles` | `[]` | 只接收这些角色的事件;空 = 全收 |
|
|
70
71
|
| `clear` | `"repo"` | 把这一轮读过的通知线程标为已读:`repo` 只清订阅的仓库,`off` 不碰收件箱。整个账号不在范围内——清别人的仓库属于人的决定,不是后台轮询的决定。旧配置里的 `"all"` 按 `"repo"` 载入。GitHub 没有「完成」API,所以清的是未读角标,历史仍在收件箱里 |
|
|
@@ -74,7 +75,7 @@ GitHub 的 Done 只有网页端点,所以归档要用插件自己的浏览器
|
|
|
74
75
|
| `poll` | 插件自带 CLI 的 `poll` | 换掉抓取命令:`{ command, args }`,只要能输出约定的 JSON,来源可以不是 GitHub |
|
|
75
76
|
| `ack` | 插件自带 CLI 的 `ack` | 同上,换掉收口命令 |
|
|
76
77
|
|
|
77
|
-
启动时会校验明显写错的组合:`identity.kind: "app"` 没给 `token`/`tokenEnv`、`intervalMs < 5000`、`wakeOn` 非空却选了 `quiet
|
|
78
|
+
启动时会校验明显写错的组合:`identity.kind: "app"` 没给 `token`/`tokenEnv`、`intervalMs < 5000`、`wakeOn` 不是字符串数组、`primary` 的键不是 `owner/name`——都会直接报错并指出是哪一项,而不是悄悄用默认值。`wakeOn` 非空却选了 `quiet` 不报错:那是「先写好白名单、还没打开唤醒」的正常写法,启动行会说明这些角色只排队。
|
|
78
79
|
|
|
79
80
|
## 身份
|
|
80
81
|
|
package/docs/how-it-works.md
CHANGED
|
@@ -51,7 +51,9 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
|
|
|
51
51
|
- 内容只有:盯着的仓库、身份、投递方式、队列三种状态的数量、未收口的 20 条(标题与链接来自本轮真实看到的事件)、每个仓库上次轮询的时间。
|
|
52
52
|
- 它不写回任何状态,也不替你 ack;读的就是 `scripts/inbox-bridge.mjs status` 那份事实。
|
|
53
53
|
- 客户端代码是在页面里执行的:更新插件后要**重新打开一次应用**(桌面版没有刷新键),胶囊才会重新装上;在那之前它会先消失(不是坏了,是没有执行者)。
|
|
54
|
-
-
|
|
54
|
+
- 卡片里的开关(提醒方式、谁来接、节奏、消息清理、订阅)也走同源路由:`GET /inbox-bridge/prefs?token=…&set=…&value=…`(指定负责会话时多带 `&target=<sessionId>`)。改动写进插件自己的覆盖层 `<cwd>/.work/inbox-bridge/prefs.json`,然后重新读一遍状态——显示的就是下一次轮询真要执行的东西,不做乐观更新。token 每次进程启动重新生成,随状态一起下发,防止别的本地页面替你改设置。
|
|
55
|
+
- 「谁来接」只在同一仓库有多个会话在看时才出现:这时没人负责就谁都不唤醒(宁可让 agent 自己按回合读,也不要叫错人),指定一个之后只有它接受唤醒;只剩一个会话时它自动负责,不需要设置。
|
|
56
|
+
- 「节奏」里的空闲时长与每小时次数就是 `wakeAfterIdleMs` 与 `wakesPerHour` 的现值,点一下写进覆盖层,不必去改插件配置。
|
|
55
57
|
- 「消息清理」选到归档时,插件会把缺的那次登录替你补上:它自己起一个可见的浏览器窗口等你在插件的浏览器配置里登录,登录完归档接着跑。会话失效而选项还停在归档上时,下一次归档失败会再开一次窗口(至少间隔 `signInCooldownMs`);还没登录时卡片里会写「归档还没登录 GitHub」,旁边是「打开登录窗口」。
|
|
56
58
|
- 页面第一次挂载时会往 `GET /inbox-bridge/client-log?m=…` 报一行容器尺寸,写进 `plugin.log`(`client: …`)。宿主的资源只应答 GET/HEAD,POST 会变成 405,所以诊断改走查询串。它只在排查「为什么浮层位置不对」时有用,平常不用管。
|
|
57
59
|
|
|
@@ -69,6 +71,8 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
|
|
|
69
71
|
| 基础设施失败 | 只提醒一次,因为再改代码也修不好它 |
|
|
70
72
|
| 安全告警 | 开着的 Dependabot 与 code scanning 告警;每个来源合成一条(条数与严重度分布),修完最后一条后下一次轮询就收口 |
|
|
71
73
|
| PR 变脏 | 我是作者或指派人,且 PR 与基分支冲突或落后;评审人不算,合并是作者的事 |
|
|
74
|
+
| 定时任务 | 由 `schedule` 触发的那次运行失败了,标为 `[Scheduled]` 而不是 `[CI]`,免得把夜里的失败读成最后一次推送的失败;下一次成功时给一条「已恢复」 |
|
|
75
|
+
| 评审意见 | 我自己的 PR 上有别人写的评审评论。GitHub 的评论没有「完成」状态,唯一的收口是代码:评论写在某个 commit 上,分支推过那个 commit 之后它就不再报出,队列随之收口 |
|
|
72
76
|
|
|
73
77
|
同一条事实不会因为检查状态变来变去就变成好几条通知:key 只由「需要你处理的状态」构成,`QUEUED → IN_PROGRESS → SUCCESS` 全程同一个 key。
|
|
74
78
|
|
package/docs/index.json
CHANGED
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
},
|
|
51
51
|
"versions": [
|
|
52
52
|
{
|
|
53
|
-
"version": "2.
|
|
54
|
-
"publishTimestamp":
|
|
53
|
+
"version": "2.20.0",
|
|
54
|
+
"publishTimestamp": 1794923141,
|
|
55
55
|
"source": {
|
|
56
56
|
"type": "git",
|
|
57
57
|
"url": "https://github.com/c3115644151/dsh-inbox-bridge",
|
|
58
|
-
"commit": "
|
|
58
|
+
"commit": "ec6cde407ed1329079e47bb8122c48c8074bbd9f"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"dsh": ">=0.1.0"
|
package/index.js
CHANGED
|
@@ -117,15 +117,34 @@ export function preferenceNext(current = {}, action = "", value = "", options =
|
|
|
117
117
|
}
|
|
118
118
|
if (action === "primary") {
|
|
119
119
|
// Who may be woken for this repository. An empty value releases the claim.
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
// The page may name the session it means (`target`), because the person is
|
|
121
|
+
// choosing among the sessions watching a repository, not necessarily
|
|
122
|
+
// speaking from the one that should own it.
|
|
123
|
+
const owner = options.targetSession ?? sessionId;
|
|
124
|
+
if (!owner) return null;
|
|
125
|
+
const repo = value ? repoFromInput(value) : (options.sessionRepo ?? null);
|
|
122
126
|
if (!repo) return null;
|
|
123
127
|
const primary = { ...(next.primary ?? {}) };
|
|
124
|
-
if (value) primary[repo] =
|
|
128
|
+
if (value) primary[repo] = owner;
|
|
125
129
|
else delete primary[repo];
|
|
126
130
|
next.primary = primary;
|
|
127
131
|
return next;
|
|
128
132
|
}
|
|
133
|
+
if (action === "idle") {
|
|
134
|
+
// How long a session must be quiet before a wakeup may open a turn. Minutes
|
|
135
|
+
// in the page, milliseconds here; zero means "as soon as nobody is busy".
|
|
136
|
+
const minutes = Number(value);
|
|
137
|
+
if (!Number.isFinite(minutes) || minutes < 0 || minutes > 24 * 60) return null;
|
|
138
|
+
next.wakeAfterIdleMs = Math.round(minutes * 60_000);
|
|
139
|
+
return next;
|
|
140
|
+
}
|
|
141
|
+
if (action === "budget") {
|
|
142
|
+
// How many wakeups an hour this instance may spend in total.
|
|
143
|
+
const perHour = Number(value);
|
|
144
|
+
if (!Number.isInteger(perHour) || perHour < 1 || perHour > 24) return null;
|
|
145
|
+
next.wakesPerHour = perHour;
|
|
146
|
+
return next;
|
|
147
|
+
}
|
|
129
148
|
return null;
|
|
130
149
|
}
|
|
131
150
|
|
|
@@ -381,6 +400,15 @@ export function apply(ctx, config) {
|
|
|
381
400
|
roles: options.roles ?? [],
|
|
382
401
|
}
|
|
383
402
|
: null;
|
|
403
|
+
// A repository can be watched by several sessions in the same directory, and
|
|
404
|
+
// a wakeup has to reach the one the person named. The page can only offer
|
|
405
|
+
// that choice if it knows who else is watching.
|
|
406
|
+
const viewers = repo
|
|
407
|
+
? [...agents.entries()]
|
|
408
|
+
.map(([id, each]) => ({ id, label: sessionLabel(each), repo: repoOf(each) }))
|
|
409
|
+
.filter((entry) => entry.repo && entry.repo.toLowerCase() === repo.toLowerCase())
|
|
410
|
+
.map(({ id, label }) => ({ id, label }))
|
|
411
|
+
: [];
|
|
384
412
|
return {
|
|
385
413
|
...buildUiPayload({
|
|
386
414
|
options,
|
|
@@ -388,6 +416,7 @@ export function apply(ctx, config) {
|
|
|
388
416
|
source: readJson(join(options.cwd, SOURCE_STATE_REL)),
|
|
389
417
|
recent,
|
|
390
418
|
session,
|
|
419
|
+
viewers,
|
|
391
420
|
}),
|
|
392
421
|
// The page proves it is this process's page before it may change anything,
|
|
393
422
|
// and shows which choices came from it rather than from the profile.
|
|
@@ -550,7 +579,18 @@ export function apply(ctx, config) {
|
|
|
550
579
|
signIn.signedIn = true;
|
|
551
580
|
log(`swept the notification inbox: ${line || "done"} (${Date.now() - began}ms)`);
|
|
552
581
|
} catch (error) {
|
|
553
|
-
|
|
582
|
+
// The command's own answer outranks its exit code. `--json` prints
|
|
583
|
+
// `{ ok: true, … }` even when the process ends non-zero (a browser it could
|
|
584
|
+
// not fully close, say), and reporting that as a failure would teach people
|
|
585
|
+
// to ignore the line that is supposed to mean "this is broken".
|
|
586
|
+
const answer = parseJsonAnswer(error?.stdout);
|
|
587
|
+
if (answer?.ok === true) {
|
|
588
|
+
signIn.signedIn = true;
|
|
589
|
+
const archived = Number.isFinite(answer.archived) ? `${answer.archived} thread(s)` : "done";
|
|
590
|
+
log(`swept the notification inbox: ${archived} (${Date.now() - began}ms)`);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (error?.exitCode === 2 || answer?.reason === "sign-in-required") {
|
|
554
594
|
// The command says "sign-in required"; raise the window rather than
|
|
555
595
|
// asking the operator to copy a command out of the log.
|
|
556
596
|
signIn.signedIn = false;
|
|
@@ -628,6 +668,17 @@ export function apply(ctx, config) {
|
|
|
628
668
|
primary: prefs.primary ?? {},
|
|
629
669
|
});
|
|
630
670
|
if (!wake.agent && wake.considered > 0) log(`no wakeup: ${wake.why}`);
|
|
671
|
+
// A wakeup that is only waiting for the idle window must not spend the
|
|
672
|
+
// event by injecting it: that would fill the next turn and leave nothing
|
|
673
|
+
// for the wake it existed for. The event stays pending and the next poll
|
|
674
|
+
// carries it (see `carriedPending`), so the wake still happens once the
|
|
675
|
+
// session has been quiet long enough.
|
|
676
|
+
if (!wake.agent && wake.why === "not-idle" && options.delivery === "wakeup") {
|
|
677
|
+
log(
|
|
678
|
+
`held ${events.length} event(s): the session has not been idle for ${pollLabel(options.wakeAfterIdleMs)} yet`,
|
|
679
|
+
);
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
631
682
|
const waking = wake.agent ? new Set([wake.agent]) : new Set();
|
|
632
683
|
const deliveredKeys = new Set();
|
|
633
684
|
let delivered = 0;
|
|
@@ -873,6 +924,10 @@ export function apply(ctx, config) {
|
|
|
873
924
|
const action = url.searchParams.get("set") ?? "";
|
|
874
925
|
const value = url.searchParams.get("value") ?? "";
|
|
875
926
|
const sessionId = url.searchParams.get("session") || null;
|
|
927
|
+
// A claim names the session that should own a repository, which is
|
|
928
|
+
// not always the session the page is drawn for.
|
|
929
|
+
const named = url.searchParams.get("target") || null;
|
|
930
|
+
const targetSession = named && agents.has(named) ? named : null;
|
|
876
931
|
// Which repository the session lives in, so "subscribe my repo" and
|
|
877
932
|
// "unsubscribe the last one" know what the default is.
|
|
878
933
|
const sessionRepo = sessionId ? repoOf(agents.get(sessionId)) : null;
|
|
@@ -890,6 +945,7 @@ export function apply(ctx, config) {
|
|
|
890
945
|
...options,
|
|
891
946
|
sessionId,
|
|
892
947
|
sessionRepo,
|
|
948
|
+
targetSession,
|
|
893
949
|
});
|
|
894
950
|
if (action === "signin") {
|
|
895
951
|
// Not a setting: open the window that archiving needs.
|
|
@@ -1355,6 +1411,10 @@ function runCommand(spec, options, extraEnv = {}) {
|
|
|
1355
1411
|
// needs a person once" (the sweep needs a browser sign-in), which is
|
|
1356
1412
|
// not the same problem as a crashed command.
|
|
1357
1413
|
if (typeof error.code === "number") failure.exitCode = error.code;
|
|
1414
|
+
// Keep the command's own words: a `--json` run may have answered while
|
|
1415
|
+
// still exiting non-zero, and the answer is the better evidence.
|
|
1416
|
+
failure.stdout = stdout ?? "";
|
|
1417
|
+
failure.stderr = stderr ?? "";
|
|
1358
1418
|
reject(failure);
|
|
1359
1419
|
return;
|
|
1360
1420
|
}
|
|
@@ -1392,10 +1452,10 @@ export function filterUndelivered(events, seen, now, resurfaceMs) {
|
|
|
1392
1452
|
|
|
1393
1453
|
export function pollLabel(ms) {
|
|
1394
1454
|
const value = Number.isFinite(ms) ? ms : DEFAULTS.intervalMs;
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
//
|
|
1398
|
-
|
|
1455
|
+
// Round numbers of minutes read best ("15 分钟"); anything else is stated in
|
|
1456
|
+
// seconds, because 90 000 ms is not "2 分钟" — it is 90 秒, and rounding it up
|
|
1457
|
+
// makes the notice promise a wait longer than it will be.
|
|
1458
|
+
if (value >= 60_000 && value % 60_000 === 0) return `${Math.round(value / 60_000)} 分钟`;
|
|
1399
1459
|
return `${Math.max(1, Math.round(value / 1_000))} 秒`;
|
|
1400
1460
|
}
|
|
1401
1461
|
|
|
@@ -1463,6 +1523,7 @@ export function buildUiPayload({
|
|
|
1463
1523
|
now = Date.now(),
|
|
1464
1524
|
session = null,
|
|
1465
1525
|
signIn = null,
|
|
1526
|
+
viewers = null,
|
|
1466
1527
|
}) {
|
|
1467
1528
|
const configured = options.repos?.length > 0 ? options.repos : options.repo ? [options.repo] : [];
|
|
1468
1529
|
// A session sees exactly what a poll would deliver to it: the repositories it
|
|
@@ -1500,6 +1561,17 @@ export function buildUiPayload({
|
|
|
1500
1561
|
.sort((left, right) => String(right.at ?? "").localeCompare(String(left.at ?? "")))
|
|
1501
1562
|
.slice(0, 20);
|
|
1502
1563
|
const identity = options.identity ?? DEFAULTS.identity;
|
|
1564
|
+
// How a wakeup may happen, in the terms the page can change: which roles, how
|
|
1565
|
+
// quiet a session must be, how many an hour, and which session owns the
|
|
1566
|
+
// repository this page is looking at.
|
|
1567
|
+
const claims = options.primary ?? {};
|
|
1568
|
+
const ownerOf = (name) => {
|
|
1569
|
+
if (!name) return null;
|
|
1570
|
+
const wanted = String(name).toLowerCase();
|
|
1571
|
+
const hit = Object.keys(claims).find((key) => key.toLowerCase() === wanted);
|
|
1572
|
+
return hit ? claims[hit] : null;
|
|
1573
|
+
};
|
|
1574
|
+
const sessionRepo = scoped ? (session.repo ?? repos[0] ?? null) : null;
|
|
1503
1575
|
return {
|
|
1504
1576
|
at: new Date(now).toISOString(),
|
|
1505
1577
|
label: options.label ?? DEFAULTS.label,
|
|
@@ -1521,6 +1593,17 @@ export function buildUiPayload({
|
|
|
1521
1593
|
sweep: options.sweep?.when ?? null,
|
|
1522
1594
|
signIn: signIn ?? { signedIn: null, open: false, attemptedAt: null },
|
|
1523
1595
|
intervalMs: options.intervalMs ?? DEFAULTS.intervalMs,
|
|
1596
|
+
wake: {
|
|
1597
|
+
on: options.wakeOn ?? [],
|
|
1598
|
+
idleMs: options.wakeAfterIdleMs ?? DEFAULTS.wakeAfterIdleMs,
|
|
1599
|
+
perHour: options.wakesPerHour ?? DEFAULTS.wakesPerHour,
|
|
1600
|
+
primary: ownerOf(sessionRepo),
|
|
1601
|
+
// Who else is watching this repository, and which of them owns it today.
|
|
1602
|
+
viewers: (viewers ?? []).map((entry) => ({
|
|
1603
|
+
...entry,
|
|
1604
|
+
primary: ownerOf(sessionRepo) === entry.id,
|
|
1605
|
+
})),
|
|
1606
|
+
},
|
|
1524
1607
|
queue: counts,
|
|
1525
1608
|
events: events.slice(0, 20),
|
|
1526
1609
|
polls: repos.map((repo) => ({ repo, ...(source?.repos?.[repo]?.lastPoll ?? {}) })),
|
|
@@ -1548,3 +1631,25 @@ function describeEvent(event) {
|
|
|
1548
1631
|
function describe(error) {
|
|
1549
1632
|
return error instanceof Error ? error.message : String(error);
|
|
1550
1633
|
}
|
|
1634
|
+
|
|
1635
|
+
/**
|
|
1636
|
+
* The last JSON object a command printed, or null. Children print progress lines
|
|
1637
|
+
* before their answer, so scan from the end and take the first line that parses.
|
|
1638
|
+
*/
|
|
1639
|
+
function parseJsonAnswer(stdout) {
|
|
1640
|
+
const lines = String(stdout ?? "")
|
|
1641
|
+
.trim()
|
|
1642
|
+
.split(/\r?\n/u)
|
|
1643
|
+
.reverse();
|
|
1644
|
+
for (const line of lines) {
|
|
1645
|
+
const text = line.trim();
|
|
1646
|
+
if (!text.startsWith("{")) continue;
|
|
1647
|
+
try {
|
|
1648
|
+
const parsed = JSON.parse(text);
|
|
1649
|
+
if (parsed && typeof parsed === "object") return parsed;
|
|
1650
|
+
} catch {
|
|
1651
|
+
// Not the answer; keep looking.
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return null;
|
|
1655
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-inbox-bridge",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"displayName": "GitHub inbox",
|
|
5
5
|
"description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
|
|
6
6
|
"type": "module",
|
package/scripts/clear-inbox.mjs
CHANGED
|
@@ -540,7 +540,15 @@ if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.m
|
|
|
540
540
|
main(process.argv.slice(2)).then(
|
|
541
541
|
(code) => process.exit(code ?? 0),
|
|
542
542
|
(error) => {
|
|
543
|
-
|
|
543
|
+
// A bare "Uncaught" tells whoever reads the log nothing. Keep the message
|
|
544
|
+
// and the first frames, which is what says whether the profile is busy or
|
|
545
|
+
// the page changed.
|
|
546
|
+
const text = String(error?.message ?? error);
|
|
547
|
+
const frames = String(error?.stack ?? "")
|
|
548
|
+
.split("\n")
|
|
549
|
+
.slice(1, 3)
|
|
550
|
+
.join("\n");
|
|
551
|
+
console.error(`clear-inbox: ${text}${frames ? `\n${frames}` : ""}`);
|
|
544
552
|
process.exit(1);
|
|
545
553
|
},
|
|
546
554
|
);
|