maxpool 1.24.80 → 1.24.82
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/package.json +1 -1
- package/src/account-manager.js +725 -35
- package/src/claude-reset-grants.js +124 -24
- package/src/index.js +1 -0
- package/src/prober.js +162 -14
- package/src/reset-policy.js +130 -25
- package/src/reset-timing.js +27 -0
- package/src/server.js +486 -93
- package/src/tui.js +111 -28
- package/src/zai-reset-cards.js +20 -6
package/src/tui.js
CHANGED
|
@@ -5,6 +5,9 @@ import { fetchProfile, loginOAuth, tokenFingerprint, isLoginCancelled } from './
|
|
|
5
5
|
import { appendEventLog, setConsoleStdoutSuppressed } from './event-log.js';
|
|
6
6
|
import { sendLoginToPool } from './cloud-login.js';
|
|
7
7
|
import { describeLinkError } from './pool-link.js';
|
|
8
|
+
import { normalizeRemoteResets } from './account-manager.js';
|
|
9
|
+
import { appliesTo } from './claude-reset-grants.js';
|
|
10
|
+
import { LISTING_FRESH_MS } from './reset-timing.js';
|
|
8
11
|
|
|
9
12
|
// ── ANSI helpers ─────────────────────────────────────────────
|
|
10
13
|
|
|
@@ -571,6 +574,12 @@ export class TUI {
|
|
|
571
574
|
if (r) r.account = info.account;
|
|
572
575
|
}
|
|
573
576
|
|
|
577
|
+
/** First response byte reached the client (server.js markFirstByte). */
|
|
578
|
+
onRequestFirstByte(id) {
|
|
579
|
+
const r = this.active.get(id);
|
|
580
|
+
if (r && r.firstByteAt == null) r.firstByteAt = Date.now();
|
|
581
|
+
}
|
|
582
|
+
|
|
574
583
|
onRequestEnd(id, info) {
|
|
575
584
|
const r = this.active.get(id);
|
|
576
585
|
this.active.delete(id);
|
|
@@ -593,7 +602,19 @@ export class TUI {
|
|
|
593
602
|
const provTag = (isProvider && r?.sessionKey) ? ` [sess ${String(r.sessionKey).slice(0, 8)}]` : '';
|
|
594
603
|
const cv = info.conversation || r?.conversation;
|
|
595
604
|
const cvTag = cv ? ` [cv ${cv.slice(0, 8)} ${String(info.sessionKey || r?.sessionKey || '').slice(0, 8)}]` : '';
|
|
596
|
-
|
|
605
|
+
// ttfb LAST: the UPSTREAM wait of the attempt that served — its fetch resolve
|
|
606
|
+
// minus its own forward start (D, 2026-11-10). Never measured from arrival:
|
|
607
|
+
// that would add queue wait and earlier failover attempts. Falls back to the
|
|
608
|
+
// client-write stamp from arrival when no upstream pair exists (a request that
|
|
609
|
+
// never reached upstream, the link path). Omitted when no byte was ever sent.
|
|
610
|
+
let ttfbMs = null;
|
|
611
|
+
if (info.firstUpstreamByteAt != null && info.upstreamForwardStartAt != null) {
|
|
612
|
+
ttfbMs = info.firstUpstreamByteAt - info.upstreamForwardStartAt;
|
|
613
|
+
} else if (r?.firstByteAt != null) {
|
|
614
|
+
ttfbMs = r.firstByteAt - r.started;
|
|
615
|
+
}
|
|
616
|
+
const ttfbTag = ttfbMs != null ? ` ttfb=${(Math.max(0, ttfbMs) / 1000).toFixed(1)}s` : '';
|
|
617
|
+
this._addLog(`${who}${info.method} ${info.path} → ${acct} (${info.status}, ${dur}s)${provTag}${cvTag}${ttfbTag}`);
|
|
597
618
|
}
|
|
598
619
|
|
|
599
620
|
_addLog(msg) {
|
|
@@ -2287,12 +2308,33 @@ export class TUI {
|
|
|
2287
2308
|
const live = a?.poolBenchedBy ? this.am.remoteRowFor?.(a) : null;
|
|
2288
2309
|
if (live) {
|
|
2289
2310
|
const r = live.row;
|
|
2311
|
+
// B2 (2026-11-10): the overlay also carries the cloud twin's RESETS via the
|
|
2312
|
+
// same normalizeRemoteResets the mirror rows use. When the twin's snapshot is
|
|
2313
|
+
// MISSING the reset fields (one failed link poll — the "2 → gone → back"
|
|
2314
|
+
// flicker through a new path), keep the PREVIOUS overlay marked not-fresh,
|
|
2315
|
+
// never 0.
|
|
2316
|
+
let resetsOverlay;
|
|
2317
|
+
if (r.resetGrants != null || r.resetCards != null || r.capLift != null) {
|
|
2318
|
+
const nr = normalizeRemoteResets(r);
|
|
2319
|
+
resetsOverlay = { resetGrants: nr.resetGrants, resetCards: nr.resetCards, capLift: nr.capLift };
|
|
2320
|
+
} else {
|
|
2321
|
+
const prev = a._twinResetsOverlay || {};
|
|
2322
|
+
resetsOverlay = {
|
|
2323
|
+
resetGrants: prev.resetGrants ? { ...prev.resetGrants, stale: true } : null,
|
|
2324
|
+
resetCards: prev.resetCards ? { ...prev.resetCards, stale: true } : null,
|
|
2325
|
+
capLift: prev.capLift ?? null,
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
a._twinResetsOverlay = resetsOverlay; // remember for the next frame's fallback
|
|
2290
2329
|
a = Object.assign(Object.create(Object.getPrototypeOf(a)), a, {
|
|
2291
2330
|
quota: { ...a.quota, ...(r.quota || {}) },
|
|
2292
2331
|
inFlight: r.inFlight ?? 0,
|
|
2293
2332
|
completedRequests: r.completedRequests ?? a.completedRequests,
|
|
2294
2333
|
refreshDead: Boolean(r.refreshDead),
|
|
2295
2334
|
rateLimitedUntil: r.rateLimitedUntil ? Date.parse(r.rateLimitedUntil) : null,
|
|
2335
|
+
resetGrants: resetsOverlay.resetGrants,
|
|
2336
|
+
resetCards: resetsOverlay.resetCards,
|
|
2337
|
+
capLift: resetsOverlay.capLift,
|
|
2296
2338
|
});
|
|
2297
2339
|
}
|
|
2298
2340
|
|
|
@@ -2428,41 +2470,82 @@ export class TUI {
|
|
|
2428
2470
|
// column showing 0 or the count). z.ai cards + Claude cedar_ember grants,
|
|
2429
2471
|
// not-yet-expired, on ENABLED accounts only: a disabled account's resets are
|
|
2430
2472
|
// not ours to spend, and showing a count there would imply otherwise.
|
|
2473
|
+
//
|
|
2474
|
+
// B3 grammar (2026-11-10), rendered width EXACTLY RESETS_W (6):
|
|
2475
|
+
// general n~Xd e.g. 2~119d
|
|
2476
|
+
// scoped nF~Xd e.g. 2F~4d (model-scoped, e.g. Fable)
|
|
2477
|
+
// mixed g+sF e.g. 1+2F
|
|
2478
|
+
// unknown n? scope unknown — count shown, never claimed
|
|
2479
|
+
// not-fresh = gray + trailing '?' (stale listing, dead account, old check)
|
|
2480
|
+
// Count = SUM of resetsLeft over spendable grants + live cards (not entries).
|
|
2481
|
+
// Overflow order: drop the suffix first, then collapse to total+'*'.
|
|
2482
|
+
// Expiry is checked LIVE here: grants endsAt>now, cards !expired &&
|
|
2483
|
+
// (expiresAt==null || expiresAt>now) — a frozen `expired` flag never keeps a
|
|
2484
|
+
// dead reset on screen (pre-mortem #18).
|
|
2431
2485
|
let resetsCell;
|
|
2432
2486
|
{
|
|
2433
|
-
|
|
2487
|
+
const now = Date.now();
|
|
2488
|
+
let general = 0; // resetsLeft of general-weekly grants + live cards
|
|
2489
|
+
let scoped = 0; // resetsLeft of model-scoped grants (tagged F)
|
|
2490
|
+
let unknown = 0; // resetsLeft of scope-unknown grants
|
|
2491
|
+
let soonest = Infinity;
|
|
2434
2492
|
if (a.enabled !== false) {
|
|
2493
|
+
const liveCard = c => c && !c.expired && (c.expiresAt == null || c.expiresAt > now);
|
|
2435
2494
|
const rc = a.resetCards;
|
|
2436
|
-
if (rc)
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
}
|
|
2441
|
-
// Expiry rides with the count when it's tight: "1~2d" = 1 reset, expires in ~2 days.
|
|
2442
|
-
// Claude grants end mid-Oct (weeks out) — a day-count would be noise; only the
|
|
2443
|
-
// SOONEST-expiring card under 7 days gets a suffix, so the column stays narrow
|
|
2444
|
-
// and the number it carries still answers "use it or lose it?".
|
|
2445
|
-
let suffix = '';
|
|
2446
|
-
if (n > 0) {
|
|
2447
|
-
let soonest = Infinity;
|
|
2448
|
-
const rc = a.resetCards;
|
|
2449
|
-
if (rc) for (const c of [...(rc.fiveHour || []), ...(rc.weekly || [])]) {
|
|
2450
|
-
if (!c.expired && c.expiresAt != null && c.expiresAt < soonest) soonest = c.expiresAt;
|
|
2495
|
+
if (rc) {
|
|
2496
|
+
for (const c of [...(rc.fiveHour || []), ...(rc.weekly || [])]) {
|
|
2497
|
+
if (liveCard(c)) { general += 1; if (c.expiresAt != null && c.expiresAt < soonest) soonest = c.expiresAt; }
|
|
2498
|
+
}
|
|
2451
2499
|
}
|
|
2452
2500
|
const rg = a.resetGrants;
|
|
2453
|
-
if (rg?.eligible
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2501
|
+
if (rg?.eligible !== false && rg) {
|
|
2502
|
+
for (const g of (rg.grants || [])) {
|
|
2503
|
+
if (!g || g.usableNow === false || g.paused || g.expired) continue;
|
|
2504
|
+
if (g.endsAt != null && g.endsAt <= now) continue; // live expiry
|
|
2505
|
+
// The ONE shared scope answer (A1) — display reads the same
|
|
2506
|
+
// classification as claim and lift.
|
|
2507
|
+
const scopes = appliesTo(g);
|
|
2508
|
+
const hasGeneral = scopes.includes('general');
|
|
2509
|
+
const hasScoped = scopes.some(x => x !== 'general' && x !== 'session');
|
|
2510
|
+
const left = Math.max(0, Math.floor(g.resetsLeft ?? 1));
|
|
2511
|
+
if (hasGeneral) general += left;
|
|
2512
|
+
else if (hasScoped) scoped += left;
|
|
2513
|
+
else unknown += left;
|
|
2514
|
+
if (g.endsAt != null && g.endsAt < soonest) soonest = g.endsAt;
|
|
2515
|
+
}
|
|
2463
2516
|
}
|
|
2464
2517
|
}
|
|
2465
|
-
|
|
2518
|
+
const total = general + scoped + unknown;
|
|
2519
|
+
// Not-fresh (pre-mortem #15): stale listing, a dead account, or a check older
|
|
2520
|
+
// than 3x the grants cadence. An account that stopped being probed never gets
|
|
2521
|
+
// re-listed, so checkedAt alone would show a green count forever.
|
|
2522
|
+
const freshGrants = a.resetGrants && a.resetGrants.stale !== true
|
|
2523
|
+
&& (a.resetGrants.checkedAt == null || now - a.resetGrants.checkedAt <= LISTING_FRESH_MS);
|
|
2524
|
+
const freshCards = !a.resetCards || (a.resetCards.stale !== true
|
|
2525
|
+
&& (a.resetCards.checkedAt == null || now - a.resetCards.checkedAt <= LISTING_FRESH_MS));
|
|
2526
|
+
const notFresh = total > 0 && (!freshGrants || !freshCards || a.refreshDead || a.subscriptionGone);
|
|
2527
|
+
|
|
2528
|
+
// Core text per the grammar.
|
|
2529
|
+
let core;
|
|
2530
|
+
if (total === 0) core = '0';
|
|
2531
|
+
else if (unknown > 0 && general === 0 && scoped === 0) core = `${unknown}?`;
|
|
2532
|
+
else if (general > 0 && scoped > 0) core = `${general}+${scoped}F`;
|
|
2533
|
+
else if (scoped > 0) core = `${scoped}F`;
|
|
2534
|
+
else core = `${general}`;
|
|
2535
|
+
|
|
2536
|
+
// Expiry suffix (owner 2026-10-01: always show when a reset exists).
|
|
2537
|
+
let suffix = '';
|
|
2538
|
+
if (total > 0 && soonest !== Infinity) {
|
|
2539
|
+
const days = (soonest - now) / 86400_000;
|
|
2540
|
+
suffix = days < 1 ? `~${Math.max(1, Math.round(days * 24))}h` : `~${Math.max(1, Math.round(days))}d`;
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
// Fit to EXACTLY RESETS_W: full form, then drop the suffix, then total+'*'.
|
|
2544
|
+
let text = core + suffix;
|
|
2545
|
+
if (text.length > RESETS_W) text = core;
|
|
2546
|
+
if (text.length > RESETS_W) text = `${total}*`.slice(0, RESETS_W);
|
|
2547
|
+
if (notFresh) text = (text + '?').length <= RESETS_W ? text + '?' : `${total}?`.slice(0, RESETS_W);
|
|
2548
|
+
resetsCell = rpad(total > 0 && !notFresh ? green(text) : gray(text), RESETS_W);
|
|
2466
2549
|
}
|
|
2467
2550
|
|
|
2468
2551
|
if (a.type === 'provider') {
|
package/src/zai-reset-cards.js
CHANGED
|
@@ -60,7 +60,10 @@ function normalizeCards(arr, now = Date.now()) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/** List this account's available reset cards. Zero-spend read.
|
|
63
|
-
* Returns { fiveHour: [], weekly: [] } | { error }.
|
|
63
|
+
* Returns { fiveHour: [], weekly: [] } | { error }.
|
|
64
|
+
* DRIFT (A4, 2026-11-10): a 200 whose expected arrays are missing, or whose raw
|
|
65
|
+
* entries all vanish in normalization (renamed field), is reported as an ERROR —
|
|
66
|
+
* never as an empty "good" list that overwrites the last known cards. */
|
|
64
67
|
export async function listResetCards(token, { signal, fetchImpl = fetch } = {}) {
|
|
65
68
|
if (!token) return { error: 'no token' };
|
|
66
69
|
try {
|
|
@@ -74,11 +77,22 @@ export async function listResetCards(token, { signal, fetchImpl = fetch } = {})
|
|
|
74
77
|
return { error: `bad_envelope${data?.code != null ? ' code=' + data.code : ''}` };
|
|
75
78
|
}
|
|
76
79
|
const now = Date.now();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const fiveHour = normalizeCards(data.data.fiveHourResets, now);
|
|
81
|
+
const weekly = normalizeCards(data.data.weekResets, now);
|
|
82
|
+
// Drift guard: the raw arrays are the expected shape; if either is missing, or
|
|
83
|
+
// raw entries exist but none survived normalization, the schema moved. An
|
|
84
|
+
// `available:false` entry is LEGITIMATELY dropped by normalizeCards — only
|
|
85
|
+
// entries that claim to be available count toward the drift check.
|
|
86
|
+
const rawFive = Array.isArray(data.data.fiveHourResets) ? data.data.fiveHourResets : null;
|
|
87
|
+
const rawWeek = Array.isArray(data.data.weekResets) ? data.data.weekResets : null;
|
|
88
|
+
if (rawFive == null || rawWeek == null) {
|
|
89
|
+
return { error: 'drift: expected arrays missing' };
|
|
90
|
+
}
|
|
91
|
+
const availableRaw = [...rawFive, ...rawWeek].filter(c => c && c.available !== false).length;
|
|
92
|
+
if (availableRaw > 0 && fiveHour.length + weekly.length === 0) {
|
|
93
|
+
return { error: `drift: ${availableRaw} raw entr${availableRaw === 1 ? 'y' : 'ies'}, 0 kept` };
|
|
94
|
+
}
|
|
95
|
+
return { fiveHour, weekly, source: 'zai' };
|
|
82
96
|
} catch (err) {
|
|
83
97
|
return { error: err.message || String(err) };
|
|
84
98
|
}
|