@bivy/bivy 0.16.18-staging.7 → 0.16.18-staging.8
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/dist/session/run-terminal.js +5 -3
- package/dist/terminal.js +45 -2
- package/package.json +1 -1
|
@@ -345,12 +345,14 @@ export function createRunTerminals(deps) {
|
|
|
345
345
|
const discover = SESSION_DISCOVERY_BY_AGENT[agent];
|
|
346
346
|
if (!discover)
|
|
347
347
|
return undefined;
|
|
348
|
-
|
|
348
|
+
const attempts = Math.max(1, Math.floor(deps.takeoverDiscoveryAttempts ?? TAKEOVER_DISCOVERY_ATTEMPTS));
|
|
349
|
+
const delayMs = Math.max(0, Math.floor(deps.takeoverDiscoveryDelayMs ?? TAKEOVER_DISCOVERY_DELAY_MS));
|
|
350
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
349
351
|
const ref = await discover(workspace, createdAt);
|
|
350
352
|
if (ref)
|
|
351
353
|
return ref;
|
|
352
|
-
if (attempt + 1 <
|
|
353
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
354
|
+
if (delayMs > 0 && attempt + 1 < attempts) {
|
|
355
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
354
356
|
}
|
|
355
357
|
}
|
|
356
358
|
return undefined;
|
package/dist/terminal.js
CHANGED
|
@@ -196,6 +196,8 @@ export class TerminalManager {
|
|
|
196
196
|
env,
|
|
197
197
|
});
|
|
198
198
|
const now = Date.now();
|
|
199
|
+
let resolveExit;
|
|
200
|
+
const exitPromise = new Promise((resolve) => { resolveExit = resolve; });
|
|
199
201
|
const entry = {
|
|
200
202
|
proc,
|
|
201
203
|
workspace: options.workspace,
|
|
@@ -209,6 +211,8 @@ export class TerminalManager {
|
|
|
209
211
|
flushTimer: null,
|
|
210
212
|
closed: false,
|
|
211
213
|
onData: options.onData,
|
|
214
|
+
exitPromise,
|
|
215
|
+
resolveExit,
|
|
212
216
|
};
|
|
213
217
|
// Register the opener as a sized client so a later, smaller client shrinks
|
|
214
218
|
// the PTY to the min of the two rather than clobbering the opener's size.
|
|
@@ -269,7 +273,12 @@ export class TerminalManager {
|
|
|
269
273
|
flush();
|
|
270
274
|
entry.closed = true;
|
|
271
275
|
this.terminals.delete(id);
|
|
272
|
-
|
|
276
|
+
try {
|
|
277
|
+
options.onExit(exitCode, signal, entry.buffer);
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
entry.resolveExit();
|
|
281
|
+
}
|
|
273
282
|
});
|
|
274
283
|
return id;
|
|
275
284
|
}
|
|
@@ -347,6 +356,19 @@ export class TerminalManager {
|
|
|
347
356
|
const entry = this.terminals.get(id);
|
|
348
357
|
if (!entry)
|
|
349
358
|
return false;
|
|
359
|
+
this.closeEntry(id, entry);
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
/** Close a terminal and wait for the underlying PTY process to report exit. */
|
|
363
|
+
async closeAndWait(id, timeoutMs = 2000) {
|
|
364
|
+
const entry = this.terminals.get(id);
|
|
365
|
+
if (!entry)
|
|
366
|
+
return false;
|
|
367
|
+
this.closeEntry(id, entry);
|
|
368
|
+
await waitForExit(entry.exitPromise, timeoutMs);
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
closeEntry(id, entry) {
|
|
350
372
|
this.terminals.delete(id);
|
|
351
373
|
// Drop any queued output — the client asked to close, so don't emit a
|
|
352
374
|
// trailing batch (which would fire onData for a terminal it has torn down).
|
|
@@ -363,7 +385,6 @@ export class TerminalManager {
|
|
|
363
385
|
catch {
|
|
364
386
|
// already gone
|
|
365
387
|
}
|
|
366
|
-
return true;
|
|
367
388
|
}
|
|
368
389
|
has(id) {
|
|
369
390
|
return this.terminals.has(id);
|
|
@@ -421,6 +442,28 @@ export class TerminalManager {
|
|
|
421
442
|
for (const id of [...this.terminals.keys()])
|
|
422
443
|
this.close(id);
|
|
423
444
|
}
|
|
445
|
+
/** Kill every terminal and wait for node-pty to release its child handles. */
|
|
446
|
+
async disposeAllAndWait(timeoutMs = 2000) {
|
|
447
|
+
const exits = [];
|
|
448
|
+
for (const [id, entry] of [...this.terminals]) {
|
|
449
|
+
this.closeEntry(id, entry);
|
|
450
|
+
exits.push(waitForExit(entry.exitPromise, timeoutMs));
|
|
451
|
+
}
|
|
452
|
+
await Promise.all(exits);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async function waitForExit(exitPromise, timeoutMs) {
|
|
456
|
+
let timer;
|
|
457
|
+
try {
|
|
458
|
+
await Promise.race([
|
|
459
|
+
exitPromise,
|
|
460
|
+
new Promise((resolve) => { timer = setTimeout(resolve, timeoutMs); }),
|
|
461
|
+
]);
|
|
462
|
+
}
|
|
463
|
+
finally {
|
|
464
|
+
if (timer)
|
|
465
|
+
clearTimeout(timer);
|
|
466
|
+
}
|
|
424
467
|
}
|
|
425
468
|
function clampDim(value, fallback) {
|
|
426
469
|
const n = Math.floor(Number(value));
|
package/package.json
CHANGED