dsh-inbox-bridge 2.19.1 → 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 +5 -0
- package/docs/index.json +3 -3
- package/package.json +1 -1
- package/scripts/inbox-bridge.mjs +104 -8
- package/scripts/inbox-bridge.test.mjs +58 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
## 2.19.2
|
|
2
|
+
|
|
3
|
+
- 被「留下」的事件现在会先记进队列(`attempts: 0` 表示记下来了但还没告诉任何人),下一次轮询即使来源已经不再报它,也会把它重新端上来。之前 issue 与评论这类只报一次的事实,在「所有会话都正忙」的那一轮被留下之后就永远消失了——唤醒因此永远等不到它要等的那条消息。
|
|
4
|
+
- 这类记录也会过期:六小时后没人收到就不再当新闻,队列不会无限长。
|
|
5
|
+
- 回归测试:`an event held while everyone was busy reaches a later poll`(取消结转后立刻红)。
|
|
1
6
|
## 2.19.1
|
|
2
7
|
|
|
3
8
|
- 一件还没告诉过任何人的事不再被「来源不再报出」直接收口。issue 与评论是只报一次的事实:某个会话正忙时事件被留下,下一次轮询本来就取不到第二次,原来的收口逻辑正好把它丢掉——于是事件永远等不到那个愿意叫人的时刻,唤醒也就永远不会发生。现在只有已经投递过的 key 才会因为事实不再成立而收口。
|
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/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,11 +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;
|
|
179
|
-
// Never told anyone about it: a fact we have not reported
|
|
180
|
-
// settled by the source going quiet. Issues and comments are
|
|
181
|
-
// so closing a held one would drop exactly the news a wakeup
|
|
182
|
-
// for.
|
|
183
|
-
if (entry.status === "pending" && (entry.attempts ?? 0) === 0)
|
|
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
|
+
}
|
|
184
259
|
events_[key] = { ...entry, status: "done", at };
|
|
185
260
|
marked.push(key);
|
|
186
261
|
}
|
|
@@ -266,8 +341,29 @@ export function pollOnce(root, options = {}) {
|
|
|
266
341
|
// `classify` also settles events that stop asking; that decision has to be
|
|
267
342
|
// written back, or the next poll reads them as delivered again.
|
|
268
343
|
const quiet = groups.done.length > 0 ? transition(closed.state, groups.done, "done", at) : closed;
|
|
269
|
-
|
|
270
|
-
|
|
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
|
+
};
|
|
271
367
|
}
|
|
272
368
|
|
|
273
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
|
|
|
@@ -128,6 +131,61 @@ test("a fact nobody was told about is not closed by the source going quiet", ()
|
|
|
128
131
|
);
|
|
129
132
|
});
|
|
130
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
|
+
|
|
131
189
|
test("classify splits events by the state they carry", () => {
|
|
132
190
|
const events = [
|
|
133
191
|
{ key: "ci:1", kind: "ci" },
|