maxpool 1.24.93 → 1.24.95

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/src/tui.js CHANGED
@@ -2,7 +2,7 @@ import { createInterface } from 'node:readline';
2
2
  import { readFileSync, writeSync } from 'node:fs';
3
3
  import { isatty } from 'node:tty';
4
4
  import { homedir } from 'node:os';
5
- import { fetchProfile, loginOAuth, tokenFingerprint, isLoginCancelled } from './oauth.js';
5
+ import { fetchProfile, loginOAuth, tokenFingerprint, isLoginCancelled, sameUser, sameAccountIdentity, organizationUnknownMatch, resolveOrganizations, suggestAccountName, knownDifferentOrg } from './oauth.js';
6
6
  import { appendEventLog, setConsoleStdoutSuppressed } from './event-log.js';
7
7
  import { sendLoginToPool } from './cloud-login.js';
8
8
  import { describeLinkError } from './pool-link.js';
@@ -140,8 +140,8 @@ const vw = s => strip(s).length;
140
140
  // ── Accounts-table columns ───────────────────────────────────
141
141
  // Fixed column widths shared by the header row (acctHeader) AND every data row, so
142
142
  // the header labels stay aligned with the columns they name. The Account/Provider/
143
- // Status/Quota start offsets (4/25/35/49) are pure functions of these widths + the
144
- // 4-col row prefix, independent of the quota-bar width.
143
+ // Status/Rst/Quota start offsets (4/25/35/49/56) are pure functions of these widths +
144
+ // the 4-col row prefix, independent of the quota-bar width.
145
145
  const NAME_W = 20; // a.name.slice(0, NAME_W).padEnd(NAME_W) — fits a full email like 2solarmax@gmail.com (19)
146
146
  const WHERE_W = 5; // 'Local' / 'Cloud' — where the account is provisioned
147
147
  const PROVIDER_W = 9; // providerLabel(a).padEnd(PROVIDER_W) — fits "Anthropic"
