diff --git a/pm-stack/aggregator/src/saas-extract.ts b/pm-stack/aggregator/src/saas-extract.ts index 85cf3f9876..b627e11f6c 100644 --- a/pm-stack/aggregator/src/saas-extract.ts +++ b/pm-stack/aggregator/src/saas-extract.ts @@ -441,19 +441,61 @@ const githubMetrics: MetricExtractor = (section) => { const modalMetrics: MetricExtractor = (section) => { const plan = bullet(section, /\*\*Plan \/ price \/ allowance:\*\*/); + const usage = bullet(section, /\*\*Usage \/ dates:\*\*/); const credits = /\$(\d+(?:\.\d+)?) monthly compute-credit/.exec(plan); + // Monthly console read (§2.2, #1111): the Usage bullet carries the + // dated used figure, e.g. "$12.50 compute credits used on 2026-10-24" + // or "used $12.50". Plan bullet holds the $30/mo grant (the limit). + // Percentage reads (e.g. "used 50% of monthly compute credits") are + // deliberately NOT numbers: no fallback below matches a bare number, + // so they stay null instead of masquerading as dollars (Codex P2). + const usedMatch = + /\$(\d+(?:\.\d+)?)\s*(?:monthly\s*)?compute\s+credits?\s*used/i.exec(usage) ?? + /(\d+(?:\.\d+)?)\s*credits?\s*used/i.exec(usage) ?? + /used[:\s]+\$(\d+(?:\.\d+)?)/i.exec(usage) ?? + /used[:\s]+(\d+(?:\.\d+)?)\s*credits?\b/i.exec(usage); + const used = usedMatch ? Number(usedMatch[1]) : null; return [ metric({ id: "compute-credits", label: "Compute credits / month", unit: "usd", + used, limit: credits ? Number(credits[1]) : 30, highlight: true, - note: "No run hours or credit balance recorded — manual dashboard read (§2.2).", + note: used != null ? "Monthly console read (§2.2)." : "No run hours or credit balance recorded — manual dashboard read (§2.2).", }), ]; }; +/** Bitwarden Secrets Manager (#1111): counts only — secret + * names/values never enter the hub. The Usage bullet carries the dated + * `bws` count-only read, e.g. "121 secrets, 1 project (bws count-only + * read 2026-10-26)". No metrics until a dated count is recorded. */ +const bitwardenMetrics: MetricExtractor = (section) => { + const usage = bullet(section, /\*\*Usage \/ dates:\*\*/); + const secrets = /(\d+)\s*secrets?/i.exec(usage); + const projects = /(\d+)\s*projects?/i.exec(usage); + return [ + metric({ + id: "secrets-count", + label: "Secrets", + unit: "count", + used: secrets ? Number(secrets[1]) : null, + highlight: true, + note: "bws count-only read (§2.2); names/values never enter the hub.", + }), + metric({ + id: "projects-count", + label: "Projects", + unit: "count", + used: projects ? Number(projects[1]) : null, + highlight: true, + note: "bws count-only read (§2.2); names/values never enter the hub.", + }), + ].filter((m) => m.used != null); +}; + const ociMetrics: MetricExtractor = (section) => { const plan = bullet(section, /\*\*Plan \/ price \/ allowance:\*\*/); return [ @@ -585,7 +627,7 @@ const SERVICE_SPECS: ServiceSpec[] = [ summaryKey: /^Bitwarden/, status: "active", cadenceDays: 7, - metrics: () => [], + metrics: bitwardenMetrics, shellNote: "Counts only in this hub — secret names/values never enter it. No count recorded yet; plan/price unknown.", }, diff --git a/pm-stack/aggregator/test/usage.test.ts b/pm-stack/aggregator/test/usage.test.ts index efcf3472d9..1388d8bb61 100644 --- a/pm-stack/aggregator/test/usage.test.ts +++ b/pm-stack/aggregator/test/usage.test.ts @@ -108,6 +108,57 @@ describe("saas extraction (Part b)", () => { expect(shells.length).toBe(8); expect(shells.every((s) => s.measuredAt === null)).toBe(true); }); + + test("modal: monthly console read carries a dated used-credits value", () => { + const view = VIEW.replace( + "- **Usage / dates:** Percentage/pace unknown; monthly grant, exact reset/credit expiry date unknown.", + "- **Usage / dates:** $12.50 compute credits used on 2026-10-24; monthly grant, exact reset unknown.", + ).replace( + "- **Last checked:** 2026-10-22 (Tracker).", + "- **Last checked:** console read 2026-10-24.", + ); + const modal = new Map(extractSaasServices(view).map((s) => [s.id, s])).get("modal")!; + const credits = modal.metrics.find((m) => m.id === "compute-credits")!; + expect(credits.used).toBe(12.5); + expect(credits.limit).toBe(30); + expect(credits.percent).toBeCloseTo(41.7, 1); + expect(modal.measuredAt).toBe("2026-10-24"); + }); + + test("modal: percentage read is not mistaken for dollars", () => { + const view = VIEW.replace( + "- **Usage / dates:** Percentage/pace unknown; monthly grant, exact reset/credit expiry date unknown.", + "- **Usage / dates:** used 50% of monthly compute credits on 2026-10-24; monthly grant, exact reset unknown.", + ); + const modal = new Map(extractSaasServices(view).map((s) => [s.id, s])).get("modal")!; + const credits = modal.metrics.find((m) => m.id === "compute-credits")!; + expect(credits.used).toBeNull(); + }); + + test("modal: no used figure stays an allowance-only shell", () => { + const modal = byId.get("modal")!; + expect(modal.metrics.find((m) => m.id === "compute-credits")?.used).toBeNull(); + }); + + test("bitwarden: bws count-only read yields dated secrets/projects metrics", () => { + const view = `${VIEW} +### Bitwarden +- **Plan / price / allowance:** Secrets Manager; plan/price unknown. +- **Usage / dates:** 121 secrets, 1 project (bws count-only read 2026-10-26). +- **PAYG estimate:** not applicable — flat account-tooling plan. +- **Last checked:** bws count-only read 2026-10-26. +`; + const bw = new Map(extractSaasServices(view).map((s) => [s.id, s])).get("bitwarden")!; + const m = new Map(bw.metrics.map((x) => [x.id, x])); + expect(m.get("secrets-count")?.used).toBe(121); + expect(m.get("projects-count")?.used).toBe(1); + expect(bw.measuredAt).toBe("2026-10-26"); + }); + + test("bitwarden: no dated count stays an empty shell, names/values never parsed", () => { + const bw = byId.get("bitwarden")!; + expect(bw.metrics).toEqual([]); + }); }); describe("payg lines + charges (§1.2, §2.4)", () => {