dsh-inbox-bridge 2.19.0 → 2.19.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 +10 -0
- package/docs/how-it-works.md +1 -1
- package/docs/index.json +3 -3
- package/index.js +1 -0
- package/package.json +1 -1
- package/scripts/inbox-bridge.mjs +104 -3
- package/scripts/inbox-bridge.test.mjs +86 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 2.19.2
|
|
2
|
+
|
|
3
|
+
- 被「留下」的事件现在会先记进队列(`attempts: 0` 表示记下来了但还没告诉任何人),下一次轮询即使来源已经不再报它,也会把它重新端上来。之前 issue 与评论这类只报一次的事实,在「所有会话都正忙」的那一轮被留下之后就永远消失了——唤醒因此永远等不到它要等的那条消息。
|
|
4
|
+
- 这类记录也会过期:六小时后没人收到就不再当新闻,队列不会无限长。
|
|
5
|
+
- 回归测试:`an event held while everyone was busy reaches a later poll`(取消结转后立刻红)。
|
|
6
|
+
## 2.19.1
|
|
7
|
+
|
|
8
|
+
- 一件还没告诉过任何人的事不再被「来源不再报出」直接收口。issue 与评论是只报一次的事实:某个会话正忙时事件被留下,下一次轮询本来就取不到第二次,原来的收口逻辑正好把它丢掉——于是事件永远等不到那个愿意叫人的时刻,唤醒也就永远不会发生。现在只有已经投递过的 key 才会因为事实不再成立而收口。
|
|
9
|
+
- `wakePlan` 的 `primary` 也会写进 `runtime.json`,`doctor` 与面板读到的是同一份事实。
|
|
10
|
+
- 回归测试:`a fact nobody was told about is not closed by the source going quiet`(去掉判定后该用例立刻红)。
|
|
1
11
|
## 2.19.0
|
|
2
12
|
|
|
3
13
|
- 唤醒要先说清「谁负责」:同一个工作区里可以开多个会话,它们看的是同一个仓库,于是「这个仓库的会话」不再是一个确定的答案。现在一个仓库只有一个会话在看时,它就是负责的那个;有多个时,谁都不叫,直到你在面板里指定某一个负责(`primary`)。插件没有资格替你挑谈话对象。
|
package/docs/how-it-works.md
CHANGED
|
@@ -31,7 +31,7 @@ DSH 插件 (index.js) 调度与投递:什么时候去取、取回来给
|
|
|
31
31
|
2. 判断「跟我有关吗」——这是插件的核心判断,见下一节。
|
|
32
32
|
3. 给每个事件一个 key(`owner/name#pr:23:reviewer:review-requested` 这样),同一件事在多次轮询里是同一个 key。
|
|
33
33
|
4. 队列里已有记录的 key 不重复投递;已经投出去但没有人收口的,6 小时后重提**一次**,再之后就当作已经说过了。
|
|
34
|
-
5. 上一次轮询能报出、这一次报不出的 key,说明这条事实已经不再成立(检查变绿、PR 合了、issue
|
|
34
|
+
5. 上一次轮询能报出、这一次报不出的 key,说明这条事实已经不再成立(检查变绿、PR 合了、issue 关了),直接收口——队列里只留「此刻仍然成立」的事。还没有告诉过任何人的事件不收口:issue 与评论这类只报一次的事实,一旦在「会话正忙」时被留下,下一次轮询就没有第二次机会了,收口等于把它丢掉。
|
|
35
35
|
6. 按会话分组:会话自己的仓库 + 自己的角色都匹配,才进它那份。
|
|
36
36
|
7. 投递:`quiet` 时注入给空闲的会话、等它下一轮;`wakeup` 时先过五道门。
|
|
37
37
|
8. 只把**真正投出去**的 key 标 delivered。没投出去的下次还有机会,不会被误标。
|
package/docs/index.json
CHANGED
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
},
|
|
51
51
|
"versions": [
|
|
52
52
|
{
|
|
53
|
-
"version": "2.19.
|
|
54
|
-
"publishTimestamp":
|
|
53
|
+
"version": "2.19.2",
|
|
54
|
+
"publishTimestamp": 1794919572,
|
|
55
55
|
"source": {
|
|
56
56
|
"type": "git",
|
|
57
57
|
"url": "https://github.com/c3115644151/dsh-inbox-bridge",
|
|
58
|
-
"commit": "
|
|
58
|
+
"commit": "c10670c89d1640756101582831d808e1e6970f01"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"dsh": ">=0.1.0"
|
package/index.js
CHANGED
|
@@ -421,6 +421,7 @@ export function apply(ctx, config) {
|
|
|
421
421
|
clear: options.clear,
|
|
422
422
|
sweep: options.sweep ? options.sweep.when : null,
|
|
423
423
|
wakeOn: options.wakeOn,
|
|
424
|
+
primary: options.primary ?? {},
|
|
424
425
|
wakeAfterIdleMs: options.wakeAfterIdleMs,
|
|
425
426
|
wakesPerHour: options.wakesPerHour,
|
|
426
427
|
maxConsecutiveWakes: options.maxConsecutiveWakes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-inbox-bridge",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.2",
|
|
4
4
|
"displayName": "GitHub inbox",
|
|
5
5
|
"description": "DSH 插件:让 agent 像维护者一样盯着你的仓库——按会话订阅仓库,取回与你有关、需要你处理的事件(失败的 CI、待评审的 PR、指派给你的 issue、@你的评论、开着的安全告警),在自己的回合送进上下文;会话空闲又遇到要紧的事时也能主动开一轮,让 agent 自己去修、去审、去接。",
|
|
6
6
|
"type": "module",
|
package/scripts/inbox-bridge.mjs
CHANGED
|
@@ -87,6 +87,76 @@ export function transition(state, items, status, at) {
|
|
|
87
87
|
return { state: { events }, marked };
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Remember the events nobody has been told about yet.
|
|
92
|
+
*
|
|
93
|
+
* Some facts are reported once: an issue is opened, a comment is posted. If the
|
|
94
|
+
* poll finds every session busy, the plugin holds the event and delivers it on
|
|
95
|
+
* a later turn — but the next poll has nothing to report, so without a record
|
|
96
|
+
* the news would simply be gone, and a wakeup could never happen. Entries use
|
|
97
|
+
* `attempts: 0` to say "recorded, never delivered".
|
|
98
|
+
*/
|
|
99
|
+
export function recordPending(state, events, at) {
|
|
100
|
+
const out = { ...(state?.events ?? {}) };
|
|
101
|
+
const marked = [];
|
|
102
|
+
for (const event of Array.isArray(events) ? events : []) {
|
|
103
|
+
if (!event || typeof event.key !== "string") continue;
|
|
104
|
+
if (out[event.key]) continue;
|
|
105
|
+
out[event.key] = {
|
|
106
|
+
status: "pending",
|
|
107
|
+
at,
|
|
108
|
+
attempts: 0,
|
|
109
|
+
...(event.kind ? { kind: event.kind } : {}),
|
|
110
|
+
...(event.role ? { role: event.role } : {}),
|
|
111
|
+
...(event.group ? { group: event.group } : {}),
|
|
112
|
+
...(event.title ? { title: event.title } : {}),
|
|
113
|
+
...(event.url ? { url: event.url } : {}),
|
|
114
|
+
...(event.label ? { label: event.label } : {}),
|
|
115
|
+
...(event.ref ? { ref: event.ref } : {}),
|
|
116
|
+
...(event.event ? { event: event.event } : {}),
|
|
117
|
+
...(event.at ? { eventAt: event.at } : {}),
|
|
118
|
+
};
|
|
119
|
+
marked.push(event.key);
|
|
120
|
+
}
|
|
121
|
+
return { state: { events: out }, marked };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Rebuild the events a previous poll recorded but never delivered, so a turn
|
|
126
|
+
* that starts later still learns about them. Facts are forgotten after
|
|
127
|
+
* `resurfaceMs`: a notice nobody received for six hours is no longer news.
|
|
128
|
+
*/
|
|
129
|
+
export function carriedPending(state, events, options = {}) {
|
|
130
|
+
const now = options.now ?? Date.now();
|
|
131
|
+
const resurfaceMs = options.resurfaceMs ?? RESURFACE_MS;
|
|
132
|
+
const live = new Set(
|
|
133
|
+
(Array.isArray(events) ? events : [])
|
|
134
|
+
.filter((event) => event && typeof event.key === "string")
|
|
135
|
+
.map((event) => event.key),
|
|
136
|
+
);
|
|
137
|
+
const out = [];
|
|
138
|
+
for (const [key, entry] of Object.entries(state?.events ?? {})) {
|
|
139
|
+
if (!entry || entry.status !== "pending" || (entry.attempts ?? 0) !== 0) continue;
|
|
140
|
+
if (live.has(key)) continue;
|
|
141
|
+
const at = Number.isFinite(Date.parse(entry.at)) ? Date.parse(entry.at) : now;
|
|
142
|
+
if (now - at >= resurfaceMs) continue;
|
|
143
|
+
out.push({
|
|
144
|
+
key,
|
|
145
|
+
...(entry.kind ? { kind: entry.kind } : {}),
|
|
146
|
+
...(entry.role ? { role: entry.role } : {}),
|
|
147
|
+
...(entry.group ? { group: entry.group } : {}),
|
|
148
|
+
...(entry.title ? { title: entry.title } : {}),
|
|
149
|
+
...(entry.url ? { url: entry.url } : {}),
|
|
150
|
+
...(entry.label ? { label: entry.label } : {}),
|
|
151
|
+
...(entry.ref ? { ref: entry.ref } : {}),
|
|
152
|
+
...(entry.event ? { event: entry.event } : {}),
|
|
153
|
+
...(entry.eventAt ? { at: entry.eventAt } : {}),
|
|
154
|
+
carried: true,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
|
|
90
160
|
/**
|
|
91
161
|
* Split the poller's events into the ones still worth injecting and the rest.
|
|
92
162
|
* A delivered event that nobody marked done comes back after `resurfaceMs`;
|
|
@@ -158,7 +228,9 @@ export function autoDone(state, events, at) {
|
|
|
158
228
|
* this, a notice nobody explicitly acks comes back every `resurfaceMs`
|
|
159
229
|
* forever, which is how a five-hour-old item ends up back on the line.
|
|
160
230
|
*/
|
|
161
|
-
export function closeResolved(state, events, { at, repos = [] } = {}) {
|
|
231
|
+
export function closeResolved(state, events, { at, repos = [], now, resurfaceMs } = {}) {
|
|
232
|
+
const nowMs = Number.isFinite(now) ? now : Date.parse(at ?? "") || Date.now();
|
|
233
|
+
const window = resurfaceMs ?? RESURFACE_MS;
|
|
162
234
|
const events_ = { ...(state?.events ?? {}) };
|
|
163
235
|
const covered = new Set(
|
|
164
236
|
(Array.isArray(repos) ? repos : []).map((repo) => String(repo).toLowerCase()),
|
|
@@ -176,6 +248,14 @@ export function closeResolved(state, events, { at, repos = [] } = {}) {
|
|
|
176
248
|
const repo = hash > 0 ? key.slice(0, hash).toLowerCase() : null;
|
|
177
249
|
if (!repo || !covered.has(repo)) continue;
|
|
178
250
|
if (live.has(key)) continue;
|
|
251
|
+
// Never told anyone about it, and still recent: a fact we have not reported
|
|
252
|
+
// yet is not settled by the source going quiet. Issues and comments are
|
|
253
|
+
// reported once, so closing a held one would drop exactly the news a wakeup
|
|
254
|
+
// was waiting for. Past the resurface window it stops being news.
|
|
255
|
+
if (entry.status === "pending" && (entry.attempts ?? 0) === 0) {
|
|
256
|
+
const seenAt = Number.isFinite(Date.parse(entry.at)) ? Date.parse(entry.at) : nowMs;
|
|
257
|
+
if (nowMs - seenAt < window) continue;
|
|
258
|
+
}
|
|
179
259
|
events_[key] = { ...entry, status: "done", at };
|
|
180
260
|
marked.push(key);
|
|
181
261
|
}
|
|
@@ -261,8 +341,29 @@ export function pollOnce(root, options = {}) {
|
|
|
261
341
|
// `classify` also settles events that stop asking; that decision has to be
|
|
262
342
|
// written back, or the next poll reads them as delivered again.
|
|
263
343
|
const quiet = groups.done.length > 0 ? transition(closed.state, groups.done, "done", at) : closed;
|
|
264
|
-
|
|
265
|
-
|
|
344
|
+
// Write down what nobody has been told yet, so a held event survives the poll
|
|
345
|
+
// that can no longer see it, and pick up whatever an earlier poll held back.
|
|
346
|
+
const recorded =
|
|
347
|
+
groups.pending.length > 0
|
|
348
|
+
? recordPending(quiet.state, groups.pending, at)
|
|
349
|
+
: { state: quiet.state, marked: [] };
|
|
350
|
+
const carried = carriedPending(recorded.state, events, options);
|
|
351
|
+
if (
|
|
352
|
+
recorded.marked.length > 0 ||
|
|
353
|
+
quiet.marked.length > 0 ||
|
|
354
|
+
settled.marked.length > 0 ||
|
|
355
|
+
!existsSync(file)
|
|
356
|
+
) {
|
|
357
|
+
writeState(file, recorded.state);
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
...groups,
|
|
361
|
+
pending: [...groups.pending, ...carried],
|
|
362
|
+
events: [...events, ...carried],
|
|
363
|
+
skipped: null,
|
|
364
|
+
closed: settled.marked,
|
|
365
|
+
state: recorded.state,
|
|
366
|
+
};
|
|
266
367
|
}
|
|
267
368
|
|
|
268
369
|
/**
|
|
@@ -7,6 +7,7 @@ import { test } from "node:test";
|
|
|
7
7
|
import {
|
|
8
8
|
STATUSES,
|
|
9
9
|
autoDone,
|
|
10
|
+
carriedPending,
|
|
10
11
|
classify,
|
|
11
12
|
closeResolved,
|
|
12
13
|
describeDoctor,
|
|
@@ -16,7 +17,9 @@ import {
|
|
|
16
17
|
formatDoctor,
|
|
17
18
|
formatExplanation,
|
|
18
19
|
formatStatus,
|
|
20
|
+
pollOnce,
|
|
19
21
|
readState,
|
|
22
|
+
recordPending,
|
|
20
23
|
transition,
|
|
21
24
|
} from "./inbox-bridge.mjs";
|
|
22
25
|
|
|
@@ -100,6 +103,89 @@ test("a fact the repository no longer reports is closed", () => {
|
|
|
100
103
|
assert.equal(closed.state.events["other/r#run:3"].status, "delivered");
|
|
101
104
|
});
|
|
102
105
|
|
|
106
|
+
test("a fact nobody was told about is not closed by the source going quiet", () => {
|
|
107
|
+
// An issue is reported once. If a poll finds a session busy, the event is
|
|
108
|
+
// held; the next poll has nothing to report, and closing it there would drop
|
|
109
|
+
// the very news a wakeup was waiting on.
|
|
110
|
+
const state = {
|
|
111
|
+
events: {
|
|
112
|
+
"o/r#issue:4:author:2026-11-17T12:25:51Z": {
|
|
113
|
+
status: "pending",
|
|
114
|
+
at: AT,
|
|
115
|
+
kind: "issue",
|
|
116
|
+
attempts: 0,
|
|
117
|
+
},
|
|
118
|
+
"o/r#issue:3:author:2026-11-16T19:30:22Z": {
|
|
119
|
+
status: "pending",
|
|
120
|
+
at: AT,
|
|
121
|
+
kind: "issue",
|
|
122
|
+
attempts: 1,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const closed = closeResolved(state, [], { at: AT, repos: ["o/r"] });
|
|
127
|
+
assert.deepEqual(closed.marked, ["o/r#issue:3:author:2026-11-16T19:30:22Z"]);
|
|
128
|
+
assert.equal(
|
|
129
|
+
closed.state.events["o/r#issue:4:author:2026-11-17T12:25:51Z"].status,
|
|
130
|
+
"pending",
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("an event held while everyone was busy reaches a later poll", () => {
|
|
135
|
+
// The fact a wakeup waits for is often reported once. Poll 1 sees the issue;
|
|
136
|
+
// the plugin holds it because every session is busy. Poll 2 has nothing new to
|
|
137
|
+
// report — the issue was never reopened — so the event has to be carried over
|
|
138
|
+
// from the queue, or it is simply gone.
|
|
139
|
+
const root = mkdtempSync(join(tmpdir(), "inbox-held-"));
|
|
140
|
+
const answer = (payload) => () => JSON.stringify(payload);
|
|
141
|
+
try {
|
|
142
|
+
const issue = {
|
|
143
|
+
key: "o/r#issue:5",
|
|
144
|
+
kind: "issue",
|
|
145
|
+
role: "author",
|
|
146
|
+
title: "wakeup test",
|
|
147
|
+
url: "https://example.test/issues/5",
|
|
148
|
+
};
|
|
149
|
+
const first = pollOnce(root, {
|
|
150
|
+
at: "2026-11-17T12:40:00Z",
|
|
151
|
+
execFile: answer({ fresh: [issue], repos: ["o/r"] }),
|
|
152
|
+
});
|
|
153
|
+
assert.deepEqual(
|
|
154
|
+
first.pending.map((event) => event.key),
|
|
155
|
+
["o/r#issue:5"],
|
|
156
|
+
);
|
|
157
|
+
const second = pollOnce(root, {
|
|
158
|
+
at: "2026-11-17T12:41:00Z",
|
|
159
|
+
execFile: answer({ fresh: [], repos: ["o/r"] }),
|
|
160
|
+
});
|
|
161
|
+
assert.deepEqual(
|
|
162
|
+
second.events.map((event) => event.key),
|
|
163
|
+
["o/r#issue:5"],
|
|
164
|
+
);
|
|
165
|
+
assert.equal(second.events[0].title, "wakeup test");
|
|
166
|
+
assert.equal(second.events[0].carried, true);
|
|
167
|
+
|
|
168
|
+
// Delivered once, it stops being carried: the agent has been told.
|
|
169
|
+
const queue = readState(join(root, ".work", "inbox-bridge", "state.json"));
|
|
170
|
+
const delivered = transition(queue, ["o/r#issue:5"], "delivered", "2026-11-17T12:42:00Z");
|
|
171
|
+
const carried = carriedPending(delivered.state, [], { now: Date.parse("2026-11-17T12:43:00Z") });
|
|
172
|
+
assert.deepEqual(carried, []);
|
|
173
|
+
|
|
174
|
+
// Past the window a notice nobody received is no longer news.
|
|
175
|
+
const stale = recordPending(
|
|
176
|
+
{ events: {} },
|
|
177
|
+
[issue],
|
|
178
|
+
"2026-11-17T12:40:00Z",
|
|
179
|
+
);
|
|
180
|
+
assert.deepEqual(
|
|
181
|
+
carriedPending(stale.state, [], { now: Date.parse("2026-11-17T19:00:00Z") }),
|
|
182
|
+
[],
|
|
183
|
+
);
|
|
184
|
+
} finally {
|
|
185
|
+
rmSync(root, { recursive: true, force: true, maxRetries: 3 });
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
103
189
|
test("classify splits events by the state they carry", () => {
|
|
104
190
|
const events = [
|
|
105
191
|
{ key: "ci:1", kind: "ci" },
|