blun-king-cli 9.1.264 → 9.1.265
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/bin/launcher-runtime.js +101 -0
- package/blun.mjs +55 -5
- package/package.json +1 -1
package/bin/launcher-runtime.js
CHANGED
|
@@ -29,7 +29,11 @@ const { repairConfiguredNativeModules } = require('./native-module-repair');
|
|
|
29
29
|
const { acquireSharedRuntimeLease, tryAcquireUpdateLease } = require('./update-lease');
|
|
30
30
|
const { compareSemver, runExplicitUpdate, runUpdateNotice } = require('./update-notice');
|
|
31
31
|
const {
|
|
32
|
+
RUNNING_UPDATE_HANDOFF_ACK_MESSAGE,
|
|
33
|
+
RUNNING_UPDATE_HANDOFF_EXIT_CODE,
|
|
34
|
+
RUNNING_UPDATE_HANDOFF_MESSAGE,
|
|
32
35
|
RUNNING_UPDATE_MODE_MESSAGE,
|
|
36
|
+
RUNNING_UPDATE_PREPARED_MESSAGE,
|
|
33
37
|
RUNTIME_EXIT_INTENT_MESSAGE,
|
|
34
38
|
activateRuntime,
|
|
35
39
|
clearActiveRuntime,
|
|
@@ -305,6 +309,7 @@ function shouldRecoverActivatedRuntime(result, recovery, options = {}) {
|
|
|
305
309
|
async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {}) {
|
|
306
310
|
const packageRoot = path.resolve(options.packageRoot || PKG);
|
|
307
311
|
let preparedTarget;
|
|
312
|
+
let pendingHandoff;
|
|
308
313
|
let updateStarted = false;
|
|
309
314
|
let runtimeReady = false;
|
|
310
315
|
let runtimeExitIntent = false;
|
|
@@ -359,6 +364,15 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
|
|
|
359
364
|
fromVersion: readPackageVersionAt(packageRoot),
|
|
360
365
|
toVersion: target.version,
|
|
361
366
|
}, { now: options.nowImpl });
|
|
367
|
+
if (child?.connected === true) {
|
|
368
|
+
try {
|
|
369
|
+
child.send({
|
|
370
|
+
type: RUNNING_UPDATE_PREPARED_MESSAGE,
|
|
371
|
+
version: target.version,
|
|
372
|
+
mode: runningUpdateMode,
|
|
373
|
+
});
|
|
374
|
+
} catch {}
|
|
375
|
+
}
|
|
362
376
|
Promise.resolve((options.pruneRunningUpdateReleases || pruneRunningUpdateReleases)(sharedHome, {
|
|
363
377
|
activePackageRoot: packageRoot,
|
|
364
378
|
})).catch((error) => options.onRunningUpdateError?.(error));
|
|
@@ -371,6 +385,34 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
|
|
|
371
385
|
};
|
|
372
386
|
const handleCoreMessage = (message, child) => {
|
|
373
387
|
if (message?.type === RUNTIME_EXIT_INTENT_MESSAGE) runtimeExitIntent = true;
|
|
388
|
+
if (message?.type === RUNNING_UPDATE_HANDOFF_MESSAGE
|
|
389
|
+
&& preparedTarget !== undefined
|
|
390
|
+
&& message.version === preparedTarget.version
|
|
391
|
+
&& message.mode === runningUpdateMode
|
|
392
|
+
&& typeof message.sessionId === 'string'
|
|
393
|
+
&& message.sessionId.length > 0
|
|
394
|
+
&& message.sessionId.length <= 256
|
|
395
|
+
&& !/[\u0000-\u001f\u007f]/u.test(message.sessionId)
|
|
396
|
+
&& resolveHandoffCwd(message.cwd, '') !== '') {
|
|
397
|
+
pendingHandoff = Object.freeze({
|
|
398
|
+
cwd: resolveHandoffCwd(message.cwd, cwd),
|
|
399
|
+
mode: message.mode,
|
|
400
|
+
sessionId: message.sessionId,
|
|
401
|
+
target: preparedTarget,
|
|
402
|
+
});
|
|
403
|
+
if (child?.connected === true) {
|
|
404
|
+
try {
|
|
405
|
+
child.send({
|
|
406
|
+
type: RUNNING_UPDATE_HANDOFF_ACK_MESSAGE,
|
|
407
|
+
version: preparedTarget.version,
|
|
408
|
+
mode: message.mode,
|
|
409
|
+
sessionId: message.sessionId,
|
|
410
|
+
});
|
|
411
|
+
} catch {
|
|
412
|
+
pendingHandoff = undefined;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
374
416
|
if (message?.type === RUNTIME_READY_MESSAGE) {
|
|
375
417
|
runtimeReady = true;
|
|
376
418
|
refreshRunningUpdateMode();
|
|
@@ -427,6 +469,65 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
|
|
|
427
469
|
const result = await core.completed;
|
|
428
470
|
clearRunningUpdatePoll();
|
|
429
471
|
if (existingMessageHandler) core.child.off('message', existingMessageHandler);
|
|
472
|
+
if (result.code === RUNNING_UPDATE_HANDOFF_EXIT_CODE && pendingHandoff !== undefined) {
|
|
473
|
+
const sharedHome = env.BLUN_SHARED_HOME;
|
|
474
|
+
const target = pendingHandoff.target;
|
|
475
|
+
const handoffArgs = handoffArgsForMode(args, pendingHandoff.mode, pendingHandoff.sessionId);
|
|
476
|
+
const handoffCwd = pendingHandoff.cwd;
|
|
477
|
+
const previousActive = (options.readActiveRuntime || readActiveRuntime)(sharedHome);
|
|
478
|
+
const nextCore = spawnCore(handoffArgs, env, handoffCwd, { packageRoot: target.packageRoot });
|
|
479
|
+
const nextLoaded = await nextCore.loaded;
|
|
480
|
+
const nextReady = nextLoaded && await (options.waitForRuntimeReady || waitForRuntimeReady)(
|
|
481
|
+
nextCore,
|
|
482
|
+
options.readyTimeoutMs,
|
|
483
|
+
);
|
|
484
|
+
if (nextReady) {
|
|
485
|
+
await (options.activateRuntime || activateRuntime)(sharedHome, target);
|
|
486
|
+
(options.clearPendingRuntime || clearPendingRuntime)(sharedHome, target);
|
|
487
|
+
const activatedAt = (options.nowImpl || Date.now)();
|
|
488
|
+
(options.recordRunningUpdateEvent || recordRunningUpdateEvent)(sharedHome, {
|
|
489
|
+
event: 'activated-at-safe-boundary',
|
|
490
|
+
fromVersion: readPackageVersionAt(packageRoot),
|
|
491
|
+
toVersion: target.version,
|
|
492
|
+
mode: pendingHandoff.mode,
|
|
493
|
+
}, { now: options.nowImpl });
|
|
494
|
+
return superviseProtectedCore(handoffArgs, env, handoffCwd, async () => {}, {
|
|
495
|
+
...options,
|
|
496
|
+
existingCore: nextCore,
|
|
497
|
+
packageRoot: target.packageRoot,
|
|
498
|
+
recoveryRuntime: {
|
|
499
|
+
activeRuntime: previousActive,
|
|
500
|
+
activatedAt,
|
|
501
|
+
packageRoot,
|
|
502
|
+
version: readPackageVersionAt(packageRoot),
|
|
503
|
+
},
|
|
504
|
+
staleActiveRuntime: undefined,
|
|
505
|
+
startupPendingRuntime: undefined,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
try { nextCore.child.kill(); } catch {}
|
|
509
|
+
(options.clearPendingRuntime || clearPendingRuntime)(sharedHome, target);
|
|
510
|
+
(options.recordRunningUpdateEvent || recordRunningUpdateEvent)(sharedHome, {
|
|
511
|
+
event: 'safe-boundary-start-failed',
|
|
512
|
+
fromVersion: readPackageVersionAt(packageRoot),
|
|
513
|
+
toVersion: target.version,
|
|
514
|
+
}, { now: options.nowImpl });
|
|
515
|
+
const fallback = spawnCore(handoffArgs, env, handoffCwd, { packageRoot });
|
|
516
|
+
const fallbackLoaded = await fallback.loaded;
|
|
517
|
+
const fallbackReady = fallbackLoaded && await (options.waitForRuntimeReady || waitForRuntimeReady)(
|
|
518
|
+
fallback,
|
|
519
|
+
options.readyTimeoutMs,
|
|
520
|
+
);
|
|
521
|
+
if (!fallbackReady) return 1;
|
|
522
|
+
return superviseProtectedCore(handoffArgs, env, handoffCwd, async () => {}, {
|
|
523
|
+
...options,
|
|
524
|
+
existingCore: fallback,
|
|
525
|
+
packageRoot,
|
|
526
|
+
recoveryRuntime: undefined,
|
|
527
|
+
staleActiveRuntime: undefined,
|
|
528
|
+
startupPendingRuntime: undefined,
|
|
529
|
+
});
|
|
530
|
+
}
|
|
430
531
|
const recovery = options.recoveryRuntime;
|
|
431
532
|
if (shouldRecoverActivatedRuntime(result, recovery, {
|
|
432
533
|
now: (options.nowImpl || Date.now)(),
|
package/blun.mjs
CHANGED
|
@@ -515372,14 +515372,64 @@ function notifyRunningRuntimeReady(tui) {
|
|
|
515372
515372
|
} catch {}
|
|
515373
515373
|
}
|
|
515374
515374
|
function requestRunningUpdateAtSafeBoundary(tui) {
|
|
515375
|
-
return false;
|
|
515375
|
+
if (tui.runningUpdateHandoffStarted || tui.isShuttingDown || !process.connected) return false;
|
|
515376
|
+
const version = tui.runningUpdatePreparedVersion;
|
|
515377
|
+
const mode = tui.runningUpdatePreparedMode;
|
|
515378
|
+
const sessionId = tui.getCurrentSessionId();
|
|
515379
|
+
const cwd = tui.state.appState.workDir;
|
|
515380
|
+
if (typeof version !== "string" || mode !== RUNNING_UPDATE_MODES.RESUME && mode !== RUNNING_UPDATE_MODES.NEW || sessionId.length === 0) return false;
|
|
515381
|
+
if (!isSafeRuntimeBoundary({
|
|
515382
|
+
isShuttingDown: tui.isShuttingDown,
|
|
515383
|
+
streamingPhase: tui.state.appState.streamingPhase,
|
|
515384
|
+
isCompacting: tui.state.appState.isCompacting,
|
|
515385
|
+
queuedMessages: tui.state.queuedMessages.length,
|
|
515386
|
+
activeToolCalls: tui.streamingUI.hasActiveToolCalls() ? 1 : 0,
|
|
515387
|
+
shellCommands: tui.shellOutputStreams.size,
|
|
515388
|
+
queueCommandRunning: tui.queueCommandRunning
|
|
515389
|
+
})) return false;
|
|
515390
|
+
tui.runningUpdateHandoffStarted = true;
|
|
515391
|
+
tui.showStatus(`Update ${version} ist bereit. Die sichere Update-Pause beginnt jetzt.`, "success");
|
|
515392
|
+
try {
|
|
515393
|
+
process.send({
|
|
515394
|
+
type: RUNNING_UPDATE_HANDOFF_MESSAGE,
|
|
515395
|
+
version,
|
|
515396
|
+
mode,
|
|
515397
|
+
sessionId,
|
|
515398
|
+
cwd
|
|
515399
|
+
}, (error) => {
|
|
515400
|
+
if (!error) return;
|
|
515401
|
+
tui.runningUpdateHandoffStarted = false;
|
|
515402
|
+
tui.showStatus("Das Update bleibt bereit und wird an der naechsten sicheren Grenze erneut versucht.", "warning");
|
|
515403
|
+
});
|
|
515404
|
+
return true;
|
|
515405
|
+
} catch {
|
|
515406
|
+
tui.runningUpdateHandoffStarted = false;
|
|
515407
|
+
return false;
|
|
515408
|
+
}
|
|
515376
515409
|
}
|
|
515377
515410
|
function installRunningUpdateListener(tui) {
|
|
515378
515411
|
const handler = (message) => {
|
|
515379
|
-
if (message?.type
|
|
515380
|
-
|
|
515381
|
-
|
|
515382
|
-
|
|
515412
|
+
if (message?.type === RUNNING_UPDATE_PREPARED_MESSAGE && typeof message.version === "string" && (message.mode === RUNNING_UPDATE_MODES.RESUME || message.mode === RUNNING_UPDATE_MODES.NEW)) {
|
|
515413
|
+
tui.runningUpdatePreparedVersion = message.version;
|
|
515414
|
+
tui.runningUpdatePreparedMode = message.mode;
|
|
515415
|
+
if (!requestRunningUpdateAtSafeBoundary(tui)) tui.showStatus(`Update ${message.version} ist bereit und wartet auf die naechste sichere Arbeitsgrenze.`, "success");
|
|
515416
|
+
return;
|
|
515417
|
+
}
|
|
515418
|
+
if (message?.type !== RUNNING_UPDATE_HANDOFF_ACK_MESSAGE || tui.runningUpdateHandoffStarted !== true || message.version !== tui.runningUpdatePreparedVersion || message.mode !== tui.runningUpdatePreparedMode || message.sessionId !== tui.getCurrentSessionId()) return;
|
|
515419
|
+
if (!isSafeRuntimeBoundary({
|
|
515420
|
+
isShuttingDown: tui.isShuttingDown,
|
|
515421
|
+
streamingPhase: tui.state.appState.streamingPhase,
|
|
515422
|
+
isCompacting: tui.state.appState.isCompacting,
|
|
515423
|
+
queuedMessages: tui.state.queuedMessages.length,
|
|
515424
|
+
activeToolCalls: tui.streamingUI.hasActiveToolCalls() ? 1 : 0,
|
|
515425
|
+
shellCommands: tui.shellOutputStreams.size,
|
|
515426
|
+
queueCommandRunning: tui.queueCommandRunning
|
|
515427
|
+
})) {
|
|
515428
|
+
tui.runningUpdateHandoffStarted = false;
|
|
515429
|
+
return;
|
|
515430
|
+
}
|
|
515431
|
+
tui.showStatus(`Update ${message.version} wird aktiviert. Die Sitzung wird automatisch fortgesetzt.`, "success");
|
|
515432
|
+
void tui.stop(RUNNING_UPDATE_HANDOFF_EXIT_CODE);
|
|
515383
515433
|
};
|
|
515384
515434
|
process.on("message", handler);
|
|
515385
515435
|
return () => process.off("message", handler);
|