Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pm-stack/aggregator/src/quota-extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ const extractCodex: Extractor = (s, now) => {
};

const extractMeta: Extractor = (s, now) => {
// A dated billing-blocked read (402 billing_not_configured — the
// billing-verification wall) outranks every window/reset read: the
// pool is blocked at the account level, whatever the windows say.
// The 100% weekly window is the fleet's blocked-status mapping (it
// drives poolState → walled), NOT a measured consumption percentage;
// the note says so, and no reset is invented for when it lifts.
const blocked =
/(\d{4}-\d{2}-\d{2})[^\n]{0,200}?billing_not_configured/i.exec(s) ??
/billing_not_configured[^\n]{0,200}?(\d{4}-\d{2}-\d{2})/i.exec(s);
if (blocked) {
return {
windows: [pctWindow("weekly", 100, null)],
note: `BLOCKED ${blocked[1]} — API returns 402 billing_not_configured (billing-verification wall); laptop meta-provider probes all walled, stewardship measurement gate closed. The 100% weekly window is a blocked-status mapping, not measured consumption.`,
};
}
const reset = first(s, /[Ww]eekly reset (?:today )?(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}) CDT/);
const resetIso = reset ? dateTimeCDT(reset[1], reset[2]) : null;
const burned = /burned to empty/i.test(s);
Expand Down
33 changes: 33 additions & 0 deletions pm-stack/aggregator/src/saas-extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,39 @@ export function extractCharges(doc: string, registryText = ""): ChargeRow[] {
},
);
}
// Single dated Meta charge incidents recorded after the 2026-10-25
// pair: the registry's billing-incident bullets ("[observed — Gmail
// card alert, <date> …] Meta PAYG (METAPAY) — **$X charged …**
// (<Card> card ending NNNN …)") and the quota view's Meta section
// ("Newer dated charge (<date>): $X charged … on <Card> card ending
// NNNN"). The same charge is written in both records, so rows are
// deduped on date+amount+card — each incident appears exactly once,
// with its own date, amount, and payment method.
const seenIncidents = new Set(rows.map((r) => `${r.at}|${r.amountUsd}|${r.method}`));
const pushIncident = (at: string, amount: string, cardName: string, last4: string) => {
const row: ChargeRow = {
at,
label: "Meta PAYG spill",
amountUsd: Number(amount),
method: `${cardName.trim()} •${last4}`,
source: "Gmail card alert (registry billing incidents)",
};
const key = `${row.at}|${row.amountUsd}|${row.method}`;
if (!seenIncidents.has(key)) {
seenIncidents.add(key);
rows.push(row);
}
};
for (const m of both.matchAll(
/\[observed — Gmail card alert, (\d{4}-\d{2}-\d{2}) [^\]]*\] Meta PAYG \(METAPAY\) —\s*\*\*\$(\d+(?:\.\d+)?) charged[^*]*\*\* \(([A-Za-z ]+?) card ending (\d{4})/g,
)) {
pushIncident(m[1], m[2], m[3], m[4]);
}
for (const m of both.matchAll(
/Newer dated charge \((\d{4}-\d{2}-\d{2})\): \$(\d+(?:\.\d+)?) charged[^.]*?on ([A-Za-z ]+?) card ending (\d{4})/g,
)) {
pushIncident(m[1], m[2], m[3], m[4]);
}
const cline = sectionOf(doc, /^### ClinePass/);
const clineCharge = /Cline Bot Inc\., \*\*\$(\d+(?:\.\d+)?)\*\* via Link, invoice (\S+)/.exec(cline);
if (clineCharge) {
Expand Down
12 changes: 12 additions & 0 deletions pm-stack/aggregator/test/quota.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ describe("quota extractors", () => {
expect(pools.filter((x) => x.provider.includes("Meta")).length).toBe(1);
});

test("meta billing-blocked read walls the pool with a truthful note, even after the reset", () => {
const blockedView = VIEW.replace(
"weekly quota **46% used at 03:20 CDT**, then burned to empty by morning sessions and spilled to PAYG. **Weekly reset today 2026-10-25 19:00 CDT.**",
"**Freshest dated read (2026-10-26, laptop meta-provider probes 14:30–14:42Z): API returns 402 billing_not_configured (billing-verification wall) on all 11 probes — pool BLOCKED, no usable quota.** Weekly reset was today 2026-10-25 19:00 CDT (that reset has since passed).",
);
const p = extractQuotaPools(blockedView, new Date("2026-10-26T17:00:00Z")).find((x) => x.id === "meta:high-usage")!;
expect(p.state).toBe("walled");
expect(p.note).toContain("billing_not_configured");
expect(p.note).toContain("2026-10-26");
expect(p.wallLiftsAt).toBeUndefined();
});

test("opencode go workspaces are separate pools in USD", () => {
const personal = byId.get("opencode-go:personal")!;
expect(personal.windows[0]).toMatchObject({ unit: "usd", limit: 60, used: 36 });
Expand Down
15 changes: 15 additions & 0 deletions pm-stack/aggregator/test/usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ describe("payg lines + charges (§1.2, §2.4)", () => {
expect(meta[0].source).toContain("card alert");
});

test("single dated Meta charge incidents land as their own rows, deduped across both records", () => {
const registry = `- [observed — Gmail card alert, 2026-10-26 10:08 CDT] Meta PAYG (METAPAY) —\n **$20.00 charged 10:08 CDT** (Citi Costco card ending 9545; merchant "Metapay*uc5dpa22y4").`;
const view = `### Meta Model API\n- **Usage / dates:** **Newer dated charge (2026-10-26): $20.00 charged 10:08 CDT — Meta PAYG (METAPAY), merchant "Metapay*uc5dpa22y4", on Citi Costco card ending 9545 (Gmail card alert).**`;
const meta = extractCharges(view, registry).filter((c) => c.label === "Meta PAYG spill");
expect(meta).toEqual([
{
at: "2026-10-26",
label: "Meta PAYG spill",
amountUsd: 20,
method: "Citi Costco •9545",
source: "Gmail card alert (registry billing incidents)",
},
]);
});

test("subscriptions strip is renewal-only rows from the records", () => {
const subs = extractSubscriptions(`${VIEW}\n### Other / flat (b)\n- **Amazon RxPass:** Subscription $5/mo; flat pharmacy.\n### Wispr Flow\n- **Plan:** Flow Pro annual $151.91/yr charged; renews 2027-10-09.`);
expect(subs).toEqual([
Expand Down
Loading