blun-king-cli 9.1.220 → 9.1.222

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,16 +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_EXIT_CODE,
33
- RUNNING_UPDATE_HANDOFF_ACK_MESSAGE,
34
- RUNNING_UPDATE_HANDOFF_MESSAGE,
35
32
  RUNNING_UPDATE_MODE_MESSAGE,
36
- RUNNING_UPDATE_PREPARED_MESSAGE,
37
33
  RUNTIME_EXIT_INTENT_MESSAGE,
38
34
  activateRuntime,
39
35
  clearActiveRuntime,
40
36
  handoffArgsForMode,
41
- handoffRuntime,
42
37
  prepareRunningUpdate,
43
38
  pruneRunningUpdateReleases,
44
39
  recordRunningUpdateEvent,
@@ -283,9 +278,6 @@ function shouldRecoverActivatedRuntime(result, recovery, options = {}) {
283
278
  async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {}) {
284
279
  const packageRoot = path.resolve(options.packageRoot || PKG);
285
280
  let preparedTarget;
286
- let handoffSessionId;
287
- let handoffMode;
288
- let handoffCwd = cwd;
289
281
  let updateStarted = false;
290
282
  let runtimeReady = false;
291
283
  let runtimeExitIntent = false;
@@ -297,9 +289,6 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
297
289
  const persistedMode = readRunningUpdateMode(env.BLUN_HOME);
298
290
  if (persistedMode !== runningUpdateMode) {
299
291
  runningUpdateMode = persistedMode;
300
- handoffSessionId = undefined;
301
- handoffMode = undefined;
302
- handoffCwd = cwd;
303
292
  }
304
293
  };
305
294
  const clearRunningUpdatePoll = () => {
@@ -317,20 +306,6 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
317
306
  else scheduleNextPreparation(child);
318
307
  });
319
308
  };
320
- const announcePrepared = (child) => {
321
- if (preparedTarget === undefined || !automaticMode() || child.connected !== true) return;
322
- try {
323
- child.send({
324
- type: RUNNING_UPDATE_PREPARED_MESSAGE,
325
- version: preparedTarget.version,
326
- mode: runningUpdateMode,
327
- }, (error) => {
328
- if (error) options.onRunningUpdateError?.(error);
329
- });
330
- } catch (error) {
331
- options.onRunningUpdateError?.(error);
332
- }
333
- };
334
309
  const startPreparation = (child) => {
335
310
  if (updateStarted || options.runningUpdate === false || !automaticMode()) return;
336
311
  updateStarted = true;
@@ -361,7 +336,6 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
361
336
  activePackageRoot: packageRoot,
362
337
  })).catch((error) => options.onRunningUpdateError?.(error));
363
338
  clearRunningUpdatePoll();
