heybash-xdpool 1.0.5 → 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,12 @@
1
1
  # Heybash
2
2
 
3
+ ## 1.0.6 — 并行工具调用修复
4
+
5
+ - 修复聚合路由在同时调用多个工具时混合参数,避免出现 MALFORMED_RESPONSE 并中断会话。
6
+ - 修复路由渠道成员 ID 的分组、保存和旧格式兼容;保留图片能力、推理档位与上下文配置。
7
+ - 修复积分浮层在视口缩放或偏移时的定位;启动时及时执行积分自动化,保留未来定时任务。
8
+ - 改善渠道网络传输、积分到期优先策略与免费模型错误提示,网关支持非流式响应。
9
+
3
10
  ## 1.0.5 — 积分浮层定位修复
4
11
 
5
12
  - 修复输入框积分浮层在部分宿主布局和缩放环境下偏离按钮;窗口尺寸或滚动变化时保持位置并避免越界。
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) {
package/lib/client.js CHANGED
@@ -1797,7 +1797,11 @@ window.__ModuleLoader__.load({
1797
1797
  .dsm-xdpool-dot[data-state='empty']{color:color-mix(in srgb, var(--dsw-alias-label-tertiary,#8a90a0) 85%, transparent)}
1798
1798
  .dsm-xdpool-dot:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:3px}
1799
1799
  /* Measured coordinates, not flow: the composer sits at the bottom of the viewport, so a
1800
- panel laid out downward would be clipped. */
1800
+ panel laid out downward would be clipped.
1801
+
1802
+ fixed is required, not incidental: the panel is portaled to document.body, so it has
1803
+ no dot wrapper to anchor to. Placement accounts for visual viewport offsets
1804
+ when a zoomed viewport is smaller than the layout viewport. */
1801
1805
  .dsm-xdpool-dotpanel{position:fixed;z-index:80;box-sizing:border-box;width:max-content;min-width:min(172px,calc(100vw - 16px));max-width:min(280px,calc(100vw - 16px));max-height:calc(100vh - 16px);overflow-y:auto;display:flex;flex-direction:column;gap:7px;padding:10px 12px 11px;border-radius:14px;border:1px solid color-mix(in srgb, var(--dsw-alias-border-l2,#ffffff1f) 92%, transparent);background:var(--dsw-alias-bg-layer-2,#1c1e22);box-shadow:0 18px 48px rgb(0 0 0 / 44%),0 3px 10px rgb(0 0 0 / 24%),inset 0 1px 0 rgb(255 255 255 / 7%);animation:dsm-xdpool-dotpanel-in .16s cubic-bezier(.16,1,.3,1)}
1802
1806
  @keyframes dsm-xdpool-dotpanel-in{from{opacity:0}to{opacity:1}}
1803
1807
  .dsm-xdpool-dotpanel-head{display:flex;align-items:center;gap:8px;min-width:0}
@@ -7889,6 +7893,32 @@ window.__ModuleLoader__.load({
7889
7893
  "anthropic-messages": "/messages"
7890
7894
  });
7891
7895
  typeof process === "undefined" || process.platform;
7896
+ // src/member-id.ts
7897
+ /** A login channel member has a colon before any slash in its model id. */
7898
+ function channelMemberOf(id) {
7899
+ const colon = id.indexOf(":");
7900
+ if (colon <= 0) return void 0;
7901
+ const channel = id.slice(0, colon);
7902
+ const model = id.slice(colon + 1);
7903
+ if (!/^[A-Za-z0-9_-]+$/u.test(channel) || model === "" || model.startsWith("//")) return void 0;
7904
+ return {
7905
+ channel,
7906
+ model: id
7907
+ };
7908
+ }
7909
+ /** Remove repeated legacy slash prefixes while preserving canonical colon IDs. */
7910
+ function memberForOwner(owner, model) {
7911
+ if (owner === "workbuddy") return model;
7912
+ while (model.startsWith(`${owner}/`)) model = model.slice(owner.length + 1);
7913
+ while (model.startsWith(`${owner}:${owner}:`)) model = model.slice(owner.length + 1);
7914
+ return model;
7915
+ }
7916
+ /** Flatten one editor member; canonical channel IDs are already complete. */
7917
+ function flattenMember(owner, model) {
7918
+ const value = memberForOwner(owner, model);
7919
+ if (owner === "workbuddy" || channelMemberOf(value)?.channel === owner) return value;
7920
+ return `${owner}/${value}`;
7921
+ }
7892
7922
  Object.freeze({
7893
7923
  "openai-chat": "chat",
7894
7924
  "openai-responses": "responses",
@@ -10137,17 +10167,11 @@ window.__ModuleLoader__.load({
10137
10167
  * a fallback that never happened. A pool model is its bare id; anything else is
10138
10168
  * `owner/model`, the same composite id the aggregate catalog publishes.
10139
10169
  */
10140
- function bareForOwner(owner, model) {
10141
- if (owner === "workbuddy") return model;
10142
- while (model.startsWith(`${owner}/`) || model.startsWith(`${owner}:`)) model = model.slice(owner.length + 1);
10143
- return model;
10144
- }
10145
10170
  function flattenDraft(platforms) {
10146
10171
  const out = [];
10147
10172
  const seen = /* @__PURE__ */ new Set();
10148
10173
  for (const platform of platforms) for (const model of platform.models) {
10149
- const bare = bareForOwner(platform.owner, model);
10150
- const id = platform.owner === "workbuddy" ? bare : `${platform.owner}/${bare}`;
10174
+ const id = flattenMember(platform.owner, model);
10151
10175
  if (seen.has(id)) continue;
10152
10176
  seen.add(id);
10153
10177
  out.push(id);
@@ -10175,17 +10199,16 @@ window.__ModuleLoader__.load({
10175
10199
  const owner = typeof group.owner === "string" ? group.owner : "workbuddy";
10176
10200
  return {
10177
10201
  owner,
10178
- models: Array.isArray(group.models) ? [...new Set(group.models.filter((model) => typeof model === "string").map((model) => bareForOwner(owner, model)))] : []
10202
+ models: Array.isArray(group.models) ? [...new Set(group.models.filter((model) => typeof model === "string").map((model) => memberForOwner(owner, model)))] : []
10179
10203
  };
10180
10204
  });
10181
10205
  const known = new Set(Array.isArray(combo.models) ? combo.models : []);
10182
10206
  for (const modelId of Array.isArray(combo.missing) ? combo.missing : []) {
10183
10207
  if (known.has(modelId)) continue;
10208
+ const channel = channelMemberOf(modelId);
10184
10209
  const slash = modelId.indexOf("/");
10185
- const colon = modelId.indexOf(":");
10186
- const separator = slash === -1 ? colon : colon === -1 ? slash : Math.min(slash, colon);
10187
- const owner = separator === -1 ? "workbuddy" : modelId.slice(0, separator);
10188
- const model = bareForOwner(owner, separator === -1 ? modelId : modelId.slice(separator + 1));
10210
+ const owner = channel?.channel ?? (slash === -1 ? "workbuddy" : modelId.slice(0, slash));
10211
+ const model = channel?.model ?? memberForOwner(owner, slash === -1 ? modelId : modelId.slice(slash + 1));
10189
10212
  const group = platforms.find((entry) => entry.owner === owner);
10190
10213
  if (group === void 0) platforms.push({
10191
10214
  owner,
@@ -10766,7 +10789,7 @@ window.__ModuleLoader__.load({
10766
10789
  }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
10767
10790
  className: "dsm-xdpool-rt-members",
10768
10791
  children: platform.models.map((model, modelIndex) => {
10769
- const fullId = platform.owner === "workbuddy" ? model : `${platform.owner}/${model}`;
10792
+ const fullId = flattenMember(platform.owner, model);
10770
10793
  const candidate = candidateById.get(fullId);
10771
10794
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
10772
10795
  className: "dsm-xdpool-rt-member",
@@ -13295,7 +13318,7 @@ window.__ModuleLoader__.load({
13295
13318
  }
13296
13319
  // src/version.ts
13297
13320
  /** Version embedded in the browser bundle at build time from the package manifest. */
13298
- const POOL_VERSION = "1.0.5";
13321
+ const POOL_VERSION = "1.0.6";
13299
13322
  // src/client/PoolCard.tsx
13300
13323
  /**
13301
13324
  * Heybash card contributed to DSH Plugin configuration.
@@ -15826,12 +15849,14 @@ window.__ModuleLoader__.load({
15826
15849
  /** Position a measured panel above its trigger, flipping and clamping at viewport edges. */
15827
15850
  function creditPanelPosition(anchor, panel, viewport) {
15828
15851
  const margin = 8;
15829
- const left = Math.min(Math.max(margin, anchor.left + anchor.width / 2 - panel.width / 2), Math.max(margin, viewport.width - panel.width - margin));
15852
+ const minLeft = (viewport.left ?? 0) + margin;
15853
+ const minTop = (viewport.top ?? 0) + margin;
15854
+ const left = Math.min(Math.max(minLeft, anchor.left + anchor.width / 2 - panel.width / 2), Math.max(minLeft, (viewport.left ?? 0) + viewport.width - panel.width - margin));
15830
15855
  const above = anchor.top - panel.height - margin;
15831
15856
  const below = anchor.bottom + margin;
15832
- const preferAbove = above >= margin || anchor.top >= viewport.height - anchor.bottom;
15857
+ const preferAbove = above >= minTop || anchor.top - (viewport.top ?? 0) >= (viewport.top ?? 0) + viewport.height - anchor.bottom;
15833
15858
  return {
15834
- top: Math.min(Math.max(margin, preferAbove ? above : below), Math.max(margin, viewport.height - panel.height - margin)),
15859
+ top: Math.min(Math.max(minTop, preferAbove ? above : below), Math.max(minTop, (viewport.top ?? 0) + viewport.height - panel.height - margin)),
15835
15860
  left
15836
15861
  };
15837
15862
  }
@@ -16166,7 +16191,7 @@ window.__ModuleLoader__.load({
16166
16191
  observer.disconnect();
16167
16192
  };
16168
16193
  }, []);
16169
- /** Keep body-relative panel and viewport-relative anchor in the same coordinate space. */
16194
+ /** Keep the anchor and fixed panel in layout-viewport CSS coordinates. */
16170
16195
  (0, react.useLayoutEffect)(() => {
16171
16196
  if (!open) {
16172
16197
  setPos(void 0);
@@ -16178,9 +16203,20 @@ window.__ModuleLoader__.load({
16178
16203
  let frame;
16179
16204
  const update = () => {
16180
16205
  frame = void 0;
16181
- const { left, top } = creditPanelPosition(anchor.getBoundingClientRect(), panel.getBoundingClientRect(), {
16206
+ const box = anchor.getBoundingClientRect();
16207
+ const panelBox = {
16208
+ width: panel.offsetWidth,
16209
+ height: panel.offsetHeight
16210
+ };
16211
+ const vv = window.visualViewport;
16212
+ const { left, top } = creditPanelPosition(box, panelBox, vv === null || vv === void 0 ? {
16182
16213
  width: window.innerWidth,
16183
16214
  height: window.innerHeight
16215
+ } : {
16216
+ width: vv.width,
16217
+ height: vv.height,
16218
+ left: vv.offsetLeft,
16219
+ top: vv.offsetTop
16184
16220
  });
16185
16221
  setPos((current) => current?.top === top && current.left === left ? current : {
16186
16222
  top,
@@ -16196,10 +16232,14 @@ window.__ModuleLoader__.load({
16196
16232
  observer?.observe(panel);
16197
16233
  window.addEventListener("resize", schedule);
16198
16234
  window.addEventListener("scroll", schedule, true);
16235
+ window.visualViewport?.addEventListener("resize", schedule);
16236
+ window.visualViewport?.addEventListener("scroll", schedule);
16199
16237
  return () => {
16200
16238
  observer?.disconnect();
16201
16239
  window.removeEventListener("resize", schedule);
16202
16240
  window.removeEventListener("scroll", schedule, true);
16241
+ window.visualViewport?.removeEventListener("resize", schedule);
16242
+ window.visualViewport?.removeEventListener("scroll", schedule);
16203
16243
  if (frame !== void 0) window.cancelAnimationFrame(frame);
16204
16244
  };
16205
16245
  }, [