heybash-xdpool 1.0.4 → 1.0.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Heybash
2
2
 
3
+ ## 1.0.6 — 并行工具调用修复
4
+
5
+ - 修复聚合路由在同时调用多个工具时混合参数,避免出现 MALFORMED_RESPONSE 并中断会话。
6
+ - 修复路由渠道成员 ID 的分组、保存和旧格式兼容;保留图片能力、推理档位与上下文配置。
7
+ - 修复积分浮层在视口缩放或偏移时的定位;启动时及时执行积分自动化,保留未来定时任务。
8
+ - 改善渠道网络传输、积分到期优先策略与免费模型错误提示,网关支持非流式响应。
9
+
10
+ ## 1.0.5 — 积分浮层定位修复
11
+
12
+ - 修复输入框积分浮层在部分宿主布局和缩放环境下偏离按钮;窗口尺寸或滚动变化时保持位置并避免越界。
13
+ - 优化发布后国内镜像的查询与重试,减少缓存引起的重复同步。
14
+
3
15
  ## 1.0.4 — WorkBuddy 模型去重与镜像同步
4
16
 
5
17
  - 模型选择器统一使用 WorkBuddy 地区名称;同一区域的渠道模型与账号池模型重复时只显示一份,保留历史渠道调用。
package/lib/bin.js CHANGED
@@ -1345,8 +1345,18 @@ var WorkBuddyUpstreamClient = class {
1345
1345
  if (models.length === 0) throw new Error("workbuddy model catalog resolved to an empty list");
1346
1346
  return models;
1347
1347
  }
1348
- /** Read-only credits query, aggregated by package. Does not consume credits. */
1349
- async fetchCredits(credential) {
1348
+ /**
1349
+ * Read-only credits query, aggregated by package. Does not consume credits.
1350
+ *
1351
+ * `signal` is the caller's cancellation, merged with the built-in timeout
1352
+ * rather than replacing it: the pool's background warm must give up when the
1353
+ * host shuts down, and a caller that has already gone away must not leave a
1354
+ * 30 s request running. `AbortSignal.any` is already the repo's way of
1355
+ * combining these (see the pricing probe in the shim), and the timeout stays
1356
+ * in force so a signal-less caller keeps the old behaviour exactly.
1357
+ */
1358
+ async fetchCredits(credential, signal) {
1359
+ const timeout = AbortSignal.timeout(JSON_TIMEOUT_MS);
1350
1360
  const now = /* @__PURE__ */ new Date();
1351
1361
  const fmt = (date) => {
1352
1362
  const p = (n) => n.toString().padStart(2, "0");
@@ -1363,7 +1373,7 @@ var WorkBuddyUpstreamClient = class {
1363
1373
  PackageEndTimeRangeBegin: fmt(now),
1364
1374
  PackageEndTimeRangeEnd: fmt(new Date(now.getTime() + 3185136e6))
1365
1375
  }),
1366
- signal: AbortSignal.timeout(JSON_TIMEOUT_MS)
1376
+ signal: signal === void 0 ? timeout : AbortSignal.any([timeout, signal])
1367
1377
  });
1368
1378
  const envelope = await readEnvelope(response);
1369
1379
  if (!response.ok || envelope.code !== 0) throw envelopeError(response.status, envelope);
@@ -3540,6 +3550,13 @@ const EXHAUST_COOLDOWN_MS = 18e5;
3540
3550
  */
3541
3551
  const CREDENTIAL_DEAD_COOLDOWN_MS = 18e5;
