blun-king-cli 9.1.171 → 9.1.172

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.
@@ -58,6 +58,25 @@ const PROFILE = parseProfileLaunchArgs(RAW_ARGS, launcherModeFromArgv(process.ar
58
58
  const ARGS = PROFILE.args;
59
59
  const CORE_LOAD_TIMEOUT_MS = 30_000;
60
60
  const RUNTIME_READY_TIMEOUT_MS = 60_000;
61
+ const RUNNING_UPDATE_RECHECK_MS = 60_000;
62
+ const RUNNING_UPDATE_RECHECK_JITTER_MS = 30_000;
63
+
64
+ function runningUpdateRecheckDelay(randomValue = Math.random()) {
65
+ const normalized = Number.isFinite(randomValue)
66
+ ? Math.min(Math.max(randomValue, 0), 0.999999999)
67
+ : 0;
68
+ return RUNNING_UPDATE_RECHECK_MS
69
+ + Math.floor(normalized * RUNNING_UPDATE_RECHECK_JITTER_MS);
70
+ }
71
+
72
+ function scheduleRunningUpdateRecheck(callback, options = {}) {
73
+ const timer = (options.setTimeoutImpl || setTimeout)(
74
+ callback,
75
+ options.delayMs ?? runningUpdateRecheckDelay((options.randomImpl || Math.random)()),
76
+ );
77
+ timer.unref?.();
78
+ return timer;
79
+ }
61
80
 
62
81
  function normalizeWindowsPath(value) {
63
82
  return path.win32.normalize(value).replace(/\\+$/u, '').toLowerCase();
@@ -232,9 +251,23 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
232
251
  let handoffMode;
233
252
  let updateStarted = false;
234
253
  let runtimeReady = false;
254
+ let runningUpdatePollTimer;
235
255
  let runningUpdateMode = readRunningUpdateMode(env.BLUN_HOME);
236
256
  const automaticMode = () => runningUpdateMode === RUNNING_UPDATE_MODES.RESUME
237
257
  || runningUpdateMode === RUNNING_UPDATE_MODES.NEW;
258
+ const clearRunningUpdatePoll = () => {
259
+ if (runningUpdatePollTimer === undefined) return;
260
+ (options.clearTimeoutImpl || clearTimeout)(runningUpdatePollTimer);
261
+ runningUpdatePollTimer = undefined;
262
+ };
263
+ const scheduleNextPreparation = (child) => {
264
+ clearRunningUpdatePoll();
265
+ if (preparedTarget !== undefined || updateStarted || !automaticMode()) return;
266
+ runningUpdatePollTimer = (options.scheduleRunningUpdateRecheck || scheduleRunningUpdateRecheck)(() => {
267
+ runningUpdatePollTimer = undefined;
268
+ startPreparation(child);
269
+ });
270
+ };
238
271
  const announcePrepared = (child) => {
239
272
  if (preparedTarget === undefined || !automaticMode() || child.connected !== true) return;
240
273
  child.send({
@@ -249,6 +282,7 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
249
282
  const sharedHome = env.BLUN_SHARED_HOME;
250
283
  if (typeof sharedHome !== 'string' || sharedHome.length === 0) {
251
284
  updateStarted = false;
285
+ scheduleNextPreparation(child);
252
286
  return;
253
287
  }
254
288
  Promise.resolve((options.prepareRunningUpdate || prepareRunningUpdate)({
@@ -258,16 +292,19 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
258
292
  })).then((target) => {
259
293
  if (target === null) {
260
294
  updateStarted = false;
295
+ scheduleNextPreparation(child);
261
296
  return;
262
297
  }
263
298
  preparedTarget = target;
299
+ clearRunningUpdatePoll();
264
300
  announcePrepared(child);
265
301
  }).catch((error) => {
266
302
  updateStarted = false;
267
303
  options.onRunningUpdateError?.(error);
304
+ scheduleNextPreparation(child);
268
305
  });
269
306
  };
270
- const core = spawnProtectedCore(args, env, cwd, {
307
+ const core = (options.spawnProtectedCore || spawnProtectedCore)(args, env, cwd, {
271
308
  packageRoot,
272
309
  onMessage(message, child) {
273
310
  if (message?.type === RUNTIME_READY_MESSAGE) {
@@ -278,6 +315,7 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
278
315
  runningUpdateMode = normalizeRunningUpdateMode(message.mode);
279
316
  handoffSessionId = undefined;
280
317
  handoffMode = undefined;
318
+ clearRunningUpdatePoll();
281
319
  if (automaticMode()) {
282
320
  if (preparedTarget !== undefined) announcePrepared(child);
283
321
  else if (runtimeReady) {
@@ -299,6 +337,7 @@ async function superviseProtectedCore(args, env, cwd, releaseNotice, options = {
299
337
  const loaded = await core.loaded;
300
338
  await releaseNotice();
301
339
  const result = await core.completed;
340
+ clearRunningUpdatePoll();
302
341
  if (result.error) throw result.error;
303
342
  if (result.code === RUNNING_UPDATE_HANDOFF_EXIT_CODE
304
343
  && preparedTarget !== undefined
@@ -656,9 +695,14 @@ async function runLauncher(options = {}) {
656
695
  }
657
696
 
658
697
  module.exports = {
698
+ RUNNING_UPDATE_RECHECK_JITTER_MS,
699
+ RUNNING_UPDATE_RECHECK_MS,
659
700
  createManagedNodeEnvironment,
660
701
  resolveLauncherPrivatePaths,
702
+ runningUpdateRecheckDelay,
661
703
  runLauncher,
704
+ scheduleRunningUpdateRecheck,
662
705
  shouldDetachProtectedCore,
663
706
  spawnManagedLauncher,
707
+ superviseProtectedCore,
664
708
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.171",
3
+ "version": "9.1.172",
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": {