@@ -171,8 +171,8 @@ function providerLabel(a) {
171
171
 
172
172
  /**
173
173
  * Aligned column header for the accounts table. Names the three columns that carry
174
- * NO inline label (Account / Type / Status) plus a group label over the two quota
175
- * bars (Quota). The per-bar naming (Ses/Wk for OAuth, Tok/Req for API keys) and the
174
+ * NO inline label (Account / Type / Status) plus a group label over the quota bars
175
+ * (Quota). The per-bar naming (Ses/Fbl/Wk for OAuth, Tok/Fbl/Req for API keys) and the
176
176
  * load fields (Now/15m/1h) stay inline per row — they're row-type-dependent and
177
177
  * begin at a variable offset — so the header stops after the Quota group label.
178
178
  */
@@ -193,6 +193,45 @@ function lpadVis(s, w) {
193
193
  return gap > 0 ? ' '.repeat(gap) + s : s;
194
194
  }
195
195
 
196
+ /**
197
+ * Which quota bars fit a terminal W columns wide, and how wide each bar is. The
198
+ * space before the first bar comes from the column widths above, never from a
199
+ * hard-coded number (the old number went stale when the Rst column was added).
200
+ * Each extra bar costs its label gap (" Fbl " or " Wk ") plus one bar width.
201
+ * Under 70 columns only the session bar shows, 5 to 20 wide; from 70 the weekly
202
+ * bar joins it, both 5 to 20 wide. The Fable bar joins only once all three can be
203
+ * 9 wide (112 columns), the narrowest bar that still shows "100% 2d5h", and three
204
+ * bars stop growing at 11 wide, so the row never passes column 118 and the tags
205
+ * after the bars (cap, prefer, staleness) keep the room they have with two bars.
206
+ * Narrower terminals keep today's two bars plus the "Fable NN%" tag.
207
+ * When no account reports a session window, the session bar is left out: the
208
+ * weekly bar always shows and the Fable bar joins it from 97 columns.
209
+ */
210
+ const BAR_START = ROW_PREFIX.length + NAME_W + 1 + WHERE_W + 1 + PROVIDER_W + 1 + STATUS_W + 1 + RESETS_W + 1 + 'Ses '.length;
211
+ const BAR_GAP = ' Wk '.length;
212
+ const BAR_MIN_W = 5;
213
+ const BAR_MAX_W = 20;
214
+ const FABLE_BAR_MIN_W = 9;
215
+ const THREE_BAR_MAX_W = 11;
216
+ function barLayout(W, showSession = true) {
217
+ const showBoth = W >= 70 || !showSession;
218
+ const others = (showSession ? 1 : 0) + (showBoth ? 1 : 0);
219
+ const showFable = W >= BAR_START + (others + 1) * FABLE_BAR_MIN_W + others * BAR_GAP;
220
+ const bars = others + (showFable ? 1 : 0);
221
+ const free = W - BAR_START - (bars - 1) * BAR_GAP;
222
+ const fit = Math.floor(free / bars);
223
+ const maxW = bars === 3 ? THREE_BAR_MAX_W : BAR_MAX_W;
224
+ const bw = Math.max(BAR_MIN_W, Math.min(maxW, fit));
225
+ return { showSession, showBoth, showFable, bw };
226
+ }
227
+
228
+ /** True when the account's first bar (Ses, or Tok for an API key) has a reading. */
229
+ function hasSessionReading(a) {
230
+ const q = a?.quota || {};
231
+ if (a?.type === 'provider') return q.providerSes != null;
232
+ return q.unified5h != null || (q.tokensLimit != null && q.tokensRemaining != null);
233
+ }
234
+
196
235
  function rpad(s, w) {
197
236
  const gap = w - vw(s);
198
237
  return gap > 0 ? s + ' '.repeat(gap) : s;
@@ -541,6 +580,20 @@ function emptyBar(label, w = 10) {
541
580
  return `${ESC}100m${' '.repeat(lp)}${text}${' '.repeat(rp)}${RESET}`;
542
581
  }
543
582
 
583
+ /**
584
+ * The "Fbl" bar: one model family's weekly limit, which Anthropic counts separately
585
+ * from the account-wide weekly. Drawn with the same bar() as Ses and Wk, so it reads
586
+ * the same way (used% and time to reset). Shows the empty dash cell when there is
587
+ * nothing to show: a provider row, no probe result yet, or a limit Anthropic marks
588
+ * as inactive. Routing
589
+ * and the "Fable NN%" tag ignore an inactive limit too, so the bar stays quiet as well.
590
+ */
591
+ function scopedWeeklyBar(quota, family, w) {
592
+ const e = quota?.scopedWeekly?.[family];
593
+ if (!e || e.isActive === false || e.utilization == null) return emptyBar('—', w);
594
+ return bar(e.utilization, w, e.resetAt);
595
+ }
596
+
544
597
  /** Write a provider's enabled flag into the CONFIG entry `loadConfigProviders` reads.
545
598
  *
546
599
  * A config-sourced provider is re-created from config on every reload
@@ -562,7 +615,7 @@ export function applyProviderEnabledToConfig(config, name, enabled) {
562
615
  return { changed: true, previous };
563
616
  }
564
617
 
565
- export const __tuiTest = { applyProviderEnabledToConfig, formatReset, quotaLabel, bar, emptyBar, strip, loadText, countdown, acctHeader, fitLine, providerLabel, weeklyPolicyText, capText, capEffectivePct };
618
+ export const __tuiTest = { applyProviderEnabledToConfig, formatReset, quotaLabel, bar, emptyBar, scopedWeeklyBar, barLayout, strip, loadText, countdown, acctHeader, fitLine, providerLabel, weeklyPolicyText, capText, capEffectivePct };
566
619
 
567
620
  function timestamp() {
568
621
  return new Date().toLocaleTimeString('en-US', { hour12: false });
@@ -1160,7 +1213,7 @@ export class TUI {
1160
1213
  } else if (k === 'l') {
1161
1214
  this._confirm(
1162
1215
  'Log in / re-authenticate via browser?',
1163
- 'Opens a browser. Logging into an account that\'s already added RE-AUTHENTICATES it in place (revives a reauth/error account) — no duplicate. Otherwise a new account is added.',
1216
+ 'Opens a browser. Logging into an account that\'s already added (same user, same organization) RE-AUTHENTICATES it in place (revives a reauth/error account) — no duplicate. Another organization of the same user, or a new user, is added as a new account.',
1164
1217
  () => this._doLogin(),
1165
1218
  );
1166
1219
  } else if (k === 'n' && this.am.accounts.length > 0) {
@@ -1200,7 +1253,7 @@ export class TUI {
1200
1253
  this.mode = 'accounts';
1201
1254
  this._confirm(
1202
1255
  'Log in / re-authenticate via browser?',
1203
- 'Opens a browser. Logging into an account that is already added RE-AUTHENTICATES it in place — no duplicate.',
1256
+ 'Opens a browser. Logging into an account that is already added (same user, same organization) RE-AUTHENTICATES it in place — no duplicate. Another organization of the same user is added as a new account.',
1204
1257
  () => this._doLogin(),
1205
1258
  );
1206
1259
  return;
@@ -1731,7 +1784,7 @@ export class TUI {
1731
1784
  }
1732
1785
 
1733
1786
  // Browser OAuth login — the SAME flow re-authenticates an existing account (matched
1734
- // by accountUuid) or adds a new one. When the login is for an account already added,
1787
+ // by user + organization) or adds a new one. When the login is for an account already added,
1735
1788
  // we say so, keep its name, and skip the "name this account" prompt — so it's clear
1736
1789
  // it's a RE-AUTH in place (revives a dead-refresh/reauth account), not a duplicate.
1737
1790
  async _doLogin() {
@@ -1771,12 +1824,9 @@ export class TUI {
1771
1824
  // a mirror match → that team pool; a brand-new account with a linked team pool →
1772
1825
  // ask once (default team pool); otherwise the local save path.
1773
1826
  async _routeLogin(creds, profile) {
1774
- const decision = decideLoginTarget({
1775
- mirror: this._findRemoteMirrorFor(profile),
1776
- links: this.am.poolLinks,
1777
- existing: this._findExistingOAuthAccount(profile),
1778
- accountUuid: profile?.accountUuid,
1779
- });
1827
+ const mirror = this._findRemoteMirrorFor(profile);
1828
+ const existing = mirror ? null : await this._matchLogin(profile);
1829
+ const decision = decideLoginTarget({ mirror, links: this.am.poolLinks, existing, accountUuid: profile?.accountUuid });
1780
1830
  if (decision.kind === 'no-uuid') {
1781
1831
  setConsoleStdoutSuppressed(false);
1782
1832
  process.stdout.write("\nCould not read this account's id — the team pool needs it. Nothing was saved; try again.\n");
@@ -1787,14 +1837,14 @@ export class TUI {
1787
1837
  await this._sendLoginToRemote(decision.mirror, creds, profile);
1788
1838
  return;
1789
1839
  }
1790
- const existing = this._findExistingOAuthAccount(profile);
1791
1840
  let name;
1792
1841
  if (existing) {
1793
1842
  process.stdout.write(`\nThis Claude account is already added as "${existing.name}" — re-authenticating it in place (no duplicate).\n`);
1794
1843
  name = existing.name;
1795
1844
  } else {
1796
- const suggested = profile?.email
1797
- || `account-${this.config.accounts.filter(a => a.name.startsWith('account-')).length + 1}`;
1845
+ const sibling = this._oauthAccounts().find(a => sameUser(a, profile));
1846
+ if (sibling) process.stdout.write(`\nSame Claude user as "${sibling.name}": adding a second account.\n`);
1847
+ const suggested = suggestAccountName(this.config.accounts, profile);
1798
1848
  let toTeam = false;
1799
1849
  if (decision.kind === 'ask-team') {
1800
1850
  const where = String(await this._ask(`\nThis is a new account. Add it to the team pool "${decision.link.name}" (recommended) or this laptop only? [T/l]: `) || '').trim().toLowerCase();
@@ -1835,7 +1885,14 @@ export class TUI {
1835
1885
  // uuid-first matcher cannot alias onto a local account).
1836
1886
  _findRemoteMirrorFor(profile) {
1837
1887
  if (!profile?.accountUuid) return null;
1838
- return this.am.accounts.find(a => a.remote && a.remoteUuid === profile.accountUuid) || null;
1888
+ // Exact match first (user + org). A mirror whose org is unknown (the cloud
1889
+ // pool saved the account before organizations were recorded) still owns the
1890
+ // login when it is the only same-user mirror: re-authenticate it rather than
1891
+ // add a second row. Two known orgs never alias.
1892
+ const mirrors = this.am.accounts.filter(a => a.remote && a.enabled !== false && sameUser({ accountUuid: a.remoteUuid }, profile));
1893
+ return mirrors.find(a => sameAccountIdentity({ accountUuid: a.remoteUuid, organizationUuid: a.remoteOrganizationUuid }, profile))
1894
+ || (profile.organizationUuid && mirrors.filter(a => !a.remoteOrganizationUuid).length === 1
1895
+ ? mirrors.find(a => !a.remoteOrganizationUuid) : null);
1839
1896
  }
1840
1897
 
1841
1898
  // Send a fresh browser login to the linked team pool that OWNS this account
@@ -1955,24 +2012,23 @@ export class TUI {
1955
2012
  }
1956
2013
 
1957
2014
  // Upsert an OAuth account into config + the running manager. Dedupes by
1958
- // accountUuid, then name. Shared by import and browser login.
2015
+ // user + organization, then name. Shared by import and browser login.
1959
2016
  async _upsertOAuthAccount({ creds, profile, name, source, verb = 'Added' }) {
1960
- if (!name) {
1961
- name = profile?.email
1962
- || `account-${this.config.accounts.filter(a => a.name.startsWith('account-')).length + 1}`;
1963
- }
2017
+ if (!name) name = suggestAccountName(this.config.accounts, profile);
1964
2018
  const entry = {
1965
2019
  name, type: 'oauth', source,
1966
2020
  accountUuid: profile?.accountUuid || null,
2021
+ organizationUuid: profile?.organizationUuid || null,
1967
2022
  accessToken: creds.accessToken,
1968
2023
  refreshToken: creds.refreshToken,
1969
2024
  expiresAt: creds.expiresAt,
1970
2025
  };
1971
2026
 
1972
- let idx = entry.accountUuid
1973
- ? this.config.accounts.findIndex(a => a.accountUuid === entry.accountUuid)
1974
- : -1;
1975
- if (idx < 0) idx = this.config.accounts.findIndex(a => a.name === name);
2027
+ // Identity first; the name only picks up rows that cannot carry an identity
2028
+ // (saved before uuids were stored). A row of the SAME USER with a KNOWN,
2029
+ // DIFFERENT organization never matches by name: its tokens are its own.
2030
+ let idx = this.config.accounts.findIndex(a => sameAccountIdentity(a, entry));
2031
+ if (idx < 0) idx = this.config.accounts.findIndex(a => a.name === name && !knownDifferentOrg(a, entry));
1976
2032
 
1977
2033
  if (idx >= 0) {
1978
2034
  const previous = this.config.accounts[idx];
@@ -1987,13 +2043,14 @@ export class TUI {
1987
2043
  // heal disk (persistTokenRefresh's generation guard skips a disk token that
1988
2044
  // != _refreshedFrom), so disk must be made correct right here.
1989
2045
  const amAcct = this.am.accounts.find(account =>
1990
- (entry.accountUuid && account.accountUuid === entry.accountUuid) || account.name === name
2046
+ sameAccountIdentity(account, entry) || (account.name === name && !knownDifferentOrg(account, entry))
1991
2047
  );
1992
2048
  if (amAcct) {
1993
2049
  amAcct.credential = creds.accessToken;
1994
2050
  amAcct.refreshToken = creds.refreshToken;
1995
2051
  amAcct.expiresAt = creds.expiresAt;
1996
2052
  amAcct.accountUuid = entry.accountUuid;
2053
+ amAcct.organizationUuid = entry.organizationUuid;
1997
2054
  amAcct.name = name;
1998
2055
  // Fresh tokens from re-auth revive a dead-refresh account. This in-place
1999
2056
  // update is the actual re-login path (the index.js reconcile sees no change
@@ -2035,15 +2092,84 @@ export class TUI {
2035
2092
  }
2036
2093
  }
2037
2094
 
2095
+ // Decide what a fresh browser-login profile is: an account already in the pool
2096
+ // (re-authenticate in place) or a new one. Same-user entries that do not know
2097
+ // their organization are read first; when one still cannot be read, the user decides.
2098
+ async _matchLogin(profile) {
2099
+ await this._resolveOrganizations(profile);
2100
+ const existing = this._findExistingOAuthAccount(profile);
2101
+ if (this._organizationUnknown(existing, profile)) return this._confirmReauth(existing);
2102
+ return existing;
2103
+ }
2104
+
2105
+ // Fill in the organization of same-user entries that lack one, reading each with
2106
+ // the running account's live token (read only, never refreshed), and mirror the
2107
+ // result to the manager. The upsert that follows persists it.
2108
+ async _resolveOrganizations(profile) {
2109
+ if (!profile?.accountUuid) return;
2110
+ await resolveOrganizations(this._oauthAccounts(), profile.accountUuid, entry => this._liveCredentials(entry));
2111
+ this._mirrorOrganizations(profile);
2112
+ }
2113
+
2114
+ _liveCredentials(entry) {
2115
+ const live = this._runningAccount(entry);
2116
+ return live ? { accessToken: live.credential, expiresAt: live.expiresAt } : entry;
2117
+ }
2118
+
2119
+ _mirrorOrganizations(profile) {
2120
+ const known = this._oauthAccounts().filter(a => sameUser(a, profile) && a.organizationUuid);
2121
+ for (const entry of known) this._mirrorOrganization(entry);
2122
+ }
2123
+
2124
+ _mirrorOrganization(entry) {
2125
+ const live = this._runningAccount(entry);
2126
+ if (live) live.organizationUuid = entry.organizationUuid;
2127
+ }
2128
+
2129
+ _runningAccount(entry) {
2130
+ return this.am.accounts.find(a => a.name === entry.name);
2131
+ }
2132
+
2133
+ _oauthAccounts() {
2134
+ return this.config.accounts.filter(a => a.type === 'oauth');
2135
+ }
2136
+
2038
2137
  // Find an already-configured OAuth account matching a fresh browser-login profile —
2039
- // by accountUuid (primary), then name===email — the SAME precedence _upsertOAuthAccount
2040
- // dedupes on, so the login flow can honestly say "re-authenticating" vs "adding new".
2138
+ // the same user in the same organization; else a same-user entry that does not know
2139
+ // its organization (the login then asks); else, for a profile without a uuid,
2140
+ // name===email; else an entry saved before uuids were stored. The SAME precedence
2141
+ // _upsertOAuthAccount dedupes on, so the login flow can honestly say
2142
+ // "re-authenticating" vs "adding new".
2041
2143
  _findExistingOAuthAccount(profile) {
2042
- const uuid = profile?.accountUuid || null;
2144
+ const accounts = this._oauthAccounts();
2043
2145
  const email = profile?.email || null;
2044
- let acct = uuid ? this.config.accounts.find(a => a.type === 'oauth' && a.accountUuid === uuid) : null;
2045
- if (!acct && email) acct = this.config.accounts.find(a => a.type === 'oauth' && a.name === email);
2046
- return acct || null;
2146
+ if (!profile?.accountUuid) return (email && accounts.find(a => a.name === email)) || null;
2147
+ return accounts.find(a => sameAccountIdentity(a, profile))
2148
+ || organizationUnknownMatch(accounts, profile)
2149
+ || accounts.find(a => !a.accountUuid && a.name === email)
2150
+ || null;
2151
+ }
2152
+
2153
+ // True when the match rests on the user alone: the entry's organization is unknown
2154
+ // while the login names one.
2155
+ _organizationUnknown(existing, profile) {
2156
+ return Boolean(existing?.accountUuid && profile?.organizationUuid && !existing.organizationUuid);
2157
+ }
2158
+
2159
+ // The user decides a same-user login whose organization could not be read: Enter
2160
+ // or r re-authenticates the entry, a adds a second account; anything else asks again.
2161
+ async _confirmReauth(existing) {
2162
+ const choice = await this._askReauthOrAdd(existing.name);
2163
+ if (choice === 'add') return null;
2164
+ if (choice === 'reauth') return existing;
2165
+ return this._confirmReauth(existing);
2166
+ }
2167
+
2168
+ async _askReauthOrAdd(name) {
2169
+ const raw = await this._ask(`Same Claude user as "${name}", organization unknown. Re-authenticate it (r) or add a second account (a)? [r] `);
2170
+ const answer = String(raw || '').trim().toLowerCase();
2171
+ if (['', 'r', 're-authenticate'].includes(answer)) return 'reauth';
2172
+ return ['a', 'add'].includes(answer) ? 'add' : null;
2047
2173
  }
2048
2174
 
2049
2175
  async _doAddKey(apiKey) {
@@ -2096,7 +2222,7 @@ export class TUI {
2096
2222
  _configAccountIndex(account) {
2097
2223
  if (!account) return -1;
2098
2224
  if (account.accountUuid) {
2099
- const byUuid = this.config.accounts.findIndex(candidate => candidate.accountUuid === account.accountUuid);
2225
+ const byUuid = this.config.accounts.findIndex(candidate => sameAccountIdentity(candidate, account));
2100
2226
  if (byUuid >= 0) return byUuid;
2101
2227
  }
2102
2228
  return this.config.accounts.findIndex(candidate => candidate.name === account.name);
@@ -2433,18 +2559,21 @@ export class TUI {
2433
2559
  } else {
2434
2560
  lines.push('');
2435
2561
  // Aligned column header (dim + underline so it reads as chrome, not data). It
2436
- // labels the fixed columns that have no inline label; the Ses/Wk/Tok/Req and
2562
+ // labels the fixed columns that have no inline label; the Ses/Fbl/Wk/Tok/Req and
2437
2563
  // Now/15m/1h labels stay inline per row. It sits DIRECTLY above the rows — the
2438
2564
  // abbreviation glossary is a FOOTER below the rows (a caption), never between
2439
2565
  // the header and the data (a left-aligned sentence there reads as a broken,
2440
2566
  // misaligned second header).
2441
2567
  lines.push(dimUnderline(acctHeader(W)));
2442
- const showBoth = W >= 70;
2443
- // 65/54 = the fixed pre-bar column span (prefix + Account + Provider + Status +
2444
- // gaps); grew by +4 with the wider 20-col Account column (was 61/50 at NAME_W 16).
2445
- const bw = showBoth
2446
- ? Math.max(5, Math.min(20, Math.floor((W - 65) / 2)))
2447
- : Math.max(5, Math.min(20, W - 54));
2568
+ // Sticky: once any account has reported a session window in this run, keep the
2569
+ // Ses column. A window that simply expires on an idle pool nulls its reading
2570
+ // until the next request or probe; dropping and re-adding the column then
2571
+ // would make every bar jump width. Pools that never report one keep it hidden.
2572
+ this._sessionColumnSeen = this._sessionColumnSeen || this.am.accounts.some(hasSessionReading);
2573
+ // Below 70 columns only ONE bar fits: Wk (real data) wins over a latched-but-
2574
+ // expired Ses, so the collapse logic still applies at narrow widths.
2575
+ const latch = W >= 70 ? this._sessionColumnSeen : this.am.accounts.some(hasSessionReading);
2576
+ const { showSession, showBoth, showFable, bw } = barLayout(W, latch);
2448
2577
 
2449
2578
  // Claude/OAuth accounts first, providers (GLM/Kimi fallback) last — a stable
2450
2579
  // display order over the canonical am.accounts array (which stays untouched so
@@ -2457,7 +2586,7 @@ export class TUI {
2457
2586
  // effectively off (owner 2026-10-29: "should it hide the local ones that are
2458
2587
  // in the cloud... they're effectively disabled as well"). No separate key.
2459
2588
  if (this.hideDisabled && this.am.accounts[i]?.poolBenchedBy) { hidden++; continue; }
2460
- lines.push(this._renderAcct(i, bw, showBoth));
2589
+ lines.push(this._renderAcct(i, bw, showBoth, showFable, showSession));
2461
2590
  }
2462
2591
  if (hidden > 0) {
2463
2592
  lines.push(` ${dim(`… ${hidden} disabled account${hidden === 1 ? '' : 's'} hidden — press h to show`)}`);
@@ -2573,7 +2702,7 @@ export class TUI {
2573
2702
  process.stdout.write(buf);
2574
2703
  }
2575
2704
 
2576
- _renderAcct(idx, bw, showBoth) {
2705
+ _renderAcct(idx, bw, showBoth, showFable = showBoth, showSession = true) {
2577
2706
  let a = this.am.accounts[idx];
2578
2707
  // A row benched by the duplicate guard renders the CLOUD's live copy (status,
2579
2708
  // bars, in-flight, request counts) — never the stale local snapshot. Identity
@@ -2842,7 +2971,7 @@ export class TUI {
2842
2971
  }
2843
2972
 
2844
2973
  if (a.type === 'provider') {
2845
- return this._renderProviderAcct(sel, cur, name, type, status + ' ' + resetsCell, a, bw, showBoth);
2974
+ return this._renderProviderAcct(sel, cur, name, type, status + ' ' + resetsCell, a, bw, showBoth, showFable, showSession);
2846
2975
  }
2847
2976
 
2848
2977
  // Quota ratios — prefer unified (Claude Max), fall back to standard (API key)
@@ -2865,15 +2994,20 @@ export class TUI {
2865
2994
  t2 = t1;
2866
2995
  }
2867
2996
 
2868
- let line = ` ${sel}${cur} ${name} ${whereCell(a)} ${type} ${status} ${resetsCell} ${l1} ${bar(r1, bw, t1)}`;
2997
+ const bars = [];
2998
+ // The Fable bar comes first, before the session and weekly bars, on every row
2999
+ // type, so each bar starts at the same offset on OAuth, API-key and provider rows.
3000
+ if (showFable) bars.push(`Fbl ${scopedWeeklyBar(q, 'fable', bw)}`);
3001
+ if (showSession) bars.push(`${l1} ${bar(r1, bw, t1)}`);
2869
3002
  if (showBoth) {
2870
3003
  // "no weekly cap on this plan" is a DIFFERENT state from "not read yet", and
2871
3004
  // both render as an empty bar. Say which, so a healthy uncapped account
2872
3005
  // (privacy@gomokka.com, measured 2026-08-06) doesn't read as broken.
2873
- line += (r2 == null && q.weeklyAbsent)
2874
- ? ` ${l2} ${emptyBar('none', bw)}`
2875
- : ` ${l2} ${bar(r2, bw, t2)}`;
3006
+ bars.push((r2 == null && q.weeklyAbsent)
3007
+ ? `${l2} ${emptyBar('none', bw)}`
3008
+ : `${l2} ${bar(r2, bw, t2)}`);
2876
3009
  }
3010
+ let line = ` ${sel}${cur} ${name} ${whereCell(a)} ${type} ${status} ${resetsCell} ${bars.join(' ')}`;
2877
3011
  const weekly = weeklyPolicyText(this.am, a);
2878
3012
  if (weekly) line += ` ${weekly}`;
2879
3013
  // Per-account SETTINGS (preferred pin, usage cap), whatever the account is
@@ -2906,7 +3040,7 @@ export class TUI {
2906
3040
  // headers don't carry them). If the probe has gone stale, say so — and name the
2907
3041
  // cause (e.g. rate-limited) when a probe failure is on record — rather than imply
2908
3042
  // the last-known value is current.
2909
- line += this._probeHealthNote(a);
3043
+ line += this._probeHealthNote(a, showFable);
2910
3044
  const act = loadText(this._accountLoad(a));
2911
3045
  if (act) line += ` ${dim(act)}`;
2912
3046
  return line;
@@ -2916,7 +3050,7 @@ export class TUI {
2916
3050
  * stale, names the cause from the last recorded probe failure (e.g. a 429 from
2917
3051
  * the usage endpoint) so a self-throttling probe reads as "rate-limited" rather
2918
3052
  * than an unexplained "stale". Leading spaces included so callers append raw. */
2919
- _probeHealthNote(a) {
3053
+ _probeHealthNote(a, showFable = false) {
2920
3054
  // A dead account (reauth / disabled) already surfaces its state in the status
2921
3055
  // column, and its quota reading is frozen and moot — the prober skips it, so a
2922
3056
  // "stale·probe 401" here is just the perpetual echo of the 401 that killed it.
@@ -2930,11 +3064,15 @@ export class TUI {
2930
3064
  // so a BUSY oauth account with a header-fresh reading and no probe-only scoped
2931
3065
  // cap is NOT stale, even if its background probe is 429-throttled. Provider bars
2932
3066
  // and per-model scoped caps ARE probe-only, so for those a stale probe genuinely
2933
- // means stale data → keep flagging.
3067
+ // means stale data → keep flagging. A scoped reading is DISPLAYED when its tag
3068
+ // shows (at or above the reserve floor) or, for Fable, whenever the Fbl bar is on
3069
+ // screen: the bar draws the reading at any level, so a stale low Fbl value must
3070
+ // carry the age marker too.
2934
3071
  const q = a.quota || {};
2935
3072
  const reserveFloor = this.am.scheduler?.weeklyReserveThreshold ?? 0.85; // mirrors _renderAcct's scoped-tag gate
2936
- const hasDisplayedScopedCap = Object.values(q.scopedWeekly || {}).some(
2937
- e => e && e.isActive !== false && e.utilization != null && e.utilization >= reserveFloor);
3073
+ const hasDisplayedScopedCap = Object.entries(q.scopedWeekly || {}).some(([family, e]) =>
3074
+ e && e.isActive !== false && e.utilization != null
3075
+ && (e.utilization >= reserveFloor || (showFable && family === 'fable')));
2938
3076
  if (a.type !== 'provider' && !hasDisplayedScopedCap) {
2939
3077
  const interval = this.am.quotaProbeIntervalMs; // > 0 here (else _quotaProbeStale returned false)
2940
3078
  const headerFresh = q.lastHeaderQuotaAt && (Date.now() - q.lastHeaderQuotaAt) <= Math.max(3 * interval, 180_000);
@@ -2971,7 +3109,7 @@ export class TUI {
2971
3109
  return interval > 0 ? `every ${formatAge(interval)}` : 'shortly';
2972
3110
  }
2973
3111
 
2974
- _renderProviderAcct(sel, cur, name, type, status, a, bw = 11, showBoth = true) {
3112
+ _renderProviderAcct(sel, cur, name, type, status, a, bw = 11, showBoth = true, showFable = showBoth, showSession = true) {
2975
3113
  const q = a.quota || {};
2976
3114
 
2977
3115
  // Ses/Wk bars in the SAME columns as OAuth rows (right after status) so the
@@ -3029,8 +3167,11 @@ export class TUI {
3029
3167
  // setting whenever the probe is quiet is how a shipped feature reads as absent.
3030
3168
  for (const tag of settingsTags(this.am, a)) note += ` ${tag}`;
3031
3169
 
3032
- let line = ` ${sel}${cur} ${name} ${whereCell(a)} ${type} ${status} Ses ${sesCell}`;
3033
- if (showBoth) line += ` Wk ${wkCell}`;
3170
+ const bars = [];
3171
+ if (showFable) bars.push(`Fbl ${scopedWeeklyBar(q, 'fable', bw)}`);
3172
+ if (showSession) bars.push(`Ses ${sesCell}`);
3173
+ if (showBoth) bars.push(`Wk ${wkCell}`);
3174
+ let line = ` ${sel}${cur} ${name} ${whereCell(a)} ${type} ${status} ${bars.join(' ')}`;
3034
3175
  line += note;
3035
3176
  // Same recent-load columns as OAuth (providers track inFlight + load events),
3036
3177
  // plus a compact Last <status> <ms> — the one signal that matters for a