From a9522f98ccf2d06863dd26f4cf67e2b8f2f8f38f Mon Sep 17 00:00:00 2001 From: repo-worker-code Date: Sun, 1 Nov 2026 02:04:49 -0600 Subject: [PATCH 1/2] fix(aggregator): Command Code quota reads use the latest dated plan read (#3410) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit extractCommandCode selected the first $X-of-$Y match in the section, so /api/quota.json rendered the stale 2026-10-25 dollar read as current: the freshest read (2026-10-27 console) is percentage-only and never matched. Per Drew's 2026-11-01 ruling, Command Code quota is the plan windows only (monthly limit, weekly, 5-hour) — never the top-up credit balance. - Segment the section at ISO date stamps and take the latest dated read, in the dollar format, the percentage-only console format, or its compact restatement. - A newer dated segment carrying a monthly figure no format can parse renders no windows instead of a stale read. - Regression tests pin latest-dated-read selection, the unparseable-freshest case, and balance-never-quota. - Verified against the live quota view: monthly 69%, weekly 14%, 5-hour 0% (the 2026-10-27 console read). Full aggregator suite 795 pass / 0 fail. --- pm-stack/aggregator/src/quota-extract.ts | 102 +++++++++++++++++++---- pm-stack/aggregator/test/quota.test.ts | 33 ++++++++ 2 files changed, 118 insertions(+), 17 deletions(-) diff --git a/pm-stack/aggregator/src/quota-extract.ts b/pm-stack/aggregator/src/quota-extract.ts index 775ce665a..98c967409 100644 --- a/pm-stack/aggregator/src/quota-extract.ts +++ b/pm-stack/aggregator/src/quota-extract.ts @@ -199,25 +199,93 @@ const extractClinePass: Extractor = (s) => { }; const extractCommandCode: Extractor = (s, now) => { - const bal = first(s, /\$(\d+(?:\.\d+)?) of \$(\d+(?:\.\d+)?) used/i); - if (!bal) return null; - const end = first(s, /period ends (\w{3}) (\d{1,2}), (\d{2}:\d{2}) UTC/i); - const windows: QuotaWindow[] = [ - usdWindow( - "monthly credits", - Number(bal[1]), - Number(bal[2]), - end ? monthDayTime(end[1], end[2], end[3], now) : null, - ), - ]; - const short = first(s, /5h (\d+(?:\.\d+)?)%, weekly (\d+(?:\.\d+)?)%/i); - if (short) { - windows.push(pctWindow("5-hour", Number(short[1]), null)); - windows.push(pctWindow("weekly", Number(short[2]), null)); + // Drew's ruling (2026-11-01, #3410): Command Code quota reads report + // the PLAN windows only (monthly limit, weekly, 5-hour) — never the + // extra/top-up credit balance. The section preserves several dated + // reads by design, so select the LATEST dated read instead of the + // first pattern that matches anywhere: the old first-match on + // "$X of $Y used" rendered the 2026-10-25 read as current because + // the freshest (2026-10-27) console read is percentage-only. + // + // Split the section into segments at each ISO date stamp (the text + // before the first stamp is one undated segment). A segment is a + // parseable read when one of the recorded formats matches: + // - percentage-only console format: "monthly limit N% used", + // "weekly limit N%", "5-hour limit N%" + // - its compact restatement: "monthly N%, weekly N%, 5h N%" + // - the dollar format: "$X of $Y used" (the $ used of the $10 + // included credits is a monthly-limit figure per the ruling) + // plus the "5h A%, weekly B%" short windows. + const stamps = [...s.matchAll(/\d{4}-\d{2}-\d{2}/g)]; + const segments: { date: string; index: number; text: string }[] = []; + if (stamps.length === 0) { + segments.push({ date: "", index: 0, text: s }); + } else { + if (stamps[0].index > 0) segments.push({ date: "", index: 0, text: s.slice(0, stamps[0].index) }); + for (let i = 0; i < stamps.length; i++) { + const start = stamps[i].index; + const end = i + 1 < stamps.length ? stamps[i + 1].index : s.length; + segments.push({ date: stamps[i][0], index: start, text: s.slice(start, end) }); + } } + const parseRead = (text: string): QuotaWindow[] | null => { + const monthly = first(text, /monthly limit (\d+(?:\.\d+)?)% used/i); + if (monthly) { + const windows = [pctWindow("monthly", Number(monthly[1]), null)]; + const weekly = first(text, /weekly limit (\d+(?:\.\d+)?)%/i); + if (weekly) windows.push(pctWindow("weekly", Number(weekly[1]), null)); + const fiveHour = first(text, /5-hour limit (\d+(?:\.\d+)?)%/i); + if (fiveHour) windows.push(pctWindow("5-hour", Number(fiveHour[1]), null)); + return windows; + } + const compact = first(text, /monthly (\d+(?:\.\d+)?)%, weekly (\d+(?:\.\d+)?)%, 5h (\d+(?:\.\d+)?)%/i); + if (compact) { + return [ + pctWindow("monthly", Number(compact[1]), null), + pctWindow("weekly", Number(compact[2]), null), + pctWindow("5-hour", Number(compact[3]), null), + ]; + } + const bal = first(text, /\$(\d+(?:\.\d+)?) of \$(\d+(?:\.\d+)?) used/i); + if (bal) { + const end = first(text, /period ends (\w{3}) (\d{1,2}), (\d{2}:\d{2}) UTC/i); + const windows: QuotaWindow[] = [ + usdWindow( + "monthly credits", + Number(bal[1]), + Number(bal[2]), + end ? monthDayTime(end[1], end[2], end[3], now) : null, + ), + ]; + const short = first(text, /5h (\d+(?:\.\d+)?)%, weekly (\d+(?:\.\d+)?)%/i); + if (short) { + windows.push(pctWindow("5-hour", Number(short[1]), null)); + windows.push(pctWindow("weekly", Number(short[2]), null)); + } + return windows; + } + return null; + }; + const parsed = segments + .map((seg) => ({ ...seg, windows: parseRead(seg.text) })) + .filter((seg) => seg.windows !== null); + if (parsed.length === 0) return null; + parsed.sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : a.index - b.index)); + const latest = parsed[parsed.length - 1]; + // A newer dated segment that carries a monthly figure none of the + // formats could parse is a fresher read we cannot read: render no + // windows rather than presenting the older read as current (#3410). + const stale = segments.some( + (seg) => + seg.date > latest.date && + parseRead(seg.text) === null && + /monthly/i.test(seg.text) && + /\d+(?:\.\d+)?\s*(%|percent)/i.test(seg.text), + ); + if (stale) return null; return { - windows, - note: "Registry: the Go plan does not include API access — wiring activates if the plan tier is upgraded.", + windows: latest.windows!, + note: "Plan windows only (Drew's 2026-11-01 ruling, #3410): freshest dated read in the quota view; the top-up credit balance is never reported as quota. Registry: the Go plan does not include API access — wiring activates if the plan tier is upgraded.", }; }; diff --git a/pm-stack/aggregator/test/quota.test.ts b/pm-stack/aggregator/test/quota.test.ts index 723f3893a..730ef7fe2 100644 --- a/pm-stack/aggregator/test/quota.test.ts +++ b/pm-stack/aggregator/test/quota.test.ts @@ -133,6 +133,39 @@ describe("quota extractors", () => { expect(p.windows[2].percent).toBe(8.8); }); + test("command code takes the latest dated read, percentage-only format (#3410)", () => { + const multi = ` +### Command Code +- **Usage / dates:** **Newer dated read (model-efficiency plan, freshest reads 2026-10-25 morning): $6.57 of $10 used ($3.43 left); 5h 1.2%, weekly 8.8%; period ends Nov 2, 23:04 UTC.** **Freshest dated read (console, 2026-10-27 10:05 CDT, commandcode.ai Settings): monthly limit 69% used, resets Nov 2; weekly limit 14% (resets in 4d); 5-hour limit 0% ("No usage in this window yet"); extra/top-up credits $0.00 balance.** +`; + const p = extractQuotaPools(multi, NOW).find((x) => x.id === "commandcode:go")!; + expect(p.windows.map((w) => [w.name, w.percent])).toEqual([ + ["monthly", 69], + ["weekly", 14], + ["5-hour", 0], + ]); + // No window is a dollar/balance figure: the top-up balance is not quota. + expect(p.windows.some((w) => w.unit === "usd")).toBe(false); + }); + + test("command code renders no windows when the freshest dated read is unparseable (#3410)", () => { + const stale = ` +### Command Code +- **Usage / dates:** **Dated read (2026-10-25): $6.57 of $10 used; 5h 1.2%, weekly 8.8%; period ends Nov 2, 23:04 UTC.** **Freshest dated read (2026-10-30): monthly limit 55 percent used (the console printed the figure in words this cycle).** +`; + const p = extractQuotaPools(stale, NOW).find((x) => x.id === "commandcode:go")!; + expect(p.windows).toEqual([]); + }); + + test("command code never emits the top-up balance as quota (#3410)", () => { + const balanceOnly = ` +### Command Code +- **Usage / dates:** **Dated read (2026-10-30): extra/top-up credits $0.10 balance; hub credits 0.1 flat.** +`; + const p = extractQuotaPools(balanceOnly, NOW).find((x) => x.id === "commandcode:go")!; + expect(p.windows).toEqual([]); + }); + test("antigravity pools are independent, remaining -> used", () => { expect(byId.get("antigravity:gemini")!.windows[0].percent).toBeCloseTo(0.9); expect(byId.get("antigravity:claude-gpt")!.windows[0].percent).toBe(0); From 08e64389cb7a90ff84d0cf0377e2ee3972506e86 Mon Sep 17 00:00:00 2001 From: repo-worker-code Date: Sun, 1 Nov 2026 02:08:52 -0600 Subject: [PATCH 2/2] fix(aggregator): same-day ordering for the Command Code stale-read guard (#3410) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex P2 on #3413: the unparseable-fresher-read guard compared dates only, so a later same-day unparseable monthly read did not invalidate an earlier parseable one. Compare (date, segment index) — the same ordering used to pick the latest read — and pin it with a test. --- pm-stack/aggregator/src/quota-extract.ts | 2 +- pm-stack/aggregator/test/quota.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pm-stack/aggregator/src/quota-extract.ts b/pm-stack/aggregator/src/quota-extract.ts index 98c967409..2caea61f6 100644 --- a/pm-stack/aggregator/src/quota-extract.ts +++ b/pm-stack/aggregator/src/quota-extract.ts @@ -277,7 +277,7 @@ const extractCommandCode: Extractor = (s, now) => { // windows rather than presenting the older read as current (#3410). const stale = segments.some( (seg) => - seg.date > latest.date && + (seg.date > latest.date || (seg.date === latest.date && seg.index > latest.index)) && parseRead(seg.text) === null && /monthly/i.test(seg.text) && /\d+(?:\.\d+)?\s*(%|percent)/i.test(seg.text), diff --git a/pm-stack/aggregator/test/quota.test.ts b/pm-stack/aggregator/test/quota.test.ts index 730ef7fe2..65ac523dc 100644 --- a/pm-stack/aggregator/test/quota.test.ts +++ b/pm-stack/aggregator/test/quota.test.ts @@ -157,6 +157,15 @@ describe("quota extractors", () => { expect(p.windows).toEqual([]); }); + test("command code: a later same-day unparseable read also invalidates the earlier one (#3410)", () => { + const sameDay = ` +### Command Code +- **Usage / dates:** **Dated read (2026-10-30 09:00 CDT): monthly limit 55% used; weekly limit 20%; 5-hour limit 3%.** **Dated update (2026-10-30 12:00 CDT): monthly limit 100 percent used (the console printed the figure in words).** +`; + const p = extractQuotaPools(sameDay, NOW).find((x) => x.id === "commandcode:go")!; + expect(p.windows).toEqual([]); + }); + test("command code never emits the top-up balance as quota (#3410)", () => { const balanceOnly = ` ### Command Code