overvues 0.0.1 → 0.4.10
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/README.md +58 -2
- package/dist/ansi.js +24 -0
- package/dist/attach-client.js +586 -0
- package/dist/auth-connect-browser.js +112 -0
- package/dist/auth-connect.js +306 -0
- package/dist/browser-bootstrap.js +190 -0
- package/dist/browser-loopback.js +289 -0
- package/dist/build-identity.js +6 -0
- package/dist/codex-reviewer-apparmor.json +4 -0
- package/dist/codex-reviewer-seccomp.json +1238 -0
- package/dist/codex-runtime-protocol.js +1 -0
- package/dist/codex-subscription.js +53 -0
- package/dist/config.js +297 -0
- package/dist/connect-comparison-code.js +26 -0
- package/dist/development-runner.js +109 -0
- package/dist/dns-doctor.js +390 -0
- package/dist/docker-names.js +47 -0
- package/dist/doctor.js +114 -0
- package/dist/gadget-job.js +804 -0
- package/dist/health-check.js +112 -0
- package/dist/help.js +71 -0
- package/dist/host-auth.js +22 -0
- package/dist/host-diagnostics.js +20 -0
- package/dist/host-runtime-identity.js +39 -0
- package/dist/host-runtime-metadata.js +56 -0
- package/dist/host-service.js +377 -0
- package/dist/host-stack.js +484 -0
- package/dist/host-supervisor.js +237 -0
- package/dist/host-update.js +387 -0
- package/dist/hub-address.js +100 -0
- package/dist/hub-client.js +459 -0
- package/dist/hub-kind.js +88 -0
- package/dist/identity.js +73 -0
- package/dist/index.js +185 -0
- package/dist/init.js +295 -0
- package/dist/isolated-run-cache.js +116 -0
- package/dist/local-stack.js +685 -0
- package/dist/machine-capacity.js +128 -0
- package/dist/managed-runner-image.js +13 -0
- package/dist/os-acted-record.js +49 -0
- package/dist/os-adapter.js +8190 -0
- package/dist/os-command.js +292 -0
- package/dist/os-handoff.js +274 -0
- package/dist/os-keychain.js +247 -0
- package/dist/os-machine.js +818 -0
- package/dist/os-owner.js +61 -0
- package/dist/os-private-file.js +98 -0
- package/dist/os-protocol.js +468 -0
- package/dist/os-session-store.js +133 -0
- package/dist/os-status.js +102 -0
- package/dist/picker.js +863 -0
- package/dist/portable-workspace-capability.js +60 -0
- package/dist/project-environment-capability.js +62 -0
- package/dist/project-environment.js +28 -0
- package/dist/project-preparation.js +134 -0
- package/dist/readiness.js +28 -0
- package/dist/redaction.js +27 -0
- package/dist/reviewer-isolation-capability.js +61 -0
- package/dist/runner-api-auth.js +80 -0
- package/dist/runner-command-fence.js +536 -0
- package/dist/runner-inspection.js +57 -0
- package/dist/runner-inventory.js +587 -0
- package/dist/runner-server.js +2520 -0
- package/dist/runner-session.js +470 -0
- package/dist/runner-slug-folder.js +39 -0
- package/dist/runner-slug.js +40 -0
- package/dist/setup.js +139 -0
- package/dist/shutdown.js +102 -0
- package/dist/splash.js +65 -0
- package/dist/staged-workspaces.js +441 -0
- package/dist/staging-disk.js +97 -0
- package/dist/terminal-lane.js +339 -0
- package/dist/terminal-recovery.js +502 -0
- package/licenses/capnweb.txt +23 -0
- package/licenses/moby-profiles.txt +212 -0
- package/licenses/ws.txt +22 -0
- package/package.json +28 -7
- package/cli.js +0 -2
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
export const CLI_RECOVERY_PAGE_SIZE = 1000;
|
|
2
|
+
export const CLI_COLD_PAGE_SIZE = 200;
|
|
3
|
+
export const CLI_MAX_PENDING_MESSAGES = 4096;
|
|
4
|
+
export const CLI_MAX_PENDING_BYTES = 8 * 1024 * 1024;
|
|
5
|
+
export const CLI_RECOVERY_DEADLINE_MS = 15_000;
|
|
6
|
+
export const CLI_RECOVERY_RETRY_DELAYS_MS = [250, 500, 1000, 2000, 4000];
|
|
7
|
+
export class CliTerminalRecoveryOverflowError extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("terminal_recovery_overflow");
|
|
10
|
+
this.name = "CliTerminalRecoveryOverflowError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function stableJson(value) {
|
|
14
|
+
const normalize = (candidate) => {
|
|
15
|
+
if (Array.isArray(candidate))
|
|
16
|
+
return candidate.map(normalize);
|
|
17
|
+
if (candidate && typeof candidate === "object") {
|
|
18
|
+
const result = {};
|
|
19
|
+
for (const key of Object.keys(candidate).sort()) {
|
|
20
|
+
const normalized = normalize(candidate[key]);
|
|
21
|
+
if (normalized !== undefined)
|
|
22
|
+
result[key] = normalized;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
return candidate;
|
|
27
|
+
};
|
|
28
|
+
return JSON.stringify(normalize(value));
|
|
29
|
+
}
|
|
30
|
+
function fingerprint(message) {
|
|
31
|
+
return stableJson({
|
|
32
|
+
id: message.id,
|
|
33
|
+
sessionId: message.sessionId,
|
|
34
|
+
seq: message.seq,
|
|
35
|
+
content: message.content,
|
|
36
|
+
localId: message.localId ?? null,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function sleep(ms) {
|
|
40
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
41
|
+
}
|
|
42
|
+
export async function readJsonResponseWithinLimit(response, maxBytes, onBytes) {
|
|
43
|
+
const declaredLength = Number(response.headers.get("content-length"));
|
|
44
|
+
if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {
|
|
45
|
+
await response.body?.cancel().catch(() => undefined);
|
|
46
|
+
throw new CliTerminalRecoveryOverflowError();
|
|
47
|
+
}
|
|
48
|
+
if (!response.body) {
|
|
49
|
+
const text = await response.text();
|
|
50
|
+
const receivedBytes = Buffer.byteLength(text);
|
|
51
|
+
if (receivedBytes > maxBytes)
|
|
52
|
+
throw new CliTerminalRecoveryOverflowError();
|
|
53
|
+
onBytes(receivedBytes);
|
|
54
|
+
return JSON.parse(text);
|
|
55
|
+
}
|
|
56
|
+
const reader = response.body.getReader();
|
|
57
|
+
const chunks = [];
|
|
58
|
+
let totalBytes = 0;
|
|
59
|
+
try {
|
|
60
|
+
while (true) {
|
|
61
|
+
const { done, value } = await reader.read();
|
|
62
|
+
if (done)
|
|
63
|
+
break;
|
|
64
|
+
totalBytes += value.byteLength;
|
|
65
|
+
if (totalBytes > maxBytes) {
|
|
66
|
+
await reader.cancel().catch(() => undefined);
|
|
67
|
+
throw new CliTerminalRecoveryOverflowError();
|
|
68
|
+
}
|
|
69
|
+
onBytes(totalBytes);
|
|
70
|
+
chunks.push(value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
await reader.cancel().catch(() => undefined);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
reader.releaseLock();
|
|
79
|
+
}
|
|
80
|
+
const payload = new Uint8Array(totalBytes);
|
|
81
|
+
let offset = 0;
|
|
82
|
+
for (const chunk of chunks) {
|
|
83
|
+
payload.set(chunk, offset);
|
|
84
|
+
offset += chunk.byteLength;
|
|
85
|
+
}
|
|
86
|
+
return JSON.parse(new TextDecoder().decode(payload));
|
|
87
|
+
}
|
|
88
|
+
export class CliTerminalRecovery {
|
|
89
|
+
options;
|
|
90
|
+
bySeq = new Map();
|
|
91
|
+
seqById = new Map();
|
|
92
|
+
bytes = 0;
|
|
93
|
+
fetchReservedBytes = 0;
|
|
94
|
+
fetchReservedMessages = 0;
|
|
95
|
+
activeFetchAbort = null;
|
|
96
|
+
lastCompletedSeq = 0;
|
|
97
|
+
baselineKnown = false;
|
|
98
|
+
state = "recovering";
|
|
99
|
+
faultCode;
|
|
100
|
+
fetching = false;
|
|
101
|
+
draining = false;
|
|
102
|
+
recoveryRequested = false;
|
|
103
|
+
disposed = false;
|
|
104
|
+
generation = 0;
|
|
105
|
+
deadlineAt = 0;
|
|
106
|
+
deadlineTimer = null;
|
|
107
|
+
constructor(options) {
|
|
108
|
+
this.options = options;
|
|
109
|
+
options.onStateChange(this.state);
|
|
110
|
+
}
|
|
111
|
+
get recoveryState() {
|
|
112
|
+
return this.state;
|
|
113
|
+
}
|
|
114
|
+
get recoveryFault() {
|
|
115
|
+
return this.faultCode;
|
|
116
|
+
}
|
|
117
|
+
get lastSeq() {
|
|
118
|
+
return this.lastCompletedSeq;
|
|
119
|
+
}
|
|
120
|
+
get pendingCount() {
|
|
121
|
+
return this.bySeq.size;
|
|
122
|
+
}
|
|
123
|
+
async startCold() {
|
|
124
|
+
const generation = this.begin(0, false, true);
|
|
125
|
+
const request = this.createFetchRequest(CLI_COLD_PAGE_SIZE);
|
|
126
|
+
if (!request)
|
|
127
|
+
return;
|
|
128
|
+
const page = await this.fetchWithRetry(request, generation);
|
|
129
|
+
if (!page || !this.current(generation))
|
|
130
|
+
return;
|
|
131
|
+
if (page.length > request.limit) {
|
|
132
|
+
this.fail("overflow");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.releaseFetchReservation();
|
|
136
|
+
const ordered = [...page].sort((left, right) => left.seq - right.seq);
|
|
137
|
+
this.lastCompletedSeq = ordered.length > 0 ? Math.max(0, ordered[0].seq - 1) : 0;
|
|
138
|
+
this.baselineKnown = true;
|
|
139
|
+
this.discardBaseline();
|
|
140
|
+
for (const message of ordered)
|
|
141
|
+
if (!this.accept(message))
|
|
142
|
+
return;
|
|
143
|
+
this.fetching = false;
|
|
144
|
+
await this.drain(generation, false);
|
|
145
|
+
}
|
|
146
|
+
recover() {
|
|
147
|
+
if (this.disposed || this.state === "fault" || !this.baselineKnown || this.fetching)
|
|
148
|
+
return;
|
|
149
|
+
if (this.draining) {
|
|
150
|
+
this.recoveryRequested = true;
|
|
151
|
+
if (this.state !== "recovering") {
|
|
152
|
+
this.state = "recovering";
|
|
153
|
+
this.faultCode = undefined;
|
|
154
|
+
this.options.onStateChange("recovering");
|
|
155
|
+
this.armDeadline(this.generation, true);
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const preserveDeadline = this.state === "recovering" && this.deadlineTimer !== null;
|
|
160
|
+
const generation = this.begin(this.lastCompletedSeq, true, false, preserveDeadline);
|
|
161
|
+
void this.fetchForward(this.lastCompletedSeq, generation);
|
|
162
|
+
}
|
|
163
|
+
acceptLive(message) {
|
|
164
|
+
if (this.disposed || this.state === "fault" || message.sessionId !== this.options.sessionId)
|
|
165
|
+
return;
|
|
166
|
+
if (this.baselineKnown && message.seq <= this.lastCompletedSeq)
|
|
167
|
+
return;
|
|
168
|
+
if (!this.accept(message) || !this.baselineKnown || this.fetching)
|
|
169
|
+
return;
|
|
170
|
+
if (!this.draining && message.seq > this.lastCompletedSeq + 1) {
|
|
171
|
+
this.recover();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
void this.drain(this.generation, false);
|
|
175
|
+
}
|
|
176
|
+
dispose() {
|
|
177
|
+
this.disposed = true;
|
|
178
|
+
this.generation += 1;
|
|
179
|
+
this.abortActiveFetch();
|
|
180
|
+
this.clearDeadline();
|
|
181
|
+
this.clearPending();
|
|
182
|
+
}
|
|
183
|
+
begin(baseline, known, clear, preserveDeadline = false) {
|
|
184
|
+
this.abortActiveFetch();
|
|
185
|
+
this.generation += 1;
|
|
186
|
+
if (clear)
|
|
187
|
+
this.clearPending();
|
|
188
|
+
this.lastCompletedSeq = baseline;
|
|
189
|
+
this.baselineKnown = known;
|
|
190
|
+
this.fetching = true;
|
|
191
|
+
this.recoveryRequested = false;
|
|
192
|
+
const notifyRecovering = this.state !== "recovering";
|
|
193
|
+
this.state = "recovering";
|
|
194
|
+
this.faultCode = undefined;
|
|
195
|
+
if (notifyRecovering)
|
|
196
|
+
this.options.onStateChange("recovering");
|
|
197
|
+
const generation = this.generation;
|
|
198
|
+
this.armDeadline(generation, !preserveDeadline);
|
|
199
|
+
return generation;
|
|
200
|
+
}
|
|
201
|
+
armDeadline(generation, resetDeadline) {
|
|
202
|
+
const now = (this.options.now ?? Date.now)();
|
|
203
|
+
if (resetDeadline) {
|
|
204
|
+
this.deadlineAt = now + (this.options.deadlineMs ?? CLI_RECOVERY_DEADLINE_MS);
|
|
205
|
+
}
|
|
206
|
+
this.clearDeadline();
|
|
207
|
+
this.deadlineTimer = setTimeout(() => {
|
|
208
|
+
if (this.current(generation) && this.state === "recovering")
|
|
209
|
+
this.fail("deadline");
|
|
210
|
+
}, Math.max(0, this.deadlineAt - now));
|
|
211
|
+
}
|
|
212
|
+
accept(message) {
|
|
213
|
+
if (message.sessionId !== this.options.sessionId ||
|
|
214
|
+
!message.id ||
|
|
215
|
+
!Number.isInteger(message.seq) ||
|
|
216
|
+
message.seq < 1) {
|
|
217
|
+
this.fail("collision");
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
if (this.baselineKnown && message.seq <= this.lastCompletedSeq)
|
|
221
|
+
return true;
|
|
222
|
+
const digest = fingerprint(message);
|
|
223
|
+
const bySequence = this.bySeq.get(message.seq);
|
|
224
|
+
if (bySequence) {
|
|
225
|
+
if (bySequence.fingerprint !== digest)
|
|
226
|
+
this.fail("collision");
|
|
227
|
+
return bySequence.fingerprint === digest;
|
|
228
|
+
}
|
|
229
|
+
const knownSeq = this.seqById.get(message.id);
|
|
230
|
+
if (knownSeq !== undefined) {
|
|
231
|
+
const byId = this.bySeq.get(knownSeq);
|
|
232
|
+
if (!byId || byId.fingerprint !== digest)
|
|
233
|
+
this.fail("collision");
|
|
234
|
+
return byId?.fingerprint === digest;
|
|
235
|
+
}
|
|
236
|
+
const payloadBytes = Buffer.byteLength(digest);
|
|
237
|
+
if (this.bySeq.size + this.fetchReservedMessages + 1 >
|
|
238
|
+
(this.options.maxMessages ?? CLI_MAX_PENDING_MESSAGES) ||
|
|
239
|
+
this.bytes + this.fetchReservedBytes + payloadBytes >
|
|
240
|
+
(this.options.maxBytes ?? CLI_MAX_PENDING_BYTES)) {
|
|
241
|
+
this.fail("overflow");
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
this.bySeq.set(message.seq, { message, fingerprint: digest, bytes: payloadBytes });
|
|
245
|
+
this.seqById.set(message.id, message.seq);
|
|
246
|
+
this.bytes += payloadBytes;
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
async fetchForward(cursor, generation) {
|
|
250
|
+
let nextCursor = cursor;
|
|
251
|
+
while (this.current(generation)) {
|
|
252
|
+
const request = this.createFetchRequest(CLI_RECOVERY_PAGE_SIZE, nextCursor);
|
|
253
|
+
if (!request)
|
|
254
|
+
return;
|
|
255
|
+
const page = await this.fetchWithRetry(request, generation);
|
|
256
|
+
if (!page || !this.current(generation))
|
|
257
|
+
return;
|
|
258
|
+
if (page.length > request.limit) {
|
|
259
|
+
this.fail("overflow");
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
this.releaseFetchReservation();
|
|
263
|
+
const ordered = [...page].sort((left, right) => left.seq - right.seq);
|
|
264
|
+
const advanced = ordered.reduce((max, message) => Math.max(max, message.seq), nextCursor);
|
|
265
|
+
if (ordered.length > 0 && advanced <= nextCursor) {
|
|
266
|
+
this.fail("non_progress");
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
for (const message of ordered)
|
|
270
|
+
if (!this.accept(message))
|
|
271
|
+
return;
|
|
272
|
+
if (ordered.length < request.limit)
|
|
273
|
+
break;
|
|
274
|
+
nextCursor = advanced;
|
|
275
|
+
}
|
|
276
|
+
if (!this.current(generation))
|
|
277
|
+
return;
|
|
278
|
+
this.fetching = false;
|
|
279
|
+
if (this.bySeq.size > 0 && !this.bySeq.has(this.lastCompletedSeq + 1)) {
|
|
280
|
+
this.fail("non_progress");
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
void this.drain(generation, true);
|
|
284
|
+
}
|
|
285
|
+
async fetchWithRetry(request, generation) {
|
|
286
|
+
this.fetchReservedMessages = request.limit;
|
|
287
|
+
let attempt = 0;
|
|
288
|
+
while (this.current(generation)) {
|
|
289
|
+
if (this.expired()) {
|
|
290
|
+
this.fail("deadline");
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
const remainingBytes = (this.options.maxBytes ?? CLI_MAX_PENDING_BYTES) - this.bytes;
|
|
294
|
+
if (remainingBytes <= 0) {
|
|
295
|
+
this.fail("overflow");
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
this.fetchReservedBytes = 0;
|
|
299
|
+
const abortController = new AbortController();
|
|
300
|
+
this.activeFetchAbort = abortController;
|
|
301
|
+
try {
|
|
302
|
+
const page = await this.options.fetchPage({
|
|
303
|
+
...request,
|
|
304
|
+
maxBytes: remainingBytes,
|
|
305
|
+
signal: abortController.signal,
|
|
306
|
+
onBytes: (receivedBytes) => this.reserveFetchBytes(receivedBytes, generation),
|
|
307
|
+
});
|
|
308
|
+
if (this.activeFetchAbort === abortController)
|
|
309
|
+
this.activeFetchAbort = null;
|
|
310
|
+
if (this.expired()) {
|
|
311
|
+
this.fail("deadline");
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
return page;
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
if (this.activeFetchAbort === abortController)
|
|
318
|
+
this.activeFetchAbort = null;
|
|
319
|
+
this.fetchReservedBytes = 0;
|
|
320
|
+
if (!this.current(generation))
|
|
321
|
+
return null;
|
|
322
|
+
if (error instanceof CliTerminalRecoveryOverflowError) {
|
|
323
|
+
this.fail("overflow");
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
const delayMs = CLI_RECOVERY_RETRY_DELAYS_MS[attempt];
|
|
327
|
+
if (delayMs === undefined) {
|
|
328
|
+
this.fail("fetch_failed");
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
attempt += 1;
|
|
332
|
+
if ((this.options.now ?? Date.now)() + delayMs >= this.deadlineAt) {
|
|
333
|
+
this.fail("deadline");
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
await (this.options.sleep ?? sleep)(delayMs);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
createFetchRequest(pageSize, afterSeq) {
|
|
342
|
+
const remainingMessages = (this.options.maxMessages ?? CLI_MAX_PENDING_MESSAGES) - this.bySeq.size;
|
|
343
|
+
const remainingBytes = (this.options.maxBytes ?? CLI_MAX_PENDING_BYTES) - this.bytes;
|
|
344
|
+
if (remainingMessages <= 0 || remainingBytes <= 0) {
|
|
345
|
+
this.fail("overflow");
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
limit: Math.min(pageSize, remainingMessages),
|
|
350
|
+
...(afterSeq !== undefined ? { afterSeq } : {}),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
reserveFetchBytes(receivedBytes, generation) {
|
|
354
|
+
if (!this.current(generation) ||
|
|
355
|
+
!Number.isInteger(receivedBytes) ||
|
|
356
|
+
receivedBytes < this.fetchReservedBytes ||
|
|
357
|
+
this.bytes + receivedBytes > (this.options.maxBytes ?? CLI_MAX_PENDING_BYTES)) {
|
|
358
|
+
throw new CliTerminalRecoveryOverflowError();
|
|
359
|
+
}
|
|
360
|
+
this.fetchReservedBytes = receivedBytes;
|
|
361
|
+
}
|
|
362
|
+
releaseFetchReservation() {
|
|
363
|
+
this.fetchReservedBytes = 0;
|
|
364
|
+
this.fetchReservedMessages = 0;
|
|
365
|
+
}
|
|
366
|
+
abortActiveFetch() {
|
|
367
|
+
const active = this.activeFetchAbort;
|
|
368
|
+
this.activeFetchAbort = null;
|
|
369
|
+
active?.abort();
|
|
370
|
+
this.releaseFetchReservation();
|
|
371
|
+
}
|
|
372
|
+
async drain(generation, fetchedForward) {
|
|
373
|
+
if (!this.current(generation) || this.draining || this.fetching)
|
|
374
|
+
return;
|
|
375
|
+
this.draining = true;
|
|
376
|
+
try {
|
|
377
|
+
while (this.current(generation)) {
|
|
378
|
+
const pending = this.bySeq.get(this.lastCompletedSeq + 1);
|
|
379
|
+
if (!pending)
|
|
380
|
+
break;
|
|
381
|
+
await this.options.write(pending.message);
|
|
382
|
+
if (!this.current(generation))
|
|
383
|
+
return;
|
|
384
|
+
if (this.expired() && this.state === "recovering") {
|
|
385
|
+
this.fail("deadline");
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
this.bySeq.delete(pending.message.seq);
|
|
389
|
+
this.seqById.delete(pending.message.id);
|
|
390
|
+
this.bytes -= pending.bytes;
|
|
391
|
+
this.lastCompletedSeq = pending.message.seq;
|
|
392
|
+
this.options.onSequenceComplete(this.lastCompletedSeq);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
this.fail("non_progress");
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
finally {
|
|
400
|
+
this.draining = false;
|
|
401
|
+
}
|
|
402
|
+
if (!this.current(generation))
|
|
403
|
+
return;
|
|
404
|
+
if (this.recoveryRequested) {
|
|
405
|
+
this.recoveryRequested = false;
|
|
406
|
+
this.recover();
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (this.bySeq.size > 0) {
|
|
410
|
+
if (fetchedForward)
|
|
411
|
+
this.fail("non_progress");
|
|
412
|
+
else
|
|
413
|
+
this.recover();
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
this.fetching = false;
|
|
417
|
+
this.recoveryRequested = false;
|
|
418
|
+
this.clearDeadline();
|
|
419
|
+
this.state = "ready";
|
|
420
|
+
this.options.onStateChange("ready");
|
|
421
|
+
}
|
|
422
|
+
fail(code) {
|
|
423
|
+
if (this.disposed || this.state === "fault")
|
|
424
|
+
return;
|
|
425
|
+
this.generation += 1;
|
|
426
|
+
this.fetching = false;
|
|
427
|
+
this.recoveryRequested = false;
|
|
428
|
+
this.abortActiveFetch();
|
|
429
|
+
this.clearDeadline();
|
|
430
|
+
this.state = "fault";
|
|
431
|
+
this.faultCode = code;
|
|
432
|
+
this.options.onStateChange("fault", code);
|
|
433
|
+
}
|
|
434
|
+
discardBaseline() {
|
|
435
|
+
for (const [seq, pending] of this.bySeq) {
|
|
436
|
+
if (seq > this.lastCompletedSeq)
|
|
437
|
+
continue;
|
|
438
|
+
this.bySeq.delete(seq);
|
|
439
|
+
this.seqById.delete(pending.message.id);
|
|
440
|
+
this.bytes -= pending.bytes;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
clearPending() {
|
|
444
|
+
this.bySeq.clear();
|
|
445
|
+
this.seqById.clear();
|
|
446
|
+
this.bytes = 0;
|
|
447
|
+
this.releaseFetchReservation();
|
|
448
|
+
}
|
|
449
|
+
expired() {
|
|
450
|
+
return (this.options.now ?? Date.now)() >= this.deadlineAt;
|
|
451
|
+
}
|
|
452
|
+
current(generation) {
|
|
453
|
+
return !this.disposed && generation === this.generation && this.state !== "fault";
|
|
454
|
+
}
|
|
455
|
+
clearDeadline() {
|
|
456
|
+
if (this.deadlineTimer)
|
|
457
|
+
clearTimeout(this.deadlineTimer);
|
|
458
|
+
this.deadlineTimer = null;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/** Wait for both the stdout callback and drain when Node reports backpressure. */
|
|
462
|
+
export function writeStdoutWithBackpressure(data) {
|
|
463
|
+
if (!data)
|
|
464
|
+
return Promise.resolve();
|
|
465
|
+
return new Promise((resolve, reject) => {
|
|
466
|
+
let callbackComplete = false;
|
|
467
|
+
let drainComplete = true;
|
|
468
|
+
let settled = false;
|
|
469
|
+
const onError = (error) => {
|
|
470
|
+
if (settled)
|
|
471
|
+
return;
|
|
472
|
+
settled = true;
|
|
473
|
+
process.stdout.removeListener("error", onError);
|
|
474
|
+
reject(error);
|
|
475
|
+
};
|
|
476
|
+
const finish = () => {
|
|
477
|
+
if (!settled && callbackComplete && drainComplete) {
|
|
478
|
+
settled = true;
|
|
479
|
+
process.stdout.removeListener("error", onError);
|
|
480
|
+
resolve();
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
try {
|
|
484
|
+
process.stdout.once("error", onError);
|
|
485
|
+
const accepted = process.stdout.write(data, () => {
|
|
486
|
+
callbackComplete = true;
|
|
487
|
+
finish();
|
|
488
|
+
});
|
|
489
|
+
if (!accepted) {
|
|
490
|
+
drainComplete = false;
|
|
491
|
+
process.stdout.once("drain", () => {
|
|
492
|
+
drainComplete = true;
|
|
493
|
+
finish();
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
process.stdout.removeListener("error", onError);
|
|
499
|
+
reject(error);
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
capnweb (https://github.com/cloudflare/capnweb), bundled into dist/os-adapter.js
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 Cloudflare, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|