3542
3552
  /**
3553
+ * Shortest gap between two attempts at the same account's deadline reading.
3554
+ *
3555
+ * Only failed attempts are actually throttled by this: a successful read stamps
3556
+ * the reading itself, so {@link EXPIRY_READING_TTL_MS} takes over from there.
3557
+ */
3558
+ const EXPIRY_WARM_RETRY_MS = 6e4;
3559
+ /**
3543
3560
  * Does this refresh failure prove the credential itself is dead?
3544
3561
  *
3545
3562
  * The upstream answers a revoked refresh token with `invalid_grant: Offline user
@@ -3568,6 +3585,7 @@ var WorkBuddyAccountPool = class {
3568
3585
  credentialDeadCooldownMs;
3569
3586
  client;
3570
3587
  refreshMarginMs;
3588
+ expiryReadingTtlMs;
3571
3589
  accounts = [];
3572
3590
  /**
3573
3591
  * Files the last scan could not read, with the reason.
@@ -3663,11 +3681,42 @@ var WorkBuddyAccountPool = class {
3663
3681
  * their own cycle and are therefore never urgent — which is why this is
3664
3682
  * written from the same `fetchCredits` reading that fills `creditBalances`.
3665
3683
  *
3666
- * An absent entry means "never probed, or nothing is about to expire". Both
3667
- * are the same thing to `expiry` mode: not urgent, so it sorts last.
3684
+ * A positive value is a deadline. The two other states are kept in
3685
+ * {@link creditExpiryNone} and {@link creditExpiryReadAt} rather than as a
3686
+ * missing key, because a missing key cannot tell "we never looked" from "we
3687
+ * looked and nothing has a deadline" — and only the first is worth reading
3688
+ * again. An account whose packs are all monthly reads as `none` forever, which
3689
+ * is exactly right: asking again cannot change the answer (S1).
3668
3690
  */
3669
3691
  creditExpiry = /* @__PURE__ */ new Map();
