patchcord 0.5.4 → 0.5.5
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/.claude-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/scripts/subscribe.mjs +31 -0
package/package.json
CHANGED
package/scripts/subscribe.mjs
CHANGED
|
@@ -102,6 +102,27 @@ async function fetchTicket(baseUrl, token) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
// Check if there are messages already pending in the inbox at the moment
|
|
106
|
+
// we connect (or reconnect). Realtime only delivers FUTURE INSERTs, so
|
|
107
|
+
// anything queued before we joined is invisible until the agent calls
|
|
108
|
+
// inbox() manually. Emit a stdout line when there's a pending queue so
|
|
109
|
+
// Monitor wakes the agent the same way a real arrival does.
|
|
110
|
+
async function drainQueueOnce(baseUrl, token) {
|
|
111
|
+
const res = await httpJson(`${baseUrl}/api/inbox?count_only=1&limit=100`, {
|
|
112
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
113
|
+
});
|
|
114
|
+
if (res.status !== 200) {
|
|
115
|
+
throw new Error(`inbox HTTP ${res.status}`);
|
|
116
|
+
}
|
|
117
|
+
let count = 0;
|
|
118
|
+
try {
|
|
119
|
+
count = JSON.parse(res.body).pending_count ?? 0;
|
|
120
|
+
} catch (_) {}
|
|
121
|
+
if (count > 0) {
|
|
122
|
+
process.stdout.write(`PATCHCORD: ${count} waiting in inbox\n`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
105
126
|
function writePidfile(path) {
|
|
106
127
|
try {
|
|
107
128
|
writeFileSync(path, String(process.pid), { flag: "wx" });
|
|
@@ -233,6 +254,16 @@ function runOnce(ticket, baseUrl, token, refreshTicket) {
|
|
|
233
254
|
})
|
|
234
255
|
);
|
|
235
256
|
}
|
|
257
|
+
|
|
258
|
+
// Drain any messages already in the queue when we connected.
|
|
259
|
+
// Realtime only delivers FUTURE INSERTs — anything pending before
|
|
260
|
+
// we joined (or that arrived during a reconnect gap) wouldn't
|
|
261
|
+
// otherwise wake the agent. Fire-and-forget: a transient HTTP
|
|
262
|
+
// failure here just means we miss queued messages this round;
|
|
263
|
+
// the next reconnect retries.
|
|
264
|
+
drainQueueOnce(baseUrl, token).catch((e) => {
|
|
265
|
+
process.stderr.write(`subscribe: queue check failed: ${e.message}\n`);
|
|
266
|
+
});
|
|
236
267
|
heartbeatTimer = setInterval(() => {
|
|
237
268
|
try {
|
|
238
269
|
ws.send(
|