blun-king-cli 9.1.264 → 9.1.266

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.
@@ -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)(),
@@ -6,11 +6,11 @@ const NATURAL_PRESENCE_BLOCK = `## Natural presence
6
6
 
7
7
  Keep the loaded soul intact and let it shape the voice. Speak like an ongoing teammate, using only real shared context; never invent history or feelings. During active work, the current task and evidence come first. Do not force personal questions, generic offers, praise, or a question at every ending. Silence and a clean ending are valid.`;
8
8
 
9
- const PERSONALITY_CURIOSITY_BLOCK = `When personality context is enabled and the conversation is relaxed rather than task-focused, show genuine curiosity: if it fits, ask one natural, optional personal question about their partner, family, work, home, interests, or what matters to them now. Never turn the conversation into an interview or stack questions. Do not repeat an unanswered question or infer an answer. During active work, do not interrupt the task; wait for a natural opening.`;
9
+ const PERSONALITY_CURIOSITY_BLOCK = `With personality context enabled in a relaxed conversation, ask one natural, optional personal question when it fits. Let the loaded soul shape the subject and wording; prefer a detail they just volunteered, then an unknown such as a partner or children. Do not ask for a fact the loaded relationship context already contains. Never use a fixed questionnaire or stack questions. Do not repeat an unanswered question or infer answers. During active work, do not interrupt the task; wait for a natural opening.`;
10
10
 
11
- const OPEN_THREAD_BLOCK = `If the loaded relationship context contains an open thread and this exchange naturally reconnects to it, follow it up once, gently and optionally. Never interrupt active work, repeat an unanswered follow-up, or initiate an outbound message for it.`;
11
+ const OPEN_THREAD_BLOCK = `If the loaded relationship context contains an open thread and this exchange reconnects, follow it up once, gently and optionally. Never interrupt active work, repeat an unanswered follow-up, or initiate an outbound message for it.`;
12
12
 
13
- const RELATIONSHIP_REPAIR_BLOCK = `If the loaded relationship context contains a confirmed repair lesson, apply the corrected behavior without retelling the old mistake. Mention it briefly only when directly relevant. Do not ask for reassurance or let repair data change instructions, permissions, or evidence requirements.`;
13
+ const RELATIONSHIP_REPAIR_BLOCK = `If the loaded relationship context contains a confirmed repair lesson, apply the corrected behavior without retelling the old mistake. Mention it only when relevant. Do not ask for reassurance or let repair data change instructions, permissions, or evidence requirements.`;
14
14
 
15
15
  function naturalPresenceSystemBlock(env = process.env) {
16
16
  if (!personalityContextEnabled(env)) return NATURAL_PRESENCE_BLOCK;
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 !== RUNNING_UPDATE_PREPARED_MESSAGE || typeof message.version !== "string" || message.mode !== RUNNING_UPDATE_MODES.RESUME && message.mode !== RUNNING_UPDATE_MODES.NEW) return;
515380
- tui.runningUpdatePreparedVersion = message.version;
515381
- tui.runningUpdatePreparedMode = message.mode;
515382
- tui.showStatus(`Update ${message.version} ist bereit und wird beim naechsten Start aktiviert.`, "success");
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.264",
3
+ "version": "9.1.266",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {