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
7 changes: 7 additions & 0 deletions pm-stack/aggregator/scripts/backfill-usage-snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
// of CNY 44.64; that is a different observation with no dated source
// line here, so no record is invented for it.
//
// NOTE (2026-11-03 config-name alignment): the service ids below are
// the pool ids in use on these records' 2026-10-20..25 observation
// dates (meta:high-usage, openai:codex, opencode-go:personal, ...).
// They are kept verbatim on purpose: this seed writes HISTORY, and
// the live rename starts new snapshot series under the config
// provider ids rather than rewriting the old series.
//
// Usage: bun run scripts/backfill-usage-snapshots.ts [--dir <storeDir>]
// Env: PM_AGG_SNAPSHOTS_DIR, QUOTA_VIEW_PATH, QUOTA_REGISTRY_PATH.
import { readFile } from "node:fs/promises";
Expand Down
10 changes: 5 additions & 5 deletions pm-stack/aggregator/scripts/collect-fleet-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,21 @@ const passwordFile =
function poolFor(provider: string, model: string): string | null {
switch (provider) {
case "meta":
return "meta:high-usage";
return "meta";
case "claude-code":
return "anthropic:claude-pro";
case "openai":
case "openai-codex":
case "chatgpt":
return "openai:codex";
return "openai";
case "openai.alternate":
return "openai.alternate";
case "cline-pass":
return "cline-pass:cline-pass";
return "cline-pass";
case "opendesign":
return "opendesign:go";
return "opendesign";
case "deepseek":
return "deepseek:api";
return "deepseek";
case "antigravity-ls":
case "antigravity-agy":
case "google":
Expand Down
46 changes: 31 additions & 15 deletions pm-stack/aggregator/src/quota-extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// assistant's Power subscription is never a pool, so no extractor here
// emits either.
// exactly TWO ChatGPT pools — the main account (drewrypope) reached
// through the `codex` gatherer door (pool openai:codex) and the
// through the `codex` gatherer door (pool openai) and the
// alternate account (popesdrew) through the `openai.alternate` door
// (pool openai.alternate). Separate accounts, separate allowances:
// never collapse them into one pool.
Expand Down Expand Up @@ -467,9 +467,22 @@ interface PoolSpec {
shellNote: string;
}

// POOL NAMING (2026-11-03, Drew): a pool's id is its OpenCode config
// provider id whenever the config defines one — meta, openai,
// openai.alternate, opencode-go.drewrypope, opencode-go.popesdrew, cline-pass,
// opendesign, deepseek, commandcode. The colon-suffixed spellings these
// replaced (meta:high-usage, openai:codex, opencode-go:drewrypope, ...)
// survive only in the historical snapshot series and the one-shot
// backfill seed (scripts/backfill-usage-snapshots.ts), which keep the
// ids in use on their observation dates. Two pools keep colon ids
// because the config defines no provider with their name:
// anthropic:claude-pro (burned through the claude-code provider) and
// the antigravity:* splits (burned through antigravity-ls /
// antigravity-agy / google; the config's antigravity-direct is a
// different door and renaming would misattribute the pools).
export const POOL_SPECS: PoolSpec[] = [
{
id: "meta:high-usage",
id: "meta",
provider: "Meta Model API",
plan: "Muse API High Usage",
heading: /^### Meta Model API/,
Expand All @@ -485,7 +498,7 @@ export const POOL_SPECS: PoolSpec[] = [
shellNote: "No current read (console-only usage).",
},
{
id: "openai:codex",
id: "openai",
provider: "OpenAI",
plan: "ChatGPT (Codex pool)",
heading: /^### ChatGPT/,
Expand All @@ -499,34 +512,34 @@ export const POOL_SPECS: PoolSpec[] = [
heading: /^### ChatGPT \(Alternate\)/,
extract: extractChatGptAlternate,
shellNote:
"No dated read. The fleet's second ChatGPT account (popesdrew), measured live by the quota gatherer through the openai.alternate credential — a separate pool from the main account (openai:codex); the two are never combined.",
"No dated read. The fleet's second ChatGPT account (popesdrew), measured live by the quota gatherer through the openai.alternate credential — a separate pool from the main account (openai); the two are never combined.",
},
{
id: "opencode-go:drewrypope",
id: "opencode-go.drewrypope",
provider: "OpenCode Go",
plan: "drewrypope account",
heading: /^### OpenCode Go/,
extract: goWorkspace("drewrypope"),
shellNote: "No current read.",
},
{
id: "opencode-go:popesdrew",
id: "opencode-go.popesdrew",
provider: "OpenCode Go",
plan: "popesdrew account",
heading: /^### OpenCode Go/,
extract: goWorkspace("popesdrew"),
shellNote: "No current read.",
},
{
id: "cline-pass:cline-pass",
id: "cline-pass",
provider: "ClinePass",
plan: "Cline Pass (Annual)",
heading: /^### ClinePass/,
extract: extractClinePass,
shellNote: "No current read (dashboard-only source).",
},
{
id: "commandcode:go",
id: "commandcode",
provider: "Command Code",
plan: "GO",
heading: /^### Command Code/,
Expand Down Expand Up @@ -554,15 +567,15 @@ export const POOL_SPECS: PoolSpec[] = [
/** Pools that render with identity only (no dated-read extractor). */
const SHELL_POOLS: QuotaPool[] = [
{
id: "opendesign:go",
id: "opendesign",
provider: "Open Design",
plan: "Go",
state: "healthy",
windows: [],
note: "No dated read. Live windows arrive through the quota gatherer (the OpenCode opendesign credential, read by the OpenChamber quota module) and are overlaid onto this pool by overlayQuotaCurrent.",
},
{
id: "deepseek:api",
id: "deepseek",
provider: "DeepSeek",
plan: "API (PAYG)",
state: "healthy",
Expand All @@ -586,8 +599,11 @@ const POOL_DOOR_PROVIDER_ID: Record<string, string> = {

/**
* The opencode provider id whose disablement filters a pool: the pool's
* door provider ("openai" in "openai:codex"; "claude-code" for
* "anthropic:claude-pro").
* door provider. Since the 2026-11-03 config-name alignment the pool id
* IS the door provider id for every single-door pool ("openai",
* "meta", "cline-pass", "opendesign", "opencode-go.personal", ...);
* the one exception is "anthropic:claude-pro", whose door is
* "claude-code" (there is no `anthropic` provider in the config).
*/
export function poolProviderId(poolId: string): string {
return POOL_DOOR_PROVIDER_ID[poolId] ?? poolId.split(":")[0];
Expand Down Expand Up @@ -630,13 +646,13 @@ export function poolFilteredByDisabled(poolId: string, disabledProviderIds: Read
* hiding it would leave a live pool unreported. Drew, 2026-11-03:
* meta and opendesign are standard report members and must show real
* quotas gathered by asking OpenCode. Today the list holds only
* meta:high-usage: the deployed config disables the `meta` provider
* meta: the deployed config disables the `meta` provider
* as a direct session door, which otherwise filtered the pool at
* assembly and left the board with no Meta row at all, while the
* gatherer's module read (serviceId meta:high-usage) had no pool to
* gatherer's module read (serviceId meta) had no pool to
* land on.
*/
export const FILTER_EXEMPT_POOL_IDS: ReadonlySet<string> = new Set(["meta:high-usage"]);
export const FILTER_EXEMPT_POOL_IDS: ReadonlySet<string> = new Set(["meta"]);

/** True when the disabled-door filter must not drop this pool. */
export function poolFilterExempt(poolId: string): boolean {
Expand Down
25 changes: 14 additions & 11 deletions pm-stack/aggregator/src/quota-gather-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ export function normalizeResetAt(v: unknown): string | null {

/**
* Hub pool/snapshot service id for a provider result. Mirrors
* POOL_SPECS (src/quota-extract.ts) where a pool exists, so gatherer
* records continue the series the dated-read writers started.
* POOL_SPECS (src/quota-extract.ts) where a pool exists. Pool ids are
* the OpenCode config provider ids (2026-11-03 alignment — see the
* POOL NAMING note in quota-extract.ts), so a renamed pool starts a
* NEW snapshot series under its config name; the pre-rename series
* stays in the store under the old colon id, unrewritten.
* OpenCode Go answers one row per workspace credential (the module's
* per-credential fetch); each row lands under the bare id, and
* entriesWithPoolSplits below ALSO files attributable rows under
Expand All @@ -69,15 +72,15 @@ export function serviceIdFor(providerId: string): string {
case "claude":
return "anthropic:claude-pro";
case "codex":
return "openai:codex";
return "openai";
case "cline-pass":
return "cline-pass:cline-pass";
return "cline-pass";
case "deepseek":
return "deepseek:api";
return "deepseek";
case "meta":
return "meta:high-usage";
return "meta";
case "opendesign":
return "opendesign:go";
return "opendesign";
default:
return providerId;
}
Expand All @@ -96,8 +99,8 @@ export const GATHERER_SOURCE = "openchamber-quota";
* These MUST mirror POOL_SPECS (src/quota-extract.ts) — the overlay side
* of this contract.
*/
export const GO_DREWRYPOPE_SERVICE_ID = "opencode-go:drewrypope";
export const GO_POPESDREW_SERVICE_ID = "opencode-go:popesdrew";
export const GO_DREWRYPOPE_SERVICE_ID = "opencode-go.drewrypope";
export const GO_POPESDREW_SERVICE_ID = "opencode-go.popesdrew";
export const ANTIGRAVITY_GEMINI_SERVICE_ID = "antigravity:gemini";
export const ANTIGRAVITY_CLAUDE_GPT_SERVICE_ID = "antigravity:claude-gpt";

Expand Down Expand Up @@ -231,7 +234,7 @@ const FILE_EXPORT_WINDOW_SECONDS: Record<string, number> = { "5h": 18_000, weekl

/**
* Map one file-export document onto a quota-current entry. The v1
* producer was Meta (service meta:high-usage, ~/atlas/meta-quota-
* producer was Meta (service meta, ~/atlas/meta-quota-
* export/latest.json on the laptop) — retired 2026-11-03 when the
* gatherer began asking the OpenCode quota module for Meta
* directly (PR #5040); the mapper stays as the #1301 convention's
Expand All @@ -247,7 +250,7 @@ export function entryFromFileExport(
const entry: QuotaCurrentEntry = {
providerId: "meta",
providerName: "Meta",
serviceId: "meta:high-usage",
serviceId: "meta",
state: "error",
measuredAt: opts.fileMtimeIso ?? new Date(0).toISOString(),
source: doc?.source ?? "file-export",
Expand Down
2 changes: 1 addition & 1 deletion pm-stack/aggregator/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ function attentionStripHtml(usage: UsageView): string {
* the yuan figure as read, never converted to dollars.
*/
function paygBalanceHtml(usage: UsageView): string {
const recs = (usage.history["deepseek:api"] ?? []).filter((r) => r.unit === "cny" && typeof r.value === "number");
const recs = (usage.history["deepseek"] ?? []).filter((r) => r.unit === "cny" && typeof r.value === "number");
if (!recs.length) return "";
const last = recs[recs.length - 1];
return `<div><strong>DeepSeek PAYG reserve balance</strong>: <strong>¥${(last.value as number).toFixed(2)}</strong><br><span class="muted">reserve only — never a routine route · measured ${esc(last.ts.slice(0, 10))} · ${esc(last.observedBy)}</span></div>`;
Expand Down
6 changes: 3 additions & 3 deletions pm-stack/aggregator/src/snapshot-records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function recordsFromPaygLines(lines: PaygLine[], observedBy: string): Sna
if (line.accruedUsd != null) {
out.push({
ts,
serviceId: line.id === "meta-payg" ? "meta:high-usage" : line.id,
serviceId: line.id === "meta-payg" ? "meta" : line.id,
metricId: "payg-accrued",
value: line.accruedUsd,
unit: "usd",
Expand Down Expand Up @@ -183,7 +183,7 @@ export function recordsFromDeepseekBalance(quotaViewText: string, observedBy: st
return [
{
ts: dayTs(date),
serviceId: "deepseek:api",
serviceId: "deepseek",
metricId: "credits_balance",
value,
unit: "cny",
Expand Down Expand Up @@ -308,7 +308,7 @@ export function recordsFromProviderUsage(snap: unknown, observedBy: string): Sna
if (!metricId) return;
out.push({
ts,
serviceId: "openai:codex",
serviceId: "openai",
metricId,
value: win.used_percent,
unit: "pct",
Expand Down
6 changes: 3 additions & 3 deletions pm-stack/aggregator/src/sources/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export const FIXTURE_QUOTA: QuotaView = {
activeSessions: [],
},
{
id: "opencode-go:drewrypope",
id: "opencode-go.drewrypope",
provider: "OpenCode Go",
plan: "drewrypope",
state: "near",
Expand Down Expand Up @@ -403,7 +403,7 @@ export const FIXTURE_QUOTA: QuotaView = {
],
},
{
id: "deepseek:api",
id: "deepseek",
provider: "DeepSeek",
plan: "API balance",
state: "healthy",
Expand Down Expand Up @@ -439,7 +439,7 @@ export const FIXTURE_QUOTA: QuotaView = {
choices: {
hasHeadroom: ["antigravity:claude", "antigravity:gemini", "meta:model-api", "openai:chatgpt"],
burnBeforeReset: ["antigravity:gemini", "antigravity:claude"],
doNotStart: ["anthropic:claude-subscription", "opencode-go:drewrypope"],
doNotStart: ["anthropic:claude-subscription", "opencode-go.drewrypope"],
},
};

Expand Down
6 changes: 3 additions & 3 deletions pm-stack/aggregator/test/clinepass-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const PREVIOUS: PreviousValue<QuotaCurrentEntry> = {
value: {
providerId: "cline-pass",
providerName: "ClinePass",
serviceId: "cline-pass:cline-pass",
serviceId: "cline-pass",
state: "ok",
measuredAt: "2026-11-02T11:45:00Z",
source: "token-adapter/cline-pass",
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("parseClinePassPayload (ported OpenChamber mapping)", () => {
test("entry mapping lands on the cline-pass service id with pct windows", () => {
const entry = entryFromClinePassReading(parseClinePassPayload(DOCUMENTED), NOW.toISOString());
expect(entry.providerId).toBe("cline-pass");
expect(entry.serviceId).toBe("cline-pass:cline-pass");
expect(entry.serviceId).toBe("cline-pass");
expect(entry.state).toBe("ok");
expect(entry.windows.map((w) => [w.name, w.pctOfLimit])).toEqual([
["5h", 43],
Expand Down Expand Up @@ -237,7 +237,7 @@ describe("gatherClinePass (gatherer registration path)", () => {
fetchImpl: async () => ({ status: 200, text: async () => JSON.stringify(DOCUMENTED) }),
});
expect(out.status).toBe("ok");
expect(out.value?.serviceId).toBe("cline-pass:cline-pass");
expect(out.value?.serviceId).toBe("cline-pass");
expect(out.value?.windows.map((w) => w.name)).toEqual(["5h", "weekly", "monthly"]);
expect(JSON.stringify(out)).not.toContain("fixture-token");
});
Expand Down
Loading