Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: keep the 60-char cap on scraped plan names when allowing interior spaces

[._.]/ Adam Eivy9966ff3d3430
diff --git a/server/services/providerUsage.js b/server/services/providerUsage.js
index 8d9503fd4b..fcf0585182 100644
--- a/server/services/providerUsage.js
+++ b/server/services/providerUsage.js
@@ -588,9 +588,12 @@ export function parseGrokUsage(text, { now = Date.now(), timezone } = {}) {
// alphanumeric start, then alphanumeric plus separators (dots, commas, underscores,
// plus, hyphen), with interior spaces allowed only before uppercase letters/digits
// (vendor names like "Claude Max 20x"). This rejects arbitrary English prose like
- // "as of Tuesday" while keeping recognized tiers on the Usage card. A missing plan
- // reads as unknown; a wrong one reads as fact.
- const PLAN_NAME = /^(?=.*[A-Za-z])[A-Za-z0-9](?:[A-Za-z0-9.,_+-]*(?:[ ][A-Z0-9][A-Za-z0-9.,_+-]*)*)?$/;
+ // "as of Tuesday" while keeping recognized tiers on the Usage card. The 60-char
+ // cap is unchanged from the single-token form: a scraped fragment that happens to
+ // be shaped like a tier is still not one. A missing plan reads as unknown; a wrong
+ // one reads as fact.
+ const PLAN_NAME =
+ /^(?=.*[A-Za-z])(?=.{1,60}$)[A-Za-z0-9](?:[A-Za-z0-9.,_+-]*(?:[ ][A-Z0-9][A-Za-z0-9.,_+-]*)*)?$/;
let plan = null;
const matches = [...str.matchAll(/(weekly|monthly)\s+limit(?:\s*\(([^)]+)\))?:?/gi)];
diff --git a/server/services/providerUsage.test.js b/server/services/providerUsage.test.js
index eb68f5d151..89a29349f8 100644
--- a/server/services/providerUsage.test.js
+++ b/server/services/providerUsage.test.js
@@ -593,6 +593,16 @@ describe('parseGrokUsage', () => {
expect(parseGrokUsage('Weekly limit (Claude Max 20x ): 42%', opts).plan).toBe('Claude Max 20x');
expect(parseGrokUsage('Weekly limit ( Claude Max 20x): 42%', opts).plan).toBe('Claude Max 20x');
});
+
+ it('still caps a tier-shaped name at 60 characters', () => {
+ // Allowing interior spaces must not drop the length cap the single-token
+ // form carried: a long scraped fragment shaped like a tier is still panel
+ // text, not a plan, and a wrong plan reads as fact.
+ const sixty = `Max ${'A'.repeat(56)}`;
+ expect(sixty).toHaveLength(60);
+ expect(parseGrokUsage(`Weekly limit (${sixty}): 42%`, opts).plan).toBe(sixty);
+ expect(parseGrokUsage(`Weekly limit (Max ${'A'.repeat(57)}): 42%`, opts).plan).toBeNull();
+ });
});
describe('TUI usage fetchers (via getProviderQuotas)', () => {