364
- announcePrepared(child);
365
339
  }).catch((error) => {
366
340
  updateStarted = false;
367
341
  options.onRunningUpdateError?.(error);
@@ -378,48 +352,14 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
378
352
  }
379
353
  if (message?.type === RUNNING_UPDATE_MODE_MESSAGE && typeof message.mode === 'string') {
380
354
  runningUpdateMode = normalizeRunningUpdateMode(message.mode);
381
- handoffSessionId = undefined;
382
- handoffMode = undefined;
383
- handoffCwd = cwd;
384
355
  clearRunningUpdatePoll();
385
356
  if (automaticMode()) {
386
- if (preparedTarget !== undefined) announcePrepared(child);
387
- else if (runtimeReady) {
357
+ if (preparedTarget === undefined && runtimeReady) {
388
358
  updateStarted = false;
389
359
  startPreparation(child);
390
360
  }
391
361
  } else if (runtimeReady) scheduleNextPreparation(child);
392
362
  }
393
- if (message?.type === RUNNING_UPDATE_HANDOFF_MESSAGE
394
- && typeof message.sessionId === 'string'
395
- && message.sessionId.length > 0
396
- && message.mode === runningUpdateMode
397
- && automaticMode()) {
398
- handoffSessionId = message.sessionId;
399
- handoffMode = runningUpdateMode;
400
- handoffCwd = resolveHandoffCwd(message.cwd, cwd);
401
- if (preparedTarget !== undefined && message.version === preparedTarget.version) {
402
- try {
403
- (options.stageRuntime || stageRuntime)(env.BLUN_SHARED_HOME, preparedTarget, {
404
- mode: handoffMode,
405
- sessionId: handoffSessionId,
406
- cwd: handoffCwd,
407
- });
408
- child.send({
409
- type: RUNNING_UPDATE_HANDOFF_ACK_MESSAGE,
410
- version: preparedTarget.version,
411
- mode: handoffMode,
412
- sessionId: handoffSessionId,
413
- }, (error) => {
414
- if (error) options.onRunningUpdateError?.(error);
415
- });
416
- } catch (error) {
417
- handoffSessionId = undefined;
418
- handoffMode = undefined;
419
- options.onRunningUpdateError?.(error);
420
- }
421
- }
422
- }
423
363
  };
424
364
  const spawnCore = options.spawnProtectedCore || spawnProtectedCore;
425
365
  const core = options.existingCore || spawnCore(args, env, cwd, {
@@ -460,67 +400,6 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
460
400
  const result = await core.completed;
461
401
  clearRunningUpdatePoll();
462
402
  if (existingMessageHandler) core.child.off('message', existingMessageHandler);
463
- if (result.code === RUNNING_UPDATE_HANDOFF_EXIT_CODE
464
- && preparedTarget !== undefined
465
- && handoffSessionId !== undefined
466
- && handoffMode !== undefined) {
467
- const previousActiveRuntime = (options.readActiveRuntime || readActiveRuntime)(env.BLUN_SHARED_HOME);
468
- const activatedAt = (options.nowImpl || Date.now)();
469
- const handoff = await handoffRuntime({
470
- target: preparedTarget,
471
- previous: { packageRoot, version: readPackageVersionAt(packageRoot) },
472
- sessionId: handoffSessionId,
473
- mode: handoffMode,
474
- args,
475
- probeTarget: options.probeRunningUpdate || (() => true),
476
- stopOld: async () => {},
477
- startCore: async ({ packageRoot: nextRoot, args: nextArgs }) => {
478
- const nextCore = spawnCore(nextArgs, env, handoffCwd, { packageRoot: nextRoot });
479
- const nextLoaded = await nextCore.loaded;
480
- const ready = nextLoaded && await waitForRuntimeReady(nextCore, options.readyTimeoutMs);
481
- if (!ready) {
482
- try { nextCore.child.kill(); } catch {}
483
- await nextCore.completed;
484
- }
485
- return { ...nextCore, ready };
486
- },
487
- activateTarget: async (target) => {
488
- await (options.activateRuntime || activateRuntime)(env.BLUN_SHARED_HOME, target);
489
- (options.clearPendingRuntime || clearPendingRuntime)(env.BLUN_SHARED_HOME, target);
490
- (options.recordRunningUpdateEvent || recordRunningUpdateEvent)(env.BLUN_SHARED_HOME, {
491
- event: 'activated',
492
- fromVersion: readPackageVersionAt(packageRoot),
493
- toVersion: target.version,
494
- }, { now: options.nowImpl });
495
- try {
496
- await (options.pruneRunningUpdateReleases || pruneRunningUpdateReleases)(env.BLUN_SHARED_HOME, {
497
- activePackageRoot: target.packageRoot,
498
- });
499
- } catch (error) {
500
- options.onRunningUpdateError?.(error);
501
- }
502
- },
503
- });
504
- if (handoff.kind !== 'activated') {
505
- (options.clearPendingRuntime || clearPendingRuntime)(env.BLUN_SHARED_HOME, preparedTarget);
506
- }
507
- const resumed = handoff.core;
508
- if (resumed === undefined || resumed.ready !== true) return 1;
509
- const resumedArgs = handoffArgsForMode(args, handoffMode, handoffSessionId);
510
- return superviseProtectedCore(resumedArgs, env, handoffCwd, async () => {}, {
511
- ...options,
512
- existingCore: resumed,
513
- packageRoot: handoff.runtime.packageRoot,
514
- startupPendingRuntime: undefined,
515
- staleActiveRuntime: undefined,
516
- recoveryRuntime: handoff.kind === 'activated' ? {
517
- activatedAt,
518
- activeRuntime: previousActiveRuntime,
519
- packageRoot,
520
- version: readPackageVersionAt(packageRoot),
521
- } : undefined,
522
- });
523
- }
524
403
  const recovery = options.recoveryRuntime;
525
404
  if (shouldRecoverActivatedRuntime(result, recovery, {
526
405
  now: (options.nowImpl || Date.now)(),
@@ -651,6 +530,7 @@ function spawnActiveLauncher(packageRoot, cwd, args = RAW_ARGS) {
651
530
  async function runLauncher(options = {}) {
652
531
  const callerCwd = process.cwd();
653
532
  let startupPendingRuntime;
533
+ let deferredPendingRuntime;
654
534
  let staleActiveRuntime;
655
535
  if (options.skipActiveRuntime !== true) {
656
536
  const activeHome = resolveLauncherPrivatePaths().sharedHome;
@@ -660,20 +540,12 @@ async function runLauncher(options = {}) {
660
540
  if (pendingRuntime !== null
661
541
  && path.resolve(pendingRuntime.packageRoot) !== PKG
662
542
  && compareSemver(currentVersion, pendingRuntime.version) === -1) {
663
- const pendingArgs = pendingRuntime.mode !== undefined && pendingRuntime.sessionId !== undefined
664
- ? handoffArgsForMode(RAW_ARGS, pendingRuntime.mode, pendingRuntime.sessionId)
665
- : RAW_ARGS;
666
- process.exitCode = await spawnActiveLauncher(
667
- pendingRuntime.packageRoot,
668
- pendingRuntime.cwd || callerCwd,
669
- pendingArgs,
670
- );
671
- return;
543
+ deferredPendingRuntime = pendingRuntime;
672
544
  }
673
545
  if (pendingRuntime !== null && path.resolve(pendingRuntime.packageRoot) === PKG) {
674
546
  startupPendingRuntime = pendingRuntime;
675
547
  }
676
- if (startupPendingRuntime === undefined && activeRuntime !== null
548
+ if (startupPendingRuntime === undefined && deferredPendingRuntime === undefined && activeRuntime !== null
677
549
  && path.resolve(activeRuntime.packageRoot) !== PKG
678
550
  && compareSemver(currentVersion, activeRuntime.version) === -1) {
679
551
  process.exitCode = await spawnActiveLauncher(activeRuntime.packageRoot, callerCwd);
@@ -837,8 +709,24 @@ async function runLauncher(options = {}) {
837
709
  stderr: process.stderr,
838
710
  blunDir: privatePaths.sharedHome,
839
711
  packageRoot: PKG,
712
+ preparedRuntime: deferredPendingRuntime,
840
713
  noticeLease,
841
714
  });
715
+ if (updateResult.kind === 'installed'
716
+ && updateResult.source === 'prepared_runtime'
717
+ && deferredPendingRuntime !== undefined) {
718
+ const pendingArgs = deferredPendingRuntime.mode !== undefined
719
+ && deferredPendingRuntime.sessionId !== undefined
720
+ ? handoffArgsForMode(RAW_ARGS, deferredPendingRuntime.mode, deferredPendingRuntime.sessionId)
721
+ : RAW_ARGS;
722
+ await releaseNotice();
723
+ process.exitCode = await spawnActiveLauncher(
724
+ deferredPendingRuntime.packageRoot,
725
+ deferredPendingRuntime.cwd || callerCwd,
726
+ pendingArgs,
727
+ );
728
+ return;
729
+ }
842
730
  if (updateResult.kind === 'installed' || updateResult.kind === 'update_in_progress') return;
843
731
 
844
732
  if (!runtimeLease) {
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ function createPendingTokenEstimateCache(estimateMessages) {
4
+ if (typeof estimateMessages !== 'function') {
5
+ throw new TypeError('estimateMessages must be a function');
6
+ }
7
+
8
+ let cachedHistory = null;
9
+ let cachedCoveredCount = -1;
10
+ let cachedRevision = -1;
11
+ let cachedEstimate = 0;
12
+
13
+ return {
14
+ read(history, coveredMessageCount, revision) {
15
+ const messages = Array.isArray(history) ? history : [];
16
+ const covered = Math.max(
17
+ 0,
18
+ Math.min(messages.length, Math.floor(Number(coveredMessageCount) || 0)),
19
+ );
20
+ const currentRevision = Number.isSafeInteger(revision) ? revision : 0;
21
+
22
+ if (
23
+ messages === cachedHistory
24
+ && covered === cachedCoveredCount
25
+ && currentRevision === cachedRevision
26
+ ) {
27
+ return cachedEstimate;
28
+ }
29
+
30
+ cachedEstimate = estimateMessages(messages.slice(covered));
31
+ cachedHistory = messages;
32
+ cachedCoveredCount = covered;
33
+ cachedRevision = currentRevision;
34
+ return cachedEstimate;
35
+ },
36
+ };
37
+ }
38
+
39
+ module.exports = {
40
+ createPendingTokenEstimateCache,
41
+ };
@@ -1393,6 +1393,13 @@ async function runUpdateFlow(options, explicitUpdate) {
1393
1393
  ? explicitNoTarget(stdout, reason, currentVersion)
1394
1394
  : { kind: 'continue', reason };
1395
1395
  }
1396
+ const preparedRuntime = options.preparedRuntime;
1397
+ const preparedRuntimeReady = preparedRuntime !== null
1398
+ && typeof preparedRuntime === 'object'
1399
+ && preparedRuntime.version === release.version
1400
+ && typeof preparedRuntime.packageRoot === 'string'
1401
+ && path.isAbsolute(preparedRuntime.packageRoot)
1402
+ && verifyInstalledPackageVersion(preparedRuntime.packageRoot, release.version);
1396
1403
  if (!explicitUpdate
1397
1404
  && pendingVersion === undefined
1398
1405
  && readSnoozeState(blunDir, release.version, now)) {
@@ -1438,7 +1445,7 @@ async function runUpdateFlow(options, explicitUpdate) {
1438
1445
  ? explicitFailure(stderr, 'lease_unavailable')
1439
1446
  : { kind: 'continue', reason: 'lease_unavailable' };
1440
1447
  }
1441
- if (!options.installVersion) {
1448
+ if (!options.installVersion && !preparedRuntimeReady) {
1442
1449
  installerSession = await (options.prepareInstaller || preparePinnedInstaller)(
1443
1450
  release.version,
1444
1451
  { blunDir, packageRoot },
@@ -1502,9 +1509,11 @@ async function runUpdateFlow(options, explicitUpdate) {
1502
1509
  let installResult;
1503
1510
  updateProgress(3, 'Paket wird installiert');
1504
1511
  try {
1505
- installResult = options.installVersion
1506
- ? await options.installVersion(release.version)
1507
- : await installerSession.commit();
1512
+ installResult = preparedRuntimeReady
1513
+ ? { code: 0, verified: true, preparedRuntime: true }
1514
+ : options.installVersion
1515
+ ? await options.installVersion(release.version)
1516
+ : await installerSession.commit();
1508
1517
  } catch {
1509
1518
  installResult = { code: undefined };
1510
1519
  }
@@ -1536,7 +1545,11 @@ async function runUpdateFlow(options, explicitUpdate) {
1536
1545
  `Update ${currentVersion} -> ${release.version} erfolgreich installiert. Starte BLUN Code neu, um die neue Version zu verwenden.\n`,
1537
1546
  );
1538
1547
  if (release.notesUrl) stdout.write(`Versionshinweise: ${release.notesUrl}\n`);
1539
- return { kind: 'installed', version: release.version };
1548
+ return {
1549
+ kind: 'installed',
1550
+ version: release.version,
1551
+ ...(installResult.preparedRuntime === true ? { source: 'prepared_runtime' } : {}),
1552
+ };
1540
1553
  }
1541
1554
 
1542
1555
  if (Number.isInteger(installResult?.code) && installResult.code !== 0) {
package/blun.mjs CHANGED
@@ -78650,12 +78650,13 @@ function formatUndoUnavailableMessage(requestedCount, undoableCount, stoppedAtCo
78650
78650
  return `${String(count)} ${count === 1 ? "prompt" : "prompts"}`;
78651
78651
  }
78652
78652
  }
78653
- var TOOL_ERROR_STATUS$2, TOOL_EMPTY_STATUS$2, TOOL_EMPTY_ERROR_STATUS$2, TOOL_OUTPUT_EMPTY_TEXT$2, TOOL_INTERRUPTED_ON_RESUME_OUTPUT$1, ContextMemory;
78653
+ var TOOL_ERROR_STATUS$2, TOOL_EMPTY_STATUS$2, TOOL_EMPTY_ERROR_STATUS$2, TOOL_OUTPUT_EMPTY_TEXT$2, TOOL_INTERRUPTED_ON_RESUME_OUTPUT$1, createPendingTokenEstimateCache, ContextMemory;
78654
78654
  var init_context$2 = __esmMin((() => {
78655
- init_src$4();
78656
- init_errors$8();
78657
- init_image_compress();
78658
- init_tokens();
78655
+ init_src$4();
78656
+ init_errors$8();
78657
+ init_image_compress();
78658
+ init_tokens();
78659
+ ({ createPendingTokenEstimateCache } = createRequire(import.meta.url)("./bin/pending-token-estimate-policy.cjs"));
78659
78660
  init_xml_escape();
78660
78661
  init_compaction();
78661
78662
  init_projector();
@@ -78669,8 +78670,10 @@ var init_context$2 = __esmMin((() => {
78669
78670
  ContextMemory = class {
78670
78671
  agent;
78671
78672
  _history = [];
78672
- _tokenCount = 0;
78673
- tokenCountCoveredMessageCount = 0;
78673
+ _tokenCount = 0;
78674
+ tokenCountCoveredMessageCount = 0;
78675
+ pendingTokenRevision = 0;
78676
+ pendingTokenEstimateCache = createPendingTokenEstimateCache(estimateTokensForMessages);
78674
78677
  openSteps = /* @__PURE__ */ new Map();
78675
78678
  pendingToolResultIds = /* @__PURE__ */ new Set();
78676
78679
  deferredMessages = [];
@@ -78679,9 +78682,12 @@ var init_context$2 = __esmMin((() => {
78679
78682
  constructor(agent) {
78680
78683
  this.agent = agent;
78681
78684
  }
78682
- get lastAssistantAt() {
78683
- return this._lastAssistantAt;
78684
- }
78685
+ get lastAssistantAt() {
78686
+ return this._lastAssistantAt;
78687
+ }
78688
+ markPendingTokenEstimateDirty() {
78689
+ this.pendingTokenRevision = (this.pendingTokenRevision + 1) % Number.MAX_SAFE_INTEGER;
78690
+ }
78685
78691
  appendUserMessage(content, origin = USER_PROMPT_ORIGIN) {
78686
78692
  if (content.length === 0) return;
78687
78693
  const { captions, parts } = origin.kind === "user" ? splitImageCompressionCaptions(content) : {
@@ -78783,8 +78789,11 @@ var init_context$2 = __esmMin((() => {
78783
78789
  const last = lastDeferred ?? this._history.at(-1);
78784
78790
  if (last === void 0) return false;
78785
78791
  if (!matcher(last.origin)) return false;
78786
- if (lastDeferred !== void 0) this.deferredMessages.pop();
78787
- else this._history.pop();
78792
+ if (lastDeferred !== void 0) this.deferredMessages.pop();
78793
+ else {
78794
+ this._history.pop();
78795
+ this.markPendingTokenEstimateDirty();
78796
+ }
78788
78797
  return true;
78789
78798
  }
78790
78799
  /** Remove transient system reminders before the next model projection. */
@@ -78806,7 +78815,8 @@ var init_context$2 = __esmMin((() => {
78806
78815
  removedMessages.add(message);
78807
78816
  return false;
78808
78817
  });
78809
- if (removedMessages.size === 0) return 0;
78818
+ if (removedMessages.size === 0) return 0;
78819
+ this.markPendingTokenEstimateDirty();
78810
78820
  this.agent.replayBuilder.removeLastMessages(removedMessages);
78811
78821
  this.agent.microCompaction.reset(this._history.length);
78812
78822
  this.agent.toolResultBatchOffload.reset(this._history);
@@ -78817,7 +78827,8 @@ var init_context$2 = __esmMin((() => {
78817
78827
  }
78818
78828
  clear() {
78819
78829
  this.agent.records.logRecord({ type: "context.clear" });
78820
- this._history = [];
78830
+ this._history = [];
78831
+ this.markPendingTokenEstimateDirty();
78821
78832
  this._tokenCount = 0;
78822
78833
  this.tokenCountCoveredMessageCount = 0;
78823
78834
  this.openSteps.clear();
@@ -78861,7 +78872,8 @@ var init_context$2 = __esmMin((() => {
78861
78872
  if (removedUserCount >= count) break;
78862
78873
  }
78863
78874
  }
78864
- this.agent.replayBuilder.removeLastMessages(removedMessages);
78875
+ this.agent.replayBuilder.removeLastMessages(removedMessages);
78876
+ if (removedMessages.size > 0) this.markPendingTokenEstimateDirty();
78865
78877
  this.openSteps.clear();
78866
78878
  this.pendingToolResultIds.clear();
78867
78879
  this.deferredMessages = [];
@@ -78940,7 +78952,8 @@ var init_context$2 = __esmMin((() => {
78940
78952
  origin: { kind: "compaction_summary" }
78941
78953
  };
78942
78954
  const isLegacyRestore = this.agent.records.restoring !== null && input.keptUserMessageCount === void 0 && input.compactedCount < this._history.length;
78943
- this._history = isLegacyRestore ? [summaryMessage, ...this._history.slice(input.compactedCount)] : [...keptMessages, summaryMessage];
78955
+ this._history = isLegacyRestore ? [summaryMessage, ...this._history.slice(input.compactedCount)] : [...keptMessages, summaryMessage];
78956
+ this.markPendingTokenEstimateDirty();
78944
78957
  this.openSteps.clear();
78945
78958
  this.pendingToolResultIds.clear();
78946
78959
  this.deferredMessages = [];
@@ -78963,9 +78976,12 @@ var init_context$2 = __esmMin((() => {
78963
78976
  get tokenCount() {
78964
78977
  return this._tokenCount;
78965
78978
  }
78966
- get tokenCountWithPending() {
78967
- const pendingMessages = this._history.slice(this.tokenCountCoveredMessageCount);
78968
- return this._tokenCount + estimateTokensForMessages(pendingMessages);
78979
+ get tokenCountWithPending() {
78980
+ return this._tokenCount + this.pendingTokenEstimateCache.read(
78981
+ this._history,
78982
+ this.tokenCountCoveredMessageCount,
78983
+ this.pendingTokenRevision
78984
+ );
78969
78985
  }
78970
78986
  get history() {
78971
78987
  return this._history;
@@ -79120,6 +79136,7 @@ var init_context$2 = __esmMin((() => {
79120
79136
  this._tokenCount += estimateTokensForMessages(this._history.slice(previousCoveredCount, coveredCount));
79121
79137
  }
79122
79138
  this.tokenCountCoveredMessageCount = coveredCount;
79139
+ this.markPendingTokenEstimateDirty();
79123
79140
  }
79124
79141
  this.flushDeferredMessagesIfToolExchangeClosed();
79125
79142
  return;
@@ -79127,18 +79144,20 @@ var init_context$2 = __esmMin((() => {
79127
79144
  case "content.part": {
79128
79145
  const openStep = this.openSteps.get(event.stepUuid);
79129
79146
  if (openStep === void 0) throw new Error(`Received content_part for unknown step_uuid '${event.stepUuid}' (no open step_begin)`);
79130
- openStep.content.push(event.part);
79147
+ openStep.content.push(event.part);
79148
+ this.markPendingTokenEstimateDirty();
79131
79149
  return;
79132
79150
  }
79133
79151
  case "tool.call": {
79134
79152
  const openStep = this.openSteps.get(event.stepUuid);
79135
79153
  if (openStep === void 0) throw new Error(`Received tool_call for unknown step_uuid '${event.stepUuid}' (no open step_begin)`);
79136
- openStep.toolCalls.push({
79154
+ openStep.toolCalls.push({
79137
79155
  type: "function",
79138
79156
  id: event.toolCallId,
79139
79157
  name: event.name,
79140
- arguments: event.args === void 0 ? null : JSON.stringify(event.args)
79141
- });
79158
+ arguments: event.args === void 0 ? null : JSON.stringify(event.args)
79159
+ });
79160
+ this.markPendingTokenEstimateDirty();
79142
79161
  this.pendingToolResultIds.add(event.toolCallId);
79143
79162
  return;
79144
79163
  }
@@ -79175,8 +79194,9 @@ var init_context$2 = __esmMin((() => {
79175
79194
  hasOpenToolExchange() {
79176
79195
  return this.pendingToolResultIds.size > 0;
79177
79196
  }
79178
- pushHistory(...messages) {
79179
- this._history.push(...messages);
79197
+ pushHistory(...messages) {
79198
+ this._history.push(...messages);
79199
+ this.markPendingTokenEstimateDirty();
79180
79200
  for (const message of messages) {
79181
79201
  if (message.role === "assistant") this._lastAssistantAt = this.agent.records.restoring?.time ?? Date.now();
79182
79202
  if (message.origin?.kind === "background_task") this.agent.background.markDeliveredNotification(message.origin);
@@ -515099,8 +515119,6 @@ function turnsToTrim(turns, maxTurns, hysteresis) {
515099
515119
  const {
515100
515120
  AUTO_UPDATE_SETTLE_MS,
515101
515121
  RUNNING_UPDATE_HANDOFF_EXIT_CODE,
515102
- RUNNING_UPDATE_HANDOFF_ACK_MESSAGE,
515103
- RUNNING_UPDATE_HANDOFF_MESSAGE,
515104
515122
  RUNNING_UPDATE_MODE_MESSAGE,
515105
515123
  RUNNING_UPDATE_PREPARED_MESSAGE,
515106
515124
  RUNTIME_EXIT_INTENT_MESSAGE,
@@ -515128,64 +515146,14 @@ function notifyRunningRuntimeReady(tui) {
515128
515146
  } catch {}
515129
515147
  }
515130
515148
  function requestRunningUpdateAtSafeBoundary(tui) {
515131
- if (tui.runningUpdatePreparedVersion === void 0 || tui.runningUpdatePreparedMode === void 0 || tui.runningUpdateHandoffStarted || !process.connected) return false;
515132
- const boundaryState = () => ({
515133
- isShuttingDown: tui.isShuttingDown,
515134
- streamingPhase: tui.state.appState.streamingPhase,
515135
- isCompacting: tui.state.appState.isCompacting,
515136
- queuedMessages: tui.state.queuedMessages.length,
515137
- activeToolCalls: tui.streamingUI.hasActiveToolCalls() ? 1 : 0,
515138
- shellCommands: tui.shellOutputStreams.size,
515139
- queueCommandRunning: tui.queueCommandRunning
515140
- });
515141
- if (!isSafeRuntimeBoundary(boundaryState())) return false;
515142
- const sessionId = tui.getCurrentSessionId();
515143
- if (sessionId.length === 0) return false;
515144
- tui.runningUpdateHandoffStarted = true;
515145
- try {
515146
- process.send({
515147
- type: RUNNING_UPDATE_HANDOFF_MESSAGE,
515148
- sessionId,
515149
- version: tui.runningUpdatePreparedVersion,
515150
- mode: tui.runningUpdatePreparedMode,
515151
- cwd: tui.state.appState.workDir
515152
- }, (error) => {
515153
- if (error || !isSafeRuntimeBoundary(boundaryState())) {
515154
- tui.runningUpdateHandoffStarted = false;
515155
- }
515156
- });
515157
- } catch {
515158
- tui.runningUpdateHandoffStarted = false;
515159
- return false;
515160
- }
515161
- return true;
515149
+ return false;
515162
515150
  }
515163
515151
  function installRunningUpdateListener(tui) {
515164
515152
  const handler = (message) => {
515165
- if (message?.type === RUNNING_UPDATE_HANDOFF_ACK_MESSAGE) {
515166
- if (!tui.runningUpdateHandoffStarted || message.version !== tui.runningUpdatePreparedVersion || message.mode !== tui.runningUpdatePreparedMode || message.sessionId !== tui.getCurrentSessionId()) return;
515167
- if (!isSafeRuntimeBoundary({
515168
- isShuttingDown: tui.isShuttingDown,
515169
- streamingPhase: tui.state.appState.streamingPhase,
515170
- isCompacting: tui.state.appState.isCompacting,
515171
- queuedMessages: tui.state.queuedMessages.length,
515172
- activeToolCalls: tui.streamingUI.hasActiveToolCalls() ? 1 : 0,
515173
- shellCommands: tui.shellOutputStreams.size,
515174
- queueCommandRunning: tui.queueCommandRunning
515175
- })) {
515176
- tui.runningUpdateHandoffStarted = false;
515177
- return;
515178
- }
515179
- tui.showStatus("Ein Update wird geladen und die TUI wird neu gestartet.", "success");
515180
- void tui.stop(RUNNING_UPDATE_HANDOFF_EXIT_CODE).catch(() => {
515181
- tui.runningUpdateHandoffStarted = false;
515182
- });
515183
- return;
515184
- }
515185
515153
  if (message?.type !== RUNNING_UPDATE_PREPARED_MESSAGE || typeof message.version !== "string" || message.mode !== RUNNING_UPDATE_MODES.RESUME && message.mode !== RUNNING_UPDATE_MODES.NEW) return;
515186
515154
  tui.runningUpdatePreparedVersion = message.version;
515187
515155
  tui.runningUpdatePreparedMode = message.mode;
515188
- requestRunningUpdateAtSafeBoundary(tui);
515156
+ tui.showStatus(`Update ${message.version} ist bereit und wird beim naechsten Start aktiviert.`, "success");
515189
515157
  };
515190
515158
  process.on("message", handler);
515191
515159
  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.220",
3
+ "version": "9.1.222",
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": {