3670
3692
  /**
3693
+ * Accounts whose last reading found NO one-off deadline (all monthly packs, or
3694
+ * none at all). Written instead of deleting the key, so the account stops
3695
+ * being a candidate for re-reading.
3696
+ */
3697
+ creditExpiryNone = /* @__PURE__ */ new Set();
3698
+ /** When each account's deadline reading was taken, epoch ms. */
3699
+ creditExpiryReadAt = /* @__PURE__ */ new Map();
3700
+ /**
3701
+ * Accounts whose deadline reading is being fetched right now.
3702
+ *
3703
+ * Same de-duplication idea as {@link refreshInflight}, for the same reason: a
3704
+ * scan-triggered warm and a request-triggered top-up must not both spend a
3705
+ * billing round trip on the same account. A Set rather than a Map of promises
3706
+ * because no caller ever awaits the warm — the point is only that a second
3707
+ * pass skips it.
3708
+ */
3709
+ expiryWarmInflight = /* @__PURE__ */ new Set();
3710
+ /**
3711
+ * Last time the pool tried to warm an account's deadline reading, epoch ms.
3712
+ *
3713
+ * The TTL is the success gate, not a retry gate: a failed read writes nothing,
3714
+ * so without this a permanently failing billing endpoint would be hit on every
3715
+ * scan and every served request. One attempt per account per minute is cheap
3716
+ * and still recovers quickly from a transient failure.
3717
+ */
3718
+ expiryWarmAttemptAt = /* @__PURE__ */ new Map();
3719
+ /**
3671
3720
  * Last time each account served a request, epoch ms. Drives the idle term
3672
3721
  * of the priority-mode weighting below: an account that just served loses to
3673
3722
  * one that has been idle, so a small pool stops hammering a single account.
@@ -3712,6 +3761,7 @@ var WorkBuddyAccountPool = class {
3712
3761
  this.credentialDeadCooldownMs = options.credentialDeadCooldownMs ?? CREDENTIAL_DEAD_COOLDOWN_MS;
3713
3762
  this.client = options.client;
3714
3763
  this.refreshMarginMs = options.refreshMarginMs ?? 3e5;
3764
+ this.expiryReadingTtlMs = options.expiryReadingTtlMs ?? 36e5;
3715
3765
  this.distribution = options.distribution ?? "priority";
3716
3766
  this.persistent = options.persistent ?? false;
3717
3767
  this.storePath = accountStorePath();
@@ -3926,6 +3976,7 @@ var WorkBuddyAccountPool = class {
3926
3976
  ordered.sort((a, b) => compareFreshness(a.credential, b.credential));
3927
3977
  this.accounts = ordered;
3928
3978
  this.lastScanAtMs = Date.now();
3979
+ this.warmExpiryReadings();
3929
3980
  if (this.persistent) try {
3930
3981
  const leaving = this.lastPersistedIds === void 0 ? [] : [...this.lastPersistedIds].filter((id) => !this.accounts.some((account) => account.id === id));
3931
3982
  if (leaving.length > 0) this.logger?.warn?.(`heybash-xdpool: ${String(leaving.length)} account(s) are no longer in the pool after a rescan and were removed from the store: ${leaving.join(", ")}. Their credentials are gone unless they are signed in again.`);
@@ -3936,6 +3987,76 @@ var WorkBuddyAccountPool = class {
3936
3987
  }
3937
3988
  return this.accounts;
3938
3989
  }
3990
+ /**
3991
+ * Warm the deadline readings that `expiry` mode sorts on.
3992
+ *
3993
+ * Fire-and-forget on purpose, from `scan()`: the pool's first request arrives
3994
+ * before any reading exists, and the honest answer to that is the documented
3995
+ * fallback plus a log line, not a stalled request. Everything about the call
3996
+ * is chosen to be unable to make things worse:
3997
+ *
3998
+ * - `this.client` may not exist (a host that wired only token refresh), in
3999
+ * which case there is nothing to read with and the pass is a no-op — the
4000
+ * same guard `ensureFresh` uses;
4001
+ * - a dead sign-in is skipped, and a successful read NEVER calls
4002
+ * `clearCredentialDead`. That is the difference between this and
4003
+ * `reviveBenched`: the billing endpoint answers 200 for a banned account
4004
+ * (observed on 11140), so treating a read as proof of health is what got a
4005
+ * banned account revived six times in a day (S2). Only a token refresh or a
4006
+ * fresh sign-in may clear that mark;
4007
+ * - accounts whose reading is fresh enough are skipped, and so are accounts
4008
+ * already being read (S10's de-duplication, mirroring `refreshInflight`);
4009
+ * - a failed read writes nothing and only warns, so the next pass tries
4010
+ * again without the failure being mistaken for a reading.
4011
+ */
4012
+ warmExpiryReadings() {
4013
+ if (this.client?.fetchCredits === void 0) return;
4014
+ for (const account of this.accounts) this.warmExpiryReadingFor(account.id);
4015
+ }
4016
+ /** One account's warm read; see {@link warmExpiryReadings} for the rules. */
4017
+ async warmOneExpiryReading(account, client) {
4018
+ this.expiryWarmInflight.add(account.id);
4019
+ this.expiryWarmAttemptAt.set(account.id, Date.now());
4020
+ try {
4021
+ const credits = await client.fetchCredits(account.credential);
4022
+ this.noteExpiryOnly(account.id, credits.nearestExpiryMs);
4023
+ } catch (error) {
4024
+ this.logger?.warn?.(`heybash-xdpool: could not read credit deadlines for ${account.label} (read failed); expiry mode keeps falling back for it until a read succeeds`, error);
4025
+ } finally {
4026
+ this.expiryWarmInflight.delete(account.id);
4027
+ }
4028
+ }
4029
+ /**
4030
+ * Top up one account's deadline reading, from wherever the pool notices it is
4031
+ * missing or stale.
4032
+ *
4033
+ * The request path is the second caller (after `scan()`), because a reading
4034
+ * ages out while the pool is busy too: the shim calls this for the account that
4035
+ * just served a request, which is the one whose spend is most likely to have
4036
+ * moved its deadline. No timer is created — the existing balance refresh is
4037
+ * already the natural heartbeat, and this rides on it.
4038
+ *
4039
+ * Every gate lives here rather than in the callers, so both paths obey exactly
4040
+ * the same rules: no client, no account, a rejected sign-in, an already-running
4041
+ * read, a finished "nothing expires" answer, a fresh reading, or an attempt
4042
+ * made within the last minute all mean "do nothing".
4043
+ */
4044
+ warmExpiryReadingFor(accountId) {
4045
+ if (this.distribution !== "expiry") return;
4046
+ const client = this.client;
4047
+ if (client?.fetchCredits === void 0) return;
4048
+ const account = this.accounts.find((item) => item.id === accountId);
4049
+ if (account === void 0) return;
4050
+ const now = Date.now();
4051
+ if ((account.credentialDeadUntilMs ?? 0) > now) return;
4052
+ if (this.expiryWarmInflight.has(accountId)) return;
4053
+ const reading = this.expiryReadingOf(accountId, now);
4054
+ if (reading.state === "none") return;
4055
+ if (reading.state === "at" && !reading.stale) return;
4056
+ const lastAttempt = this.expiryWarmAttemptAt.get(accountId) ?? 0;
4057
+ if (lastAttempt > (reading.readAtMs ?? 0) && now - lastAttempt < EXPIRY_WARM_RETRY_MS) return;
4058
+ this.warmOneExpiryReading(account, client);
4059
+ }
3939
4060
  /** All accounts, cooldown state included. */
3940
4061
  list(region) {
3941
4062
  if (region === void 0) return this.accounts;
@@ -4283,18 +4404,37 @@ var WorkBuddyAccountPool = class {
4283
4404
  * A pool where nobody has a known expiry therefore behaves exactly like
4284
4405
  * priority, which is the honest degradation: without a reading there is
4285
4406
  * nothing to sort by.
4407
+ *
4408
+ * What this method must NOT do is pretend. With only SOME readings in hand it
4409
+ * still has to fall back to `pool[0]`, because picking the earliest of the
4410
+ * accounts that happen to have answered would silently drop the account that
4411
+ * really dies first — the failure mode S0 in `EXPIRY-ADVERSARIAL-20261111.md`
4412
+ * called "worse than not fixing it", since the pick looks plausible and is
4413
+ * wrong. So the incomplete case is announced instead: the caller keeps the old
4414
+ * semantics and the log says which accounts were not read.
4286
4415
  */
4287
4416
  pickByExpiry(pool) {
4417
+ const now = Date.now();
4418
+ const unread = [];
4419
+ const stale = [];
4288
4420
  let best;
4289
4421
  let bestAt = Number.POSITIVE_INFINITY;
4290
4422
  for (const account of pool) {
4291
- const at = this.creditExpiry.get(account.id);
4292
- if (at === void 0) continue;
4423
+ const reading = this.expiryReadingOf(account.id, now);
4424
+ if (reading.stale) stale.push(account);
4425
+ if (reading.state === "unread" || reading.stale) {
4426
+ unread.push(account);
4427
+ continue;
4428
+ }
4429
+ if (reading.state === "none") continue;
4430
+ const at = reading.at ?? Number.POSITIVE_INFINITY;
4293
4431
  if (at < bestAt) {
4294
4432
  best = account;
4295
4433
  bestAt = at;
4296
4434
  }
4297
4435
  }
4436
+ if (stale.length > 0) this.logger?.info?.(`heybash-xdpool: expiry mode found ${stale.length} deadline reading(s) older than ${Math.round(this.expiryReadingTtlMs / 6e4)} minute(s) (${stale.map((account) => account.label).join(", ")}); they are being topped up in the background`);
4437
+ if (unread.length > 0) this.logger?.warn?.(`heybash-xdpool: expiry mode has no deadline reading for ${unread.length} of ${pool.length} account(s) (${unread.map((account) => account.label).join(", ")}); falling back to pool order for this pick, which may not be the soonest to expire. Readings are filled in the background after a scan and by the request path.`);
4298
4438
  return best ?? pool[0];
4299
4439
  }
4300
4440
  /**
@@ -4472,21 +4612,91 @@ var WorkBuddyAccountPool = class {
4472
4612
  * merged: a pack that has been spent or has died disappears from the next
4473
4613
  * reading, and keeping the stale deadline would pin the pool to an account
4474
4614
  * whose credits are already gone — the opposite of what `expiry` mode wants.
4615
+ *
4616
+ * "Nothing expires" is a real answer, not the absence of one: it is stored as
4617
+ * {@link creditExpiryNone} so the account is not read again on every pass.
4475
4618
  */
4476
4619
  noteCredits(accountId, balance, nearestExpiryMs) {
4477
4620
  if (!Number.isFinite(balance)) return;
4478
4621
  if (!this.accounts.some((account) => account.id === accountId)) return;
4479
4622
  this.creditBalances.set(accountId, balance);
4623
+ this.noteExpiryReading(accountId, nearestExpiryMs);
4624
+ }
4625
+ /**
4626
+ * Record ONLY the deadline, never the balance.
4627
+ *
4628
+ * The scan-triggered warm exists to fill `expiry` mode's sort key. Writing the
4629
+ * balance as a side effect would change what the reserve floor decides — an
4630
+ * account could be pulled out of rotation by a background read the user never
4631
+ * asked for, which is a behaviour change outside this fix's scope (S7 in
4632
+ * `EXPIRY-ADVERSARIAL-20261111.md`; the reserve's own cold-start hole is V4,
4633
+ * fixed separately).
4634
+ */
4635
+ noteExpiryOnly(accountId, nearestExpiryMs) {
4636
+ if (!this.accounts.some((account) => account.id === accountId)) return;
4637
+ this.noteExpiryReading(accountId, nearestExpiryMs);
4638
+ }
4639
+ /**
4640
+ * The three-state writer both entry points funnel through.
4641
+ *
4642
+ * One place, so the invariant "a finished reading always leaves a state" can be
4643
+ * read off a single function: either a deadline is stored, or the account joins
4644
+ * `creditExpiryNone`. Nothing here deletes the read stamp — that is what makes
4645
+ * "read, found nothing" distinguishable from "never read".
4646
+ */
4647
+ noteExpiryReading(accountId, nearestExpiryMs) {
4648
+ this.creditExpiryReadAt.set(accountId, Date.now());
4480
4649
  if (nearestExpiryMs === void 0 || !Number.isFinite(nearestExpiryMs)) {
4481
4650
  this.creditExpiry.delete(accountId);
4651
+ this.creditExpiryNone.add(accountId);
4482
4652
  return;
4483
4653
  }
4654
+ this.creditExpiryNone.delete(accountId);
4484
4655
  this.creditExpiry.set(accountId, nearestExpiryMs);
4485
4656
  }
4486
4657
  /** Nearest one-off pack expiry for one account, or undefined when none known. */
4487
4658
  creditExpiryOf(accountId) {
4488
4659
  return this.creditExpiry.get(accountId);
4489
4660
  }
4661
+ /**
4662
+ * The full three-state reading for one account, including staleness.
4663
+ *
4664
+ * `stale` is evaluated against {@link EXPIRY_READING_TTL_MS} here rather than
4665
+ * baked into the stored value, so the TTL stays a constant of the policy and
4666
+ * not of the data.
4667
+ *
4668
+ * Only a real deadline can go stale. "We never asked" is not a reading, and
4669
+ * "nothing here has a deadline" does not become less true with age: a monthly
4670
+ * pack does not grow an expiry date by waiting. Keeping `none` permanently
4671
+ * valid is what makes the S1 loop impossible — an account that answered once
4672
+ * is never read again by the expiry machinery, so there is no predicate that
4673
+ * can stay true forever and re-read it on every pass. If such an account does
4674
+ * gain a one-off pack later, the card refresh (which writes through
4675
+ * `noteCredits` on every poll) is what notices.
4676
+ */
4677
+ expiryReadingOf(accountId, now = Date.now()) {
4678
+ const at = this.creditExpiry.get(accountId);
4679
+ const readAtMs = this.creditExpiryReadAt.get(accountId);
4680
+ if (readAtMs === void 0) return {
4681
+ state: "unread",
4682
+ stale: false
4683
+ };
4684
+ if (at !== void 0) return {
4685
+ state: "at",
4686
+ at,
4687
+ readAtMs,
4688
+ stale: now - readAtMs > this.expiryReadingTtlMs
4689
+ };
4690
+ if (this.creditExpiryNone.has(accountId)) return {
4691
+ state: "none",
4692
+ readAtMs,
4693
+ stale: false
4694
+ };
4695
+ return {
4696
+ state: "unread",
4697
+ stale: false
4698
+ };
4699
+ }
4490
4700
  /** Last known balance for one account, or undefined when never read. */
4491
4701
  creditsOf(accountId) {
4492
4702
  return this.creditBalances.get(accountId);
@@ -10654,6 +10864,22 @@ const EVENT_CHAIN_BUILDERS = {
10654
10864
  WorkBuddy_Valorant: true
10655
10865
  };
10656
10866
  const AUTOMATION_TICK_MS = 6e4;
10867
+ /**
10868
+ * How long after {@link WorkBuddyScheduler.start} the second kick runs.
10869
+ *
10870
+ * Long enough for the pool's first account scan to have produced credentials,
10871
+ * short enough that a user watching the card sees the jobs land right away.
10872
+ */
10873
+ const AUTOMATION_START_SETTLE_MS = 5e3;
10874
+ /**
10875
+ * How long after {@link WorkBuddyScheduler.start} an extra startup pass may run.
10876
+ * This pass never consumes a future scheduled slot.
10877
+ *
10878
+ * Long enough to cover a slow first account scan plus the six jobs running one
10879
+ * after another, short enough that an app left open all day resumes its normal
10880
+ * schedule well before the next configured hour.
10881
+ */
10882
+ const AUTOMATION_STARTUP_CATCHUP_MS = 12e4;
10657
10883
  const JOB_KINDS = [
10658
10884
  "checkin",
10659
10885
  "report",
@@ -10831,6 +11057,17 @@ var WorkBuddyScheduler = class {
10831
11057
  travelHours;
10832
11058
  compensationHours;
10833
11059
  timer;
11060
+ /** The one-shot kick scheduled just after `start`; cleared by `stop`. */
11061
+ settleTimer;
11062
+ /**
11063
+ * Deadline for the start-of-day window described in {@link dueSlot}.
11064
+ *
11065
+ * Zero until {@link start} sets it, so a manual `tick` before the loop starts
11066
+ * keeps the original "only past hours" behaviour.
11067
+ */
11068
+ startupCatchUpUntilMs = 0;
11069
+ /** A startup pass is extra work; it never spends a future scheduled slot. */
11070
+ startupCompleted = /* @__PURE__ */ new Set();
10834
11071
  running = false;
10835
11072
  /** Guards against a slow run overlapping the next tick. */
10836
11073
  busy = false;
@@ -10960,6 +11197,29 @@ var WorkBuddyScheduler = class {
10960
11197
  if (this.timer !== void 0) return;
10961
11198
  this.stopped = false;
10962
11199
  this.running = true;
11200
+ /**
11201
+ * Launching DSH is itself a "run today's jobs" signal.
11202
+ *
11203
+ * `setInterval` alone delays the first pass by a whole tick, so an app
11204
+ * started at 17:57 ran every catch-up job at 17:58 and the card showed all
11205
+ * six stamped on the same minute — indistinguishable from "nothing happened
11206
+ * until I moved". Kicking the loop now, and once more shortly after, makes
11207
+ * "I started DSH" and "the automation started" the same moment.
11208
+ *
11209
+ * During this window, unrun jobs receive one extra startup pass. Past due
11210
+ * slots are consumed as normal; future slots remain scheduled.
11211
+ *
11212
+ * Both kicks are cheap no-ops when the pool has no accounts yet or the day
11213
+ * is already done: `tick` returns early on an empty pool, and `dueSlot`
11214
+ * finds nothing left to consume.
11215
+ */
11216
+ this.startupCompleted.clear();
11217
+ this.startupCatchUpUntilMs = this.now().getTime() + AUTOMATION_STARTUP_CATCHUP_MS;
11218
+ this.tick();
11219
+ this.settleTimer = setTimeout(() => {
11220
+ this.tick();
11221
+ }, AUTOMATION_START_SETTLE_MS);
11222
+ this.settleTimer.unref?.();
10963
11223
  this.timer = setInterval(() => {
10964
11224
  this.tick();
10965
11225
  }, AUTOMATION_TICK_MS);
@@ -10969,6 +11229,10 @@ var WorkBuddyScheduler = class {
10969
11229
  stop() {
10970
11230
  this.stopped = true;
10971
11231
  this.running = false;
11232
+ if (this.settleTimer !== void 0) {
11233
+ clearTimeout(this.settleTimer);
11234
+ this.settleTimer = void 0;
11235
+ }
10972
11236
  if (this.timer !== void 0) {
10973
11237
  clearInterval(this.timer);
10974
11238
  this.timer = void 0;
@@ -11100,6 +11364,8 @@ var WorkBuddyScheduler = class {
11100
11364
  * PASSED and its slot is still unconsumed, so a laptop that slept through
11101
11365
  * 10:00 still runs the job when it wakes, on the same day.
11102
11366
  *
11367
+ * Startup runs are handled separately in tick and do not spend a future slot.
11368
+ *
11103
11369
  * The EARLIEST unconsumed candidate wins, which is what keeps a two-hour job
11104
11370
  * (`travelHours: [9, 21]`) whole: consuming the earliest due slot leaves the
11105
11371
  * later one for its own hour.
@@ -11131,6 +11397,19 @@ var WorkBuddyScheduler = class {
11131
11397
  }
11132
11398
  async tick() {
11133
11399
  if (!this.enabled || this.stopped || this.busy) return;
11400
+ /**
11401
+ * Never spend a slot on an empty pool.
11402
+ *
11403
+ * The kick {@link start} fires runs within milliseconds of load, which in
11404
+ * some launches lands BEFORE the pool's first credential scan (measured: all
11405
+ * six jobs reported "0 accounts ok" while the card already listed two
11406
+ * accounts). `runJob` treats "0 eligible accounts" as a successful pass, so
11407
+ * the slot was marked consumed and the day's jobs never ran again — the
11408
+ * opposite of what the kick is for. Returning before the ledger is touched
11409
+ * leaves the slot unconsumed, so the settle kick and the regular timer pick
11410
+ * the work up as soon as the pool is ready.
11411
+ */
11412
+ if (this.pool.list().length === 0) return;
11134
11413
  this.busy = true;
11135
11414
  try {
11136
11415
  const now = this.now();
@@ -11140,8 +11419,9 @@ var WorkBuddyScheduler = class {
11140
11419
  if (this.stopped) return;
11141
11420
  if (this.states[kind].lastFiredHour === slot) continue;
11142
11421
  const consumed = this.dueSlot(kind, now);
11143
- if (consumed === void 0) continue;
11144
- await this.runJob(kind, today, consumed);
11422
+ const startup = consumed === void 0 && now.getTime() <= this.startupCatchUpUntilMs && !this.startupCompleted.has(kind);
11423
+ if (consumed === void 0 && !startup) continue;
11424
+ if (await this.runJob(kind, today, consumed, startup)) this.startupCompleted.add(kind);
11145
11425
  }
11146
11426
  } catch (error) {
11147
11427
  this.logger.warn?.("heybash-xdpool automation tick failed:", error);
@@ -11253,7 +11533,7 @@ var WorkBuddyScheduler = class {
11253
11533
  * while claiming wants the whole pool to have been lit up first. Splitting
11254
11534
  * them costs one shared wait instead of one wait per account.
11255
11535
  */
11256
- async runJob(kind, today, consumedSlot) {
11536
+ async runJob(kind, today, consumedSlot, startup = false) {
11257
11537
  const accountWord = kind === "report" ? "report" : kind;
11258
11538
  let ok = 0;
11259
11539
  let failed = 0;
@@ -11277,6 +11557,7 @@ var WorkBuddyScheduler = class {
11277
11557
  this.logger.warn?.("automation: could not probe benched accounts:", error);
11278
11558
  }
11279
11559
  const accounts = this.accountsInOrder(kind);
11560
+ if (accounts.length === 0 || this.stopped) return false;
11280
11561
  if (kind === "tasks") await this.sendEventChains(accounts);
11281
11562
  for (let index = 0; index < accounts.length; index++) {
11282
11563
  if (this.stopped) break;
@@ -11357,7 +11638,7 @@ var WorkBuddyScheduler = class {
11357
11638
  }
11358
11639
  const state = this.states[kind];
11359
11640
  if (consumedSlot !== void 0) this.consumeSlot(kind, consumedSlot);
11360
- state.lastFiredHour = slotKey(this.now());
11641
+ if (!startup) state.lastFiredHour = slotKey(this.now());
11361
11642
  state.lastRunDate = today;
11362
11643
  state.lastRunAtMs = this.now().getTime();
11363
11644
  state.ok = ok;
@@ -11372,6 +11653,7 @@ var WorkBuddyScheduler = class {
11372
11653
  else state.progress = progressNote;
11373
11654
  this.logger.info?.(`automation ${accountWord}: ${state.message}`);
11374
11655
  if (kind === "tasks" || kind === "checkin" || kind === "streak" || kind === "travel" || kind === "compensation") await this.flushEarnings();
11656
+ return true;
11375
11657
  }
11376
11658
  /** Compose the one-line summary shown on the card. */
11377
11659
  summarise(kind, ok, failed, claimed, credit, energy) {