From 69cf4a8fde43e5cc7e152a7643d197dd53748733 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 10:23:32 +0900 Subject: [PATCH 01/18] feat(paseo-omp): tag quota accounts with plan and organization - Read each account's plan and organization from OMP's cached usage reports and show them as badges. - Show an Anthropic organization named after the account's email as Personal. - Show reset countdowns a day or more away as days and hours. --- paseo-omp/README.md | 2 +- paseo-omp/client/quota-popover.tsx | 21 ++++ paseo-omp/client/quota-state.ts | 39 ++++++- paseo-omp/server/quota.ts | 70 +++++++++++++ paseo-omp/shared/quota.ts | 4 + paseo-omp/tests/omp-state.test.ts | 4 + paseo-omp/tests/omp-store-client.test.ts | 2 + paseo-omp/tests/quota-popover.test.tsx | 15 +++ paseo-omp/tests/quota-state.test.ts | 125 +++++++++++++++++++++++ 9 files changed, 279 insertions(+), 3 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 305c2c87..3760cbb0 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Provider summary percentages show the highest recorded usage across that provider's accounts. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges under each account show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index aa44582e..dae2eccf 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -93,6 +93,18 @@ export function QuotaPopover(props: PluginButtonContentProps) { minWidth: 0, }, accountSuffix: { color: theme.colors.foregroundMuted, fontSize: 11, flexShrink: 0 }, + tags: { flexDirection: "row" as const, flexWrap: "wrap" as const, gap: 4 }, + tag: { + color: theme.colors.foregroundMuted, + fontSize: 10, + fontWeight: "600" as const, + paddingHorizontal: 6, + paddingVertical: 1, + borderRadius: 999, + borderWidth: 1, + borderColor: theme.colors.border, + overflow: "hidden" as const, + }, }), [layout.compact, theme], ); @@ -154,6 +166,15 @@ export function QuotaPopover(props: PluginButtonContentProps) { ) : null} ) : null} + {account.tags.length > 0 ? ( + + {account.tags.map((tag) => ( + + {tag} + + ))} + + ) : null} {account.accountService ? ( {account.accountService === "github" diff --git a/paseo-omp/client/quota-state.ts b/paseo-omp/client/quota-state.ts index 9518a602..3c17d8d2 100644 --- a/paseo-omp/client/quota-state.ts +++ b/paseo-omp/client/quota-state.ts @@ -97,6 +97,8 @@ export type QuotaAccountGroup = { accountService: OmpQuota["accountService"]; accountHost: string | null; label: string | null; + /** Plan and organization badges, e.g. "Business", "Personal" or an organization name. */ + tags: string[]; suffix: string | null; quotas: OmpQuota[]; peakFraction: number | null; @@ -143,6 +145,37 @@ export function quotaProviderGroups( return groups; } +const PLAN_LABELS: Record = { + free: "Free", + go: "Go", + plus: "Plus", + pro: "Pro", + prolite: "Pro Lite", + max: "Max", + team: "Team", + business: "Business", + self_serve_business_prolite: "Business", + self_serve_business_usage_based: "Business", + enterprise: "Enterprise", + enterprise_cbp_automation: "Enterprise", + enterprise_cbp_usage_based: "Enterprise", + edu: "Edu", +}; + +function accountTags(quotas: readonly OmpQuota[], email: string | null): string[] { + const plan = quotas.find((quota) => quota.plan)?.plan ?? null; + const organization = quotas.find((quota) => quota.organization)?.organization ?? null; + const tags: string[] = []; + if (plan) { + tags.push(PLAN_LABELS[plan.toLowerCase()] ?? plan.charAt(0).toUpperCase() + plan.slice(1)); + } + // Anthropic names a personal account's default organization after its email. + if (organization) { + tags.push(email && organization === `${email}'s Organization` ? "Personal" : organization); + } + return [...new Set(tags)]; +} + function quotaAccountGroups(quotas: readonly OmpQuota[]): QuotaAccountGroup[] { const byAccount = new Map(); for (const quota of quotas) { @@ -165,6 +198,7 @@ function quotaAccountGroups(quotas: readonly OmpQuota[]): QuotaAccountGroup[] { email, accountService: service?.accountService ?? null, accountHost: service?.accountHost ?? null, + tags: accountTags(accountQuotas, email), label: email ?? accountId, suffix: null, quotas: [...accountQuotas].sort((a, b) => (b.usedFraction ?? -1) - (a.usedFraction ?? -1)), @@ -207,9 +241,10 @@ function quotaAccountGroups(quotas: readonly OmpQuota[]): QuotaAccountGroup[] { export function quotaResetLabel(resetsAtMs: number | null, nowMs: number = Date.now()): string { if (resetsAtMs === null) return ""; const remainingMs = Math.max(0, resetsAtMs - nowMs); - const hours = Math.floor(remainingMs / 3_600_000); + const totalHours = Math.floor(remainingMs / 3_600_000); const minutes = Math.floor((remainingMs % 3_600_000) / 60_000); - return hours > 0 ? `resets ${hours}h ${minutes}m` : `resets ${minutes}m`; + if (totalHours >= 24) return `resets ${Math.floor(totalHours / 24)}d ${totalHours % 24}h`; + return totalHours > 0 ? `resets ${totalHours}h ${minutes}m` : `resets ${minutes}m`; } export function quotaRecordedLabel(recordedAtMs: number, nowMs: number = Date.now()): string { diff --git a/paseo-omp/server/quota.ts b/paseo-omp/server/quota.ts index 9d4665e3..8a5bfb83 100644 --- a/paseo-omp/server/quota.ts +++ b/paseo-omp/server/quota.ts @@ -46,6 +46,74 @@ function copilotAccount(accountKey: string): CopilotAccount { } } +const CachedReportSchema = z.object({ + value: z.object({ + provider: z.string(), + fetchedAt: z.number(), + metadata: z + .object({ + plan: z.string().nullish(), + planType: z.string().nullish(), + orgName: z.string().nullish(), + }) + .nullish(), + }), +}); + +type AccountTags = Pick; +type CachedReport = AccountTags & { key: string; provider: string; fetchedAt: number }; + +/** OMP's usage cache; missing on older OMP versions, so any failure yields no tags. */ +function readCachedReports(database: DatabaseSync): CachedReport[] { + let rows: Record[]; + try { + rows = database + .prepare("SELECT key, value FROM cache WHERE key LIKE 'usage_cache:report:%'") + .all(); + } catch { + return []; + } + return rows.flatMap(({ key, value }) => { + if (typeof key !== "string" || typeof value !== "string") return []; + let json: unknown; + try { + json = JSON.parse(value); + } catch { + return []; + } + const parsed = CachedReportSchema.safeParse(json); + if (!parsed.success) return []; + const { provider, fetchedAt, metadata } = parsed.data.value; + const plan = (metadata?.planType ?? metadata?.plan)?.trim() || null; + const organization = metadata?.orgName?.trim() || null; + return [ + { + key, + provider, + fetchedAt, + plan, + // Codex reports its plan as the organization name too; that is not an organization. + organization: organization?.toLowerCase() === plan?.toLowerCase() ? null : organization, + }, + ]; + }); +} + +/** OMP caches each report under a key that ends with the account_key usage_history records. */ +function accountTags( + reports: readonly CachedReport[], + provider: string, + accountKey: string, +): AccountTags { + const matches = reports + .filter((report) => report.provider === provider && report.key.endsWith(`:${accountKey}`)) + .sort((a, b) => b.fetchedAt - a.fetchedAt); + return { + plan: matches.find((report) => report.plan)?.plan ?? null, + organization: matches.find((report) => report.organization)?.organization ?? null, + }; +} + // Only live windows are returned: a series whose newest row already reset (or never resets and was // abandoned) would otherwise pin the pill at its last exhausted value and bloat the popover. export function listOmpQuotasFrom(path: string, now = Date.now()): OmpQuota[] { @@ -79,6 +147,7 @@ export function listOmpQuotasFrom(path: string, now = Date.now()): OmpQuota[] { ORDER BY COALESCE(usedFraction, -1) DESC, provider, label, accountKey, limitId`, ) .all(now, now - ABANDONED_AFTER_MS); + const reports = readCachedReports(database); return rows.flatMap((row) => { const parsed = QuotaRowSchema.safeParse(row); if (!parsed.success) return []; @@ -91,6 +160,7 @@ export function listOmpQuotasFrom(path: string, now = Date.now()): OmpQuota[] { // account_id is only known to be a username for Copilot; other providers keep it private. accountId: copilot ? quota.accountId : null, ...(copilot ? copilotAccount(quota.accountKey) : UNKNOWN_SERVICE), + ...accountTags(reports, quota.provider, quota.accountKey), }, ]; }); diff --git a/paseo-omp/shared/quota.ts b/paseo-omp/shared/quota.ts index be39817b..23f6f5e0 100644 --- a/paseo-omp/shared/quota.ts +++ b/paseo-omp/shared/quota.ts @@ -16,6 +16,10 @@ export const OmpQuotaSchema = z.object({ accountService: z.enum(["github", "ghe"]).nullable(), /** GHE hostname; null for public GitHub and every other provider. */ accountHost: z.string().nullable(), + /** Raw plan OMP's cached usage report names (Codex `planType`, Copilot `plan`). */ + plan: z.string().nullable().default(null), + /** Organization name from OMP's cached usage report, when it is not just the plan. */ + organization: z.string().nullable().default(null), label: z.string(), windowLabel: z.string().nullable(), usedFraction: z.number().min(0).nullable(), diff --git a/paseo-omp/tests/omp-state.test.ts b/paseo-omp/tests/omp-state.test.ts index e010d3eb..75f256d1 100644 --- a/paseo-omp/tests/omp-state.test.ts +++ b/paseo-omp/tests/omp-state.test.ts @@ -68,6 +68,8 @@ describe("omp quota reader", () => { accountId: null, accountService: null, accountHost: null, + plan: null, + organization: null, label: "Claude 5 Hour", windowLabel: "5 Hour", usedFraction: 0.8, @@ -83,6 +85,8 @@ describe("omp quota reader", () => { accountId: null, accountService: null, accountHost: null, + plan: null, + organization: null, label: "Codex Weekly", windowLabel: "Weekly", usedFraction: 0.3, diff --git a/paseo-omp/tests/omp-store-client.test.ts b/paseo-omp/tests/omp-store-client.test.ts index ab0f847d..434d147a 100644 --- a/paseo-omp/tests/omp-store-client.test.ts +++ b/paseo-omp/tests/omp-store-client.test.ts @@ -16,6 +16,8 @@ const quota = (provider: string): OmpQuota => ({ accountId: null, accountService: null, accountHost: null, + plan: null, + organization: null, label: provider, windowLabel: null, usedFraction: 0.25, diff --git a/paseo-omp/tests/quota-popover.test.tsx b/paseo-omp/tests/quota-popover.test.tsx index fbbad5ee..4f7a5015 100644 --- a/paseo-omp/tests/quota-popover.test.tsx +++ b/paseo-omp/tests/quota-popover.test.tsx @@ -61,6 +61,8 @@ function quota(accountKey: string, limitId: string, usedFraction: number): OmpQu accountId: null, accountService: null, accountHost: null, + plan: null, + organization: null, label: "Usage", windowLabel: "Weekly", usedFraction, @@ -141,4 +143,17 @@ describe("quota popover reconciliation", () => { expect(secondLimit.isConnected).toBe(false); expect(container.textContent).not.toContain("80%"); }); + + test("shows plan and organization badges under the account heading", async () => { + await render([ + { + ...quota("a", "weekly", 0.4), + plan: "self_serve_business_prolite", + organization: "Example Team", + }, + ]); + const account = heading("same@example.invalid").parentElement; + expect(account?.contains(text("Business"))).toBe(true); + expect(account?.contains(text("Example Team"))).toBe(true); + }); }); diff --git a/paseo-omp/tests/quota-state.test.ts b/paseo-omp/tests/quota-state.test.ts index baa345f6..04d48b8e 100644 --- a/paseo-omp/tests/quota-state.test.ts +++ b/paseo-omp/tests/quota-state.test.ts @@ -32,6 +32,8 @@ const quotas: OmpQuota[] = [ accountId: null, accountService: null, accountHost: null, + plan: null, + organization: null, label: "Claude 5 Hour", windowLabel: "5 Hour", usedFraction: 0.25, @@ -47,6 +49,8 @@ const quotas: OmpQuota[] = [ accountId: null, accountService: null, accountHost: null, + plan: null, + organization: null, label: "Cursor Pro", windowLabel: null, usedFraction: 0.9, @@ -211,6 +215,8 @@ describe("quota timestamps", () => { accountId: null, accountService: null, accountHost: null, + plan: null, + organization: null, usedFraction: 0.25, windowLabel: "5 Hour", status: "ok", @@ -231,9 +237,128 @@ describe("quota reset countdown", () => { expect(quotaResetLabel(now - 1_000, now)).toBe("resets 0m"); expect(quotaResetLabel(null, now)).toBe(""); }); + + test("shows days and hours once a reset is a day or more away", () => { + const now = Date.UTC(2026, 0, 1, 0, 0, 0); + const at = (hours: number, minutes = 0) => now + hours * 3_600_000 + minutes * 60_000; + expect(quotaResetLabel(at(23, 59), now)).toBe("resets 23h 59m"); + expect(quotaResetLabel(at(24), now)).toBe("resets 1d 0h"); + expect(quotaResetLabel(at(357, 52), now)).toBe("resets 14d 21h"); + }); }); describe("OMP quota reader", () => { + test("tags accounts with the plan and organization from OMP's cached usage reports", async () => { + const root = await mkdtemp(join(tmpdir(), "paseo-omp-tags-")); + quotaRoots.push(root); + const path = join(root, "agent.db"); + const database = new DatabaseSync(path); + database.exec(`CREATE TABLE usage_history ( + id INTEGER PRIMARY KEY, provider TEXT, account_key TEXT, email TEXT, + limit_id TEXT, label TEXT, window_label TEXT, used_fraction REAL, status TEXT, + resets_at INTEGER, recorded_at INTEGER + ); + CREATE TABLE cache (key TEXT PRIMARY KEY, value TEXT, expires_at INTEGER)`); + const now = Date.now(); + const usage = database.prepare( + "INSERT INTO usage_history VALUES (?, ?, ?, ?, 'weekly', 'Weekly', NULL, 0.1, 'ok', NULL, ?)", + ); + usage.run( + 1, + "openai-codex", + "oauth|account:a|email:team@example.invalid", + "team@example.invalid", + now, + ); + usage.run( + 2, + "openai-codex", + "oauth|account:b|email:me@example.invalid", + "me@example.invalid", + now, + ); + usage.run( + 3, + "anthropic", + "oauth|account:c|email:me@example.invalid", + "me@example.invalid", + now, + ); + usage.run( + 4, + "anthropic", + "oauth|account:d|email:work@example.invalid", + "work@example.invalid", + now, + ); + usage.run(5, "xai-oauth", "oauth|account:e", null, now); + const cache = database.prepare("INSERT INTO cache VALUES (?, ?, NULL)"); + const report = (provider: string, fetchedAt: number, metadata: object) => + JSON.stringify({ expiresAt: 0, value: { provider, fetchedAt, limits: [], metadata } }); + cache.run( + "usage_cache:report:1:openai-codex:https://example.invalid/api:oauth|account:a|email:team@example.invalid", + report("openai-codex", 2, { + planType: "self_serve_business_prolite", + orgName: "self_serve_business_prolite", + }), + ); + cache.run( + "usage_cache:report:0:openai-codex:default:oauth|account:a|email:team@example.invalid", + report("openai-codex", 1, { planType: "plus" }), + ); + cache.run( + "usage_cache:report:1:openai-codex:default:oauth|account:b|email:me@example.invalid", + report("openai-codex", 1, { planType: "prolite", orgName: "prolite" }), + ); + cache.run( + "usage_cache:report:3:anthropic:default:oauth|account:c|email:me@example.invalid", + report("anthropic", 1, { orgName: "me@example.invalid's Organization" }), + ); + cache.run( + "usage_cache:report:3:anthropic:default:oauth|account:d|email:work@example.invalid", + report("anthropic", 1, { orgName: "Example Team" }), + ); + // Another provider's report under the same key suffix, and an unreadable one, are ignored. + cache.run( + "usage_cache:report:xai-oauth:default:oauth|account:c|email:me@example.invalid", + report("xai-oauth", 5, { plan: "business" }), + ); + cache.run("usage_cache:report:xai-oauth:default:oauth|account:e", "not json"); + database.close(); + + const recorded = listOmpQuotasFrom(path, now); + const tagsOf = (provider: string, email: string | null) => + quotaProviderGroups(recorded, null) + .find((group) => group.provider === provider) + ?.accounts.find((account) => account.email === email)?.tags; + expect(tagsOf("openai-codex", "team@example.invalid")).toEqual(["Business"]); + expect(tagsOf("openai-codex", "me@example.invalid")).toEqual(["Pro Lite"]); + expect(tagsOf("anthropic", "me@example.invalid")).toEqual(["Personal"]); + expect(tagsOf("anthropic", "work@example.invalid")).toEqual(["Example Team"]); + expect(tagsOf("xai-oauth", null)).toEqual([]); + }); + + test("reads quotas without tags when OMP has no usage cache table", async () => { + const root = await mkdtemp(join(tmpdir(), "paseo-omp-no-cache-")); + quotaRoots.push(root); + const path = join(root, "agent.db"); + const database = new DatabaseSync(path); + database.exec(`CREATE TABLE usage_history ( + id INTEGER PRIMARY KEY, provider TEXT, account_key TEXT, limit_id TEXT, label TEXT, + window_label TEXT, used_fraction REAL, status TEXT, resets_at INTEGER, recorded_at INTEGER + )`); + const now = Date.now(); + database + .prepare( + "INSERT INTO usage_history VALUES (1, 'anthropic', 'k', 'w', 'Weekly', NULL, 0.1, 'ok', NULL, ?)", + ) + .run(now); + database.close(); + expect(listOmpQuotasFrom(path, now)).toEqual([ + expect.objectContaining({ label: "Weekly", plan: null, organization: null }), + ]); + }); + test("shows Copilot usernames and distinguishes GitHub from the recorded GHE host", async () => { const root = await mkdtemp(join(tmpdir(), "paseo-omp-copilot-")); quotaRoots.push(root); From 8fee9282fadaca95abd237ce1685508177b682a4 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 12:44:31 +0900 Subject: [PATCH 02/18] fix(paseo-omp): show account badges beside the account name - Move plan and organization badges into the account heading row and its accessibility label. --- paseo-omp/README.md | 2 +- paseo-omp/client/quota-popover.tsx | 23 ++++++++++++++++------- paseo-omp/tests/quota-popover.test.tsx | 9 +++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 3760cbb0..2d1b2b1f 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges under each account show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index dae2eccf..df2c7915 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -85,7 +85,7 @@ export function QuotaPopover(props: PluginButtonContentProps) { }, detail: { color: theme.colors.foregroundMuted, fontSize: 11 }, account: { gap: 6, paddingTop: 4 }, - accountHeading: { flexDirection: "row" as const, alignItems: "baseline" as const }, + accountHeading: { flexDirection: "row" as const, alignItems: "center" as const }, accountLabel: { color: theme.colors.foregroundMuted, fontSize: 11, @@ -93,7 +93,8 @@ export function QuotaPopover(props: PluginButtonContentProps) { minWidth: 0, }, accountSuffix: { color: theme.colors.foregroundMuted, fontSize: 11, flexShrink: 0 }, - tags: { flexDirection: "row" as const, flexWrap: "wrap" as const, gap: 4 }, + tags: { flexDirection: "row" as const, gap: 4, flexShrink: 0 }, + headingTags: { flexDirection: "row" as const, gap: 4, flexShrink: 0, marginLeft: 6 }, tag: { color: theme.colors.foregroundMuted, fontSize: 10, @@ -153,9 +154,9 @@ export function QuotaPopover(props: PluginButtonContentProps) { {account.label ? ( @@ -164,9 +165,17 @@ export function QuotaPopover(props: PluginButtonContentProps) { {account.suffix ? ( {` · ${account.suffix}`} ) : null} + {account.tags.length > 0 ? ( + + {account.tags.map((tag) => ( + + {tag} + + ))} + + ) : null} - ) : null} - {account.tags.length > 0 ? ( + ) : account.tags.length > 0 ? ( {account.tags.map((tag) => ( diff --git a/paseo-omp/tests/quota-popover.test.tsx b/paseo-omp/tests/quota-popover.test.tsx index 4f7a5015..e965bf1a 100644 --- a/paseo-omp/tests/quota-popover.test.tsx +++ b/paseo-omp/tests/quota-popover.test.tsx @@ -144,7 +144,7 @@ describe("quota popover reconciliation", () => { expect(container.textContent).not.toContain("80%"); }); - test("shows plan and organization badges under the account heading", async () => { + test("shows plan and organization badges beside the account name", async () => { await render([ { ...quota("a", "weekly", 0.4), @@ -152,8 +152,9 @@ describe("quota popover reconciliation", () => { organization: "Example Team", }, ]); - const account = heading("same@example.invalid").parentElement; - expect(account?.contains(text("Business"))).toBe(true); - expect(account?.contains(text("Example Team"))).toBe(true); + const name = heading("same@example.invalid"); + expect(name.contains(text("Business"))).toBe(true); + expect(name.contains(text("Example Team"))).toBe(true); + expect(name.getAttribute("aria-label")).toBe("same@example.invalid · Business · Example Team"); }); }); From 4e3c63ab133f9625119b7b11c5cc03671a282e7a Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 12:46:01 +0900 Subject: [PATCH 03/18] test(paseo-omp): expose accessibility labels from the react-native test double --- paseo-omp/tests/quota-popover.test.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/paseo-omp/tests/quota-popover.test.tsx b/paseo-omp/tests/quota-popover.test.tsx index e965bf1a..6a0efff2 100644 --- a/paseo-omp/tests/quota-popover.test.tsx +++ b/paseo-omp/tests/quota-popover.test.tsx @@ -23,7 +23,12 @@ vi.mock("react-native", () => ({ accessibilityLabel?: string; style?: Record; }) => ( -
{props.children}
+
+ {props.children} +
), Text: (props: { children?: ReactNode }) => {props.children}, })); @@ -155,6 +160,8 @@ describe("quota popover reconciliation", () => { const name = heading("same@example.invalid"); expect(name.contains(text("Business"))).toBe(true); expect(name.contains(text("Example Team"))).toBe(true); - expect(name.getAttribute("aria-label")).toBe("same@example.invalid · Business · Example Team"); + expect(name.getAttribute("data-accessibility-label")).toBe( + "same@example.invalid · Business · Example Team", + ); }); }); From 0453354cbfa8bd952209278919ccd62e0fbda6e3 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 16:42:53 +0900 Subject: [PATCH 04/18] feat(paseo-omp): show and switch the session's account and tag OMP logins - Quota popover: ask the live OMP session (get_logout_accounts) which login it uses, show it on top, mark it IN USE first in its provider, and switch with `/session pin OAuth credential #`. - Link logins to recorded usage server-side by OMP's identity rule; only hashed account keys reach the client. - Separate accounts in the popover with dividers. - Accounts tab: plan and organization badges per login, sharing the popover's tag rules. --- paseo-omp/README.md | 4 +- paseo-omp/client/omp-accounts-section.tsx | 23 +- paseo-omp/client/quota-popover.tsx | 311 +++++++++++++----- paseo-omp/client/quota-state.ts | 60 ++-- paseo-omp/index.server.ts | 7 +- paseo-omp/server/omp-accounts.ts | 38 ++- paseo-omp/server/provider/omp-rpc-protocol.ts | 17 +- paseo-omp/server/provider/omp-rpc.ts | 11 + paseo-omp/server/provider/session.ts | 7 + paseo-omp/server/quota.ts | 129 +++++++- paseo-omp/server/subagents.ts | 5 +- paseo-omp/shared/account-tags.ts | 38 +++ paseo-omp/shared/omp-accounts.ts | 2 + paseo-omp/shared/quota.ts | 24 ++ paseo-omp/tests/helpers/provider-harness.ts | 7 + paseo-omp/tests/omp-accounts-state.test.ts | 1 + paseo-omp/tests/omp-accounts.test.ts | 50 +++ .../tests/provider-subagent-control.test.ts | 1 + paseo-omp/tests/quota-popover.test.tsx | 70 +++- paseo-omp/tests/quota-state.test.ts | 122 ++++++- 20 files changed, 793 insertions(+), 134 deletions(-) create mode 100644 paseo-omp/shared/account-tags.ts diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 2d1b2b1f..35862d7f 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -33,9 +33,9 @@ paseo plugin ls paseo-omp Open the **OMP** sidebar to review the provider-profile contract, choose which composer pills appear, browse and edit native scalar settings, manage OMP-native plugins, verify runtime health, and generate a bounded support report under **Help**. The same tabs, including Accounts, MCPs, and Composer, are available in the workspace OMP panel, which adds a workspace-only Security tab. Then create an agent and select **OMP Plugin**; on a new install, [enable it](#plugin-provider-opt-in) and restart the daemon first. Its optional **MCP** composer control runs OMP-native management commands in the current session; setup questions and authorization stay in that chat timeline, where OAuth can open in a workspace-scoped Paseo Browser or on the current device. While OMP subagents run, a row under each `task` card in the conversation lets you steer or stop one of them; this needs OMP 18.4.9 or newer. Composer pill preferences are shared by clients connected to the same host; normal use requires no other plugin-specific settings. -Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). +Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Each login shows plan and organization badges from its usage report, such as **Business**, **Pro Lite**, **Personal** or an organization name, and the label drops OMP's parenthesized organization once a badge shows it. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. For a live OMP Plugin session, the popover asks the session's OMP runtime (`get_logout_accounts`) which login it uses: **THIS SESSION USES** at the top names it, its account leads the current provider marked **IN USE**, and **Use for this session** on another linked login sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login links to recorded usage by OMP's identity rule (organization, then email, then account id); a provider with one login and one usage account links without one. Without a live session, or on an OMP that cannot list logins, **CURRENT PROVIDER** identifies only the session's provider. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/client/omp-accounts-section.tsx b/paseo-omp/client/omp-accounts-section.tsx index 3ee7e3ae..69cfae8c 100644 --- a/paseo-omp/client/omp-accounts-section.tsx +++ b/paseo-omp/client/omp-accounts-section.tsx @@ -191,9 +191,26 @@ function AccountCard({ return ( - - {account.label} - + + + {account.label} + + {account.tags.map((tag) => ( + + + {tag} + + + ))} + {account.resets ? ( {resetsLabel(account.resets)} diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index df2c7915..2d004da5 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -1,38 +1,73 @@ -import { type PluginButtonContentProps, useAgent, useRpc } from "@getpaseo/plugin/client"; +import { type PluginButtonContentProps, useAgent, usePaseo, useRpc } from "@getpaseo/plugin/client"; import { Icon } from "@getpaseo/plugin/client/ui"; -import { useQuery } from "@tanstack/react-query"; -import { useMemo } from "react"; -import { Text, View } from "react-native"; +import { useQuery, useQueryClient } from "@tanstack/react-query"; +import { useMemo, useState } from "react"; +import { Pressable, Text, View } from "react-native"; import { storeForProvider, storeLabel } from "../shared/omp-store"; -import { listOmpQuotas } from "../shared/quota"; +import { listOmpQuotas, listOmpSessionAccounts, type OmpSessionAccount } from "../shared/quota"; import { ompStoreKey } from "./omp-store-state"; import { type QuotaProviderGroup, + type QuotaSessionAccountGroup, + type QuotaSeverity, quotaDetailLabel, quotaProviderFromSession, quotaProviderGroups, quotaProviderIconName, quotaProviderLabel, + quotaSessionAccounts, quotaSeverityFromFraction, + sessionPinCommand, } from "./quota-state"; const QUOTA_POLL_MS = 30_000; export function QuotaPopover(props: PluginButtonContentProps) { - const { theme, layout } = props; + const { theme, layout, close } = props; const agentId = props.context === "agent" ? props.agentId : ""; - const session = useAgent(agentId, (agent) => ({ model: agent.model, provider: agent.provider })); + const session = useAgent(agentId, (agent) => ({ + model: agent.model, + provider: agent.provider, + status: agent.status, + })); const currentProvider = quotaProviderFromSession(session?.provider ?? "", session?.model ?? null); const store = storeForProvider(session?.provider); + const paseo = usePaseo(); + const queryClient = useQueryClient(); const loadQuotas = useRpc(listOmpQuotas); + const loadSessionAccounts = useRpc(listOmpSessionAccounts); const quotas = useQuery({ queryKey: ["paseo-omp", "quotas", ompStoreKey(store)], queryFn: () => loadQuotas({ store }), enabled: session !== undefined && session !== null, refetchInterval: QUOTA_POLL_MS, }); + const sessionAccountsKey = ["paseo-omp", "session-accounts", agentId, currentProvider]; + const sessionAccounts = useQuery({ + queryKey: sessionAccountsKey, + queryFn: () => loadSessionAccounts({ agentId, provider: currentProvider ?? "" }), + enabled: Boolean(agentId && currentProvider), + refetchInterval: QUOTA_POLL_MS, + retry: false, + }); + const [switching, setSwitching] = useState(null); + const [switchError, setSwitchError] = useState(null); + + async function switchTo(login: OmpSessionAccount): Promise { + setSwitching(login.credentialId); + setSwitchError(null); + try { + await paseo.agents.ref(agentId).send(sessionPinCommand(login.credentialId)); + await queryClient.invalidateQueries({ queryKey: sessionAccountsKey }); + close(); + } catch (cause) { + setSwitchError(cause instanceof Error ? cause.message : "Could not switch the account."); + } finally { + setSwitching(null); + } + } - function severityColor(severity: ReturnType): string { + function severityColor(severity: QuotaSeverity): string { if (severity === "danger") return theme.colors.statusDanger; if (severity === "warning") return theme.colors.statusWarning; if (severity === "ok") return theme.colors.statusSuccess; @@ -44,6 +79,31 @@ export function QuotaPopover(props: PluginButtonContentProps) { root: { gap: layout.compact ? 8 : 10, minWidth: layout.compact ? undefined : 260 }, muted: { color: theme.colors.foregroundMuted, fontSize: 13 }, error: { color: theme.colors.statusDanger, fontSize: 13 }, + sessionCard: { + gap: 4, + padding: layout.compact ? 10 : 12, + borderRadius: 10, + borderWidth: 2, + borderColor: theme.colors.accent, + backgroundColor: theme.colors.surface1, + }, + sessionHeading: { + color: theme.colors.foregroundMuted, + fontSize: 10, + fontWeight: "700" as const, + }, + sessionLabelRow: { + flexDirection: "row" as const, + alignItems: "center" as const, + flexWrap: "wrap" as const, + gap: 6, + }, + sessionLabel: { + color: theme.colors.foreground, + fontSize: 14, + fontWeight: "700" as const, + flexShrink: 1, + }, group: (current: boolean) => ({ gap: 6, padding: layout.compact ? 10 : 12, @@ -84,14 +144,22 @@ export function QuotaPopover(props: PluginButtonContentProps) { overflow: "hidden" as const, }, detail: { color: theme.colors.foregroundMuted, fontSize: 11 }, - account: { gap: 6, paddingTop: 4 }, + // Accounts after the first get a divider so each account's limits read as one block. + account: (first: boolean) => ({ + gap: 6, + paddingTop: first ? 4 : 10, + marginTop: first ? 0 : 4, + borderTopWidth: first ? 0 : 1, + borderTopColor: theme.colors.border, + }), accountHeading: { flexDirection: "row" as const, alignItems: "center" as const }, - accountLabel: { - color: theme.colors.foregroundMuted, + accountLabel: (inUse: boolean) => ({ + color: inUse ? theme.colors.foreground : theme.colors.foregroundMuted, fontSize: 11, + fontWeight: inUse ? ("700" as const) : ("400" as const), flexShrink: 1, minWidth: 0, - }, + }), accountSuffix: { color: theme.colors.foregroundMuted, fontSize: 11, flexShrink: 0 }, tags: { flexDirection: "row" as const, gap: 4, flexShrink: 0 }, headingTags: { flexDirection: "row" as const, gap: 4, flexShrink: 0, marginLeft: 6 }, @@ -106,6 +174,18 @@ export function QuotaPopover(props: PluginButtonContentProps) { borderColor: theme.colors.border, overflow: "hidden" as const, }, + switch: { + alignSelf: "flex-start" as const, + paddingHorizontal: 8, + paddingVertical: 4, + borderWidth: 1, + borderColor: theme.colors.border, + borderRadius: 8, + backgroundColor: theme.colors.surface2, + }, + switchPressed: { opacity: 0.72 }, + switchDisabled: { opacity: 0.45 }, + switchText: { color: theme.colors.foreground, fontSize: 11, fontWeight: "600" as const }, }), [layout.compact, theme], ); @@ -115,18 +195,142 @@ export function QuotaPopover(props: PluginButtonContentProps) { const groups = quotaProviderGroups(quotas.data?.quotas ?? [], currentProvider); const hasCurrent = groups.some((group) => group.provider === currentProvider); + const logins = sessionAccounts.data?.accounts ?? []; + const activeLogin = logins.find((login) => login.active) ?? null; + const currentAccounts = quotaSessionAccounts( + groups.find((group) => group.provider === currentProvider)?.accounts ?? [], + logins, + ); + const activeAccount = currentAccounts.find((account) => account.inUse) ?? null; - if (groups.length === 0) { - return No provider quota data available.; + function renderTags(tags: readonly string[], style: object) { + return ( + + {tags.map((tag) => ( + + {tag} + + ))} + + ); + } + + function renderAccount(account: QuotaSessionAccountGroup, index: number) { + const login = account.login; + return ( + + {account.label ? ( + + + {account.label} + + {account.suffix ? ( + {` · ${account.suffix}`} + ) : null} + {account.tags.length > 0 ? renderTags(account.tags, styles.headingTags) : null} + {account.inUse ? IN USE : null} + + ) : account.tags.length > 0 ? ( + renderTags(account.tags, styles.tags) + ) : null} + {account.accountService ? ( + + {account.accountService === "github" ? "GitHub" : `GHE · ${account.accountHost}`} + + ) : null} + {account.quotas.map((quota) => { + const severity = quotaSeverityFromFraction(quota.usedFraction); + const color = severityColor(severity); + const pct = + quota.usedFraction === null ? 0 : Math.min(100, Math.round(quota.usedFraction * 100)); + return ( + + + + {quota.label} + + + {quota.usedFraction === null ? "Unknown" : `${pct}%`} + + + + + + {quotaDetailLabel(quota)} + + ); + })} + {login && !account.inUse ? ( + void switchTo(login)} + style={({ pressed }) => [ + styles.switch, + pressed ? styles.switchPressed : null, + switching !== null ? styles.switchDisabled : null, + ]} + > + + {switching === login.credentialId ? "Switching…" : "Use for this session"} + + + ) : null} + + ); } return ( + {activeLogin ? ( + + THIS SESSION USES + + + {activeAccount?.label ?? activeLogin.label} + + {activeAccount && activeAccount.tags.length > 0 + ? renderTags(activeAccount.tags, styles.tags) + : null} + + {quotaProviderLabel(currentProvider)} + + ) : null} + {sessionAccounts.error ? ( + + {sessionAccounts.error instanceof Error + ? sessionAccounts.error.message + : "Could not read which account this session uses."} + + ) : null} + {switchError ? {switchError} : null} + {session.status === "running" && logins.length > 1 ? ( + Switching takes effect after the current turn finishes. + ) : null} {storeLabel(store)} Last recorded usage from the local agent database, not read live from the provider. - {currentProvider ? ( + {currentProvider && !activeLogin ? ( CURRENT PROVIDER identifies the provider, not the account used by this session. @@ -136,8 +340,14 @@ export function QuotaPopover(props: PluginButtonContentProps) { {`No recorded quota yet for ${quotaProviderLabel(currentProvider)} (this session's provider).`}
) : null} + {groups.length === 0 ? ( + No provider quota data available. + ) : null} {groups.map((group: QuotaProviderGroup) => { const current = group.provider === currentProvider; + const accounts: QuotaSessionAccountGroup[] = current + ? currentAccounts + : group.accounts.map((account) => ({ ...account, login: null, inUse: false })); return ( @@ -149,76 +359,7 @@ export function QuotaPopover(props: PluginButtonContentProps) { {quotaProviderLabel(group.provider)} {current ? "CURRENT PROVIDER" : "RECORDED"} - {group.accounts.map((account) => ( - - {account.label ? ( - - - {account.label} - - {account.suffix ? ( - {` · ${account.suffix}`} - ) : null} - {account.tags.length > 0 ? ( - - {account.tags.map((tag) => ( - - {tag} - - ))} - - ) : null} - - ) : account.tags.length > 0 ? ( - - {account.tags.map((tag) => ( - - {tag} - - ))} - - ) : null} - {account.accountService ? ( - - {account.accountService === "github" - ? "GitHub" - : `GHE · ${account.accountHost}`} - - ) : null} - {account.quotas.map((quota) => { - const severity = quotaSeverityFromFraction(quota.usedFraction); - const color = severityColor(severity); - const pct = - quota.usedFraction === null - ? 0 - : Math.min(100, Math.round(quota.usedFraction * 100)); - return ( - - - - {quota.label} - - - {quota.usedFraction === null ? "Unknown" : `${pct}%`} - - - - - - {quotaDetailLabel(quota)} - - ); - })} - - ))} + {accounts.map(renderAccount)} ); })} diff --git a/paseo-omp/client/quota-state.ts b/paseo-omp/client/quota-state.ts index 3c17d8d2..a1ab7487 100644 --- a/paseo-omp/client/quota-state.ts +++ b/paseo-omp/client/quota-state.ts @@ -1,4 +1,5 @@ -import type { OmpQuota } from "../shared/quota"; +import { accountTags } from "../shared/account-tags"; +import type { OmpQuota, OmpSessionAccount } from "../shared/quota"; import { isOmpProvider } from "./omp-store-state"; const PROVIDER_LABELS: Record = { @@ -145,35 +146,36 @@ export function quotaProviderGroups( return groups; } -const PLAN_LABELS: Record = { - free: "Free", - go: "Go", - plus: "Plus", - pro: "Pro", - prolite: "Pro Lite", - max: "Max", - team: "Team", - business: "Business", - self_serve_business_prolite: "Business", - self_serve_business_usage_based: "Business", - enterprise: "Enterprise", - enterprise_cbp_automation: "Enterprise", - enterprise_cbp_usage_based: "Enterprise", - edu: "Edu", +export type QuotaSessionAccountGroup = QuotaAccountGroup & { + /** The OMP login this usage belongs to, when the session listed it. */ + login: OmpSessionAccount | null; + /** OMP routes this session's requests to this account. */ + inUse: boolean; }; -function accountTags(quotas: readonly OmpQuota[], email: string | null): string[] { - const plan = quotas.find((quota) => quota.plan)?.plan ?? null; - const organization = quotas.find((quota) => quota.organization)?.organization ?? null; - const tags: string[] = []; - if (plan) { - tags.push(PLAN_LABELS[plan.toLowerCase()] ?? plan.charAt(0).toUpperCase() + plan.slice(1)); - } - // Anthropic names a personal account's default organization after its email. - if (organization) { - tags.push(email && organization === `${email}'s Organization` ? "Personal" : organization); - } - return [...new Set(tags)]; +/** Links the current provider's accounts to the session's logins; the one in use sorts first. */ +export function quotaSessionAccounts( + accounts: readonly QuotaAccountGroup[], + logins: readonly OmpSessionAccount[], +): QuotaSessionAccountGroup[] { + const linked = accounts.map((account) => { + const login = logins.find((entry) => entry.quotaAccountKeys.includes(account.accountKey)); + return { ...account, login: login ?? null, inUse: login?.active === true }; + }); + return [...linked.filter((a) => a.inUse), ...linked.filter((a) => !a.inUse)]; +} + +/** OMP's `/session pin` accepts this exact form for any stored OAuth login. */ +export function sessionPinCommand(credentialId: number): string { + return `/session pin OAuth credential #${credentialId}`; +} + +function quotaAccountTags(quotas: readonly OmpQuota[], email: string | null): string[] { + return accountTags({ + plan: quotas.find((quota) => quota.plan)?.plan ?? null, + organization: quotas.find((quota) => quota.organization)?.organization ?? null, + email, + }); } function quotaAccountGroups(quotas: readonly OmpQuota[]): QuotaAccountGroup[] { @@ -198,7 +200,7 @@ function quotaAccountGroups(quotas: readonly OmpQuota[]): QuotaAccountGroup[] { email, accountService: service?.accountService ?? null, accountHost: service?.accountHost ?? null, - tags: accountTags(accountQuotas, email), + tags: quotaAccountTags(accountQuotas, email), label: email ?? accountId, suffix: null, quotas: [...accountQuotas].sort((a, b) => (b.usedFraction ?? -1) - (a.usedFraction ?? -1)), diff --git a/paseo-omp/index.server.ts b/paseo-omp/index.server.ts index cd5c27aa..92b0101a 100644 --- a/paseo-omp/index.server.ts +++ b/paseo-omp/index.server.ts @@ -52,7 +52,7 @@ import { createOmpProvider } from "./server/provider/registration"; import { OmpPublicError } from "./server/provider/security"; import { OmpSessionLimit } from "./server/provider/session-limit"; import { resolveGetOmpProviderHealth } from "./server/provider-diagnostics"; -import { resolveListOmpQuotas } from "./server/quota"; +import { resolveListOmpQuotas, resolveListOmpSessionAccounts } from "./server/quota"; import { ompRuleNoticeRow } from "./server/rule-notices"; import { OmpSubagentControlRegistry, @@ -116,7 +116,7 @@ import { getOmpUpdateStatus, installOmpUpdate } from "./shared/omp-update"; import { getOmpProviderHealth } from "./shared/provider-diagnostics"; import { getOmpImage } from "./shared/provider-image"; import { providerLaunchSettings } from "./shared/provider-launch-settings"; -import { listOmpQuotas } from "./shared/quota"; +import { listOmpQuotas, listOmpSessionAccounts } from "./shared/quota"; import { cancelOmpSubagent, steerOmpSubagent } from "./shared/subagents"; import { getOmpSupportReport } from "./shared/support-diagnostics"; @@ -162,6 +162,9 @@ export default function contribute(server: PluginServerContext) { server.handle(listHubProcesses, resolveListHubProcesses); server.handle(tailHubLog, resolveTailHubLog); server.handle(listOmpQuotas, scoped(resolveListOmpQuotas)); + server.handle(listOmpSessionAccounts, (input) => + resolveListOmpSessionAccounts(input, subagentControlRegistry), + ); server.handle( listOmpAccounts, scoped(({ store, refresh }) => accounts.list(store, refresh ?? false)), diff --git a/paseo-omp/server/omp-accounts.ts b/paseo-omp/server/omp-accounts.ts index 8f95f994..476719ba 100644 --- a/paseo-omp/server/omp-accounts.ts +++ b/paseo-omp/server/omp-accounts.ts @@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto"; import { tmpdir } from "node:os"; import { createInterface } from "node:readline"; import { z } from "zod"; +import { accountTags } from "../shared/account-tags"; import { OMP_ACCOUNTS_SETTING_PATHS, type OmpAccount, @@ -118,7 +119,16 @@ const UsageReportSchema = z.object({ amount: z.object({ usedFraction: UsedFraction.nullish() }).nullish(), }), ).nullish(), - metadata: z.object({ accountId: z.string().nullish(), orgId: z.string().nullish() }).nullish(), + metadata: z + .object({ + accountId: z.string().nullish(), + orgId: z.string().nullish(), + email: z.string().nullish(), + plan: z.string().nullish(), + planType: z.string().nullish(), + orgName: z.string().nullish(), + }) + .nullish(), }); type UsageReport = z.infer; const UsageSchema = z.object({ reports: entries(UsageReportSchema).nullish() }); @@ -578,6 +588,7 @@ export function joinAccounts( credentialId: login.credentialId, oauth: false, label: login.label, + tags: [], limits: [], usageAt: null, usageIsRecorded: false, @@ -608,7 +619,7 @@ export function joinAccounts( provider: login.provider, credentialId: login.credentialId, oauth: true, - label: login.label, + ...labelWithTags(login.label, report), limits: recorded?.limits ?? live, usageAt: recorded?.at ?? report?.fetchedAt ?? null, usageIsRecorded: recorded !== null, @@ -621,6 +632,29 @@ export function joinAccounts( ); } +/** + * Plan and organization badges from the login's usage report. OMP appends the organization to the + * label in parentheses (`email (org)`); once a badge shows it, the suffix only repeats it. + */ +function labelWithTags( + label: string, + report: UsageReport | undefined, +): Pick { + const metadata = report?.metadata; + const orgName = metadata?.orgName?.trim() || null; + const tags = accountTags({ + plan: (metadata?.planType ?? metadata?.plan)?.trim() || null, + organization: orgName, + email: metadata?.email?.trim() || null, + }); + const suffix = orgName ? ` (${orgName})` : null; + return { + label: + tags.length > 0 && suffix && label.endsWith(suffix) ? label.slice(0, -suffix.length) : label, + tags, + }; +} + /** Where new sessions would go right now, by OMP's own balancer. */ async function previewBalance( command: OmpCommand, diff --git a/paseo-omp/server/provider/omp-rpc-protocol.ts b/paseo-omp/server/provider/omp-rpc-protocol.ts index 2d07fdef..77a80ce8 100644 --- a/paseo-omp/server/provider/omp-rpc-protocol.ts +++ b/paseo-omp/server/provider/omp-rpc-protocol.ts @@ -148,7 +148,7 @@ export const OMP_RPC_COMMAND_POLICIES = { cancel_subagent: "implemented", fork: "unsupported", get_btw_history: "unsupported", - get_logout_accounts: "unsupported", + get_logout_accounts: "implemented", goal: "unsupported", live_mute: "unsupported", live_connect: "unsupported", @@ -2003,6 +2003,21 @@ export const OmpSubagentsResultSchema = z.object({ .max(1_024), }); export const OmpCancelSubagentResultSchema = z.object({ cancelled: z.boolean() }); +/** Stored logins of one provider; `active` marks the ones this session may be using. */ +export const OmpLogoutAccountsResultSchema = z.object({ + accounts: z + .array( + z.object({ + credentialId: z.number().int().nonnegative(), + provider: IDENTIFIER, + label: TEXT, + type: z.enum(["api_key", "oauth"]), + active: z.boolean(), + }), + ) + .max(256), +}); +export type OmpLogoutAccount = z.infer["accounts"][number]; export const OmpSteerSubagentResultSchema = z.object({}).strict().optional(); export const OmpSubagentMessagesResultSchema = z.object({ sessionFile: boundedString(MAX_PATH_LENGTH), diff --git a/paseo-omp/server/provider/omp-rpc.ts b/paseo-omp/server/provider/omp-rpc.ts index 47df5b8f..84a49226 100644 --- a/paseo-omp/server/provider/omp-rpc.ts +++ b/paseo-omp/server/provider/omp-rpc.ts @@ -37,6 +37,8 @@ import { type OmpHostToolResult, type OmpHostToolUpdate, type OmpImage, + type OmpLogoutAccount, + OmpLogoutAccountsResultSchema, type OmpMessage, OmpMessageSchema, OmpMessagesPageResultSchema, @@ -121,6 +123,8 @@ export interface OmpRuntimeSession { /** Resolves `false` when OMP no longer lists the subagent as running for this session. */ cancelSubagent(subagentId: string): Promise; steerSubagent(subagentId: string, message: string): Promise; + /** The provider's stored logins; `active` marks the ones this session may be using. */ + getLogoutAccounts(providerId: string): Promise; prompt( message: string, images?: readonly OmpImage[], @@ -561,6 +565,13 @@ class OmpRpcSession implements OmpRuntimeSession { ).cancelled; } + async getLogoutAccounts(providerId: string): Promise { + const safeId = validateBoundedText(providerId, "provider identifier", MAX_ID_LENGTH); + return OmpLogoutAccountsResultSchema.parse( + await this.process.request({ type: "get_logout_accounts", providerId: safeId }), + ).accounts; + } + async steerSubagent(subagentId: string, message: string): Promise { const safeId = validateBoundedText(subagentId, "subagent identifier", MAX_ID_LENGTH); const safeMessage = validateBoundedText(message, "subagent steering message", MAX_TEXT_LENGTH); diff --git a/paseo-omp/server/provider/session.ts b/paseo-omp/server/provider/session.ts index 1c9dc8a9..e92ed081 100644 --- a/paseo-omp/server/provider/session.ts +++ b/paseo-omp/server/provider/session.ts @@ -40,6 +40,7 @@ import type { OmpAvailableCommand, OmpBranchResult, OmpCompactionResult, + OmpLogoutAccount, OmpMessage, OmpModel, OmpRpcEvent, @@ -482,6 +483,12 @@ export class OmpProviderSession implements OmpOpenedSession, OmpSubagentControls await target.runtime.steerSubagent(target.nativeId, message); } + /** The provider's stored logins as this session's runtime sees them; `active` marks its own. */ + async listProviderAccounts(provider: string): Promise { + if (this.closed || this.runtimeDead) throw new OmpPublicError("The OMP session is closed"); + return await this.runtime.getLogoutAccounts(provider); + } + /** * The native ID and runtime of a subagent this session's current runtime lists as running, or * `null`. OMP repeats the check; this scopes the request to this session and answers exactly. diff --git a/paseo-omp/server/quota.ts b/paseo-omp/server/quota.ts index 8a5bfb83..7d51ae1c 100644 --- a/paseo-omp/server/quota.ts +++ b/paseo-omp/server/quota.ts @@ -1,10 +1,14 @@ import { createHash } from "node:crypto"; import { join } from "node:path"; import { DatabaseSync } from "node:sqlite"; -import type { RpcInput } from "@getpaseo/plugin"; +import type { RpcInput, RpcOutput } from "@getpaseo/plugin"; import { z } from "zod"; -import type { listOmpQuotas, OmpQuota } from "../shared/quota"; +import type { listOmpQuotas, listOmpSessionAccounts, OmpQuota } from "../shared/quota"; import { ompDataDir } from "./paths"; +import type { OmpLogoutAccount } from "./provider/omp-rpc-protocol"; +import { OmpRpcRequestRejectedError } from "./provider/omp-rpc-transport"; +import { isOmpPublicError, OmpPublicError } from "./provider/security"; +import type { OmpSubagentControlRegistry } from "./subagents"; const QuotaRowSchema = z.object({ provider: z.string(), @@ -171,9 +175,126 @@ export function listOmpQuotasFrom(path: string, now = Date.now()): OmpQuota[] { return []; } } - export function resolveListOmpQuotas(_input: RpcInput): { quotas: OmpQuota[]; } { - return { quotas: listOmpQuotasFrom(join(ompDataDir(), "agent.db")) }; + return { quotas: listOmpQuotasFrom(defaultDatabasePath()) }; +} + +function defaultDatabasePath(): string { + return join(ompDataDir(), "agent.db"); +} + +function hashAccountKey(accountKey: string): string { + return createHash("sha256").update(accountKey).digest("hex"); +} + +type LoginIdentity = { email: string | null; accountId: string | null; orgId: string | null }; + +/** OMP's usage_history account_key is `oauth|account:|email:|org:`. */ +function usageKeyIdentity(accountKey: string): LoginIdentity { + const parts = new Map(); + for (const part of accountKey.split("|")) { + const colon = part.indexOf(":"); + if (colon > 0) parts.set(part.slice(0, colon), part.slice(colon + 1)); + } + return { + email: parts.get("email") || null, + accountId: parts.get("account") || null, + orgId: parts.get("org") || null, + }; +} + +/** OMP's own rule: differing orgs never match, an email on both sides decides, else the account id. */ +function sameLogin(login: LoginIdentity, usage: LoginIdentity): boolean { + if (login.orgId && usage.orgId && login.orgId !== usage.orgId) return false; + if (login.email && usage.email) return login.email.toLowerCase() === usage.email.toLowerCase(); + return login.accountId !== null && login.accountId === usage.accountId; +} + +/** + * The usage accounts recorded for each login. Only identity fields leave the credential row; a + * provider with one login and one usage account needs none (Copilot keys hold only a fingerprint). + */ +export function quotaAccountKeysFor( + path: string, + provider: string, + credentialIds: readonly number[], +): Map { + const matched = new Map(credentialIds.map((id) => [id, []])); + if (credentialIds.length === 0) return matched; + try { + const database = new DatabaseSync(path, { readOnly: true, timeout: 500 }); + try { + const usageKeys = database + .prepare("SELECT DISTINCT account_key AS accountKey FROM usage_history WHERE provider = ?") + .all(provider) + .flatMap(({ accountKey }) => (typeof accountKey === "string" ? [accountKey] : [])); + if (credentialIds.length === 1 && usageKeys.length === 1) { + matched.set(credentialIds[0], [hashAccountKey(usageKeys[0])]); + return matched; + } + const rows = database + .prepare( + `SELECT id, json_extract(data, '$.email') AS email, + json_extract(data, '$.accountId') AS accountId, + json_extract(data, '$.orgId') AS orgId + FROM auth_credentials WHERE id IN (${credentialIds.map(() => "?").join(", ")})`, + ) + .all(...credentialIds); + for (const row of rows) { + if (typeof row.id !== "number") continue; + const text = (value: unknown) => (typeof value === "string" && value.trim()) || null; + const login = { + email: text(row.email), + accountId: text(row.accountId), + orgId: text(row.orgId), + }; + if (!login.email && !login.accountId) continue; + matched.set( + row.id, + usageKeys.filter((key) => sameLogin(login, usageKeyIdentity(key))).map(hashAccountKey), + ); + } + } finally { + database.close(); + } + } catch { + // An unreadable database only loses the link between logins and their recorded usage. + } + return matched; +} + +export async function resolveListOmpSessionAccounts( + input: RpcInput, + registry: OmpSubagentControlRegistry, + databasePath = defaultDatabasePath(), +): Promise> { + const controls = registry.get(input.agentId); + if (!controls) throw new OmpPublicError("This agent has no running OMP Plugin session"); + let logins: OmpLogoutAccount[]; + try { + logins = await controls.listProviderAccounts(input.provider); + } catch (error) { + if (isOmpPublicError(error)) throw error; + if (error instanceof OmpRpcRequestRejectedError && error.code === "unsupported_command") { + throw new OmpPublicError("Update OMP to show which login this session uses"); + } + // Native OMP error text is never forwarded. + throw new OmpPublicError("OMP could not list this session's logins"); + } + const oauth = logins.filter((login) => login.type === "oauth"); + const keys = quotaAccountKeysFor( + databasePath, + input.provider, + oauth.map((login) => login.credentialId), + ); + return { + accounts: oauth.map((login) => ({ + credentialId: login.credentialId, + label: login.label, + active: login.active, + quotaAccountKeys: keys.get(login.credentialId) ?? [], + })), + }; } diff --git a/paseo-omp/server/subagents.ts b/paseo-omp/server/subagents.ts index 5d15e1ad..ce427328 100644 --- a/paseo-omp/server/subagents.ts +++ b/paseo-omp/server/subagents.ts @@ -1,13 +1,16 @@ import type { RpcInput, RpcOutput } from "@getpaseo/plugin"; import type { cancelOmpSubagent, steerOmpSubagent } from "../shared/subagents"; +import type { OmpLogoutAccount } from "./provider/omp-rpc-protocol"; import { OmpRpcRequestRejectedError } from "./provider/omp-rpc-transport"; import { isOmpPublicError, OmpPublicError } from "./provider/security"; -/** Subagent controls of one live OMP session; history-only sessions never register. */ +/** Controls of one live OMP session; history-only sessions never register. */ export interface OmpSubagentControls { /** Resolves `false` when the subagent is no longer running. */ cancelSubagent(handle: string): Promise; steerSubagent(handle: string, message: string): Promise; + /** The provider's stored logins; `active` marks the ones this session may be using. */ + listProviderAccounts(provider: string): Promise; } export class OmpSubagentNotRunningError extends OmpPublicError { diff --git a/paseo-omp/shared/account-tags.ts b/paseo-omp/shared/account-tags.ts new file mode 100644 index 00000000..4bf5ada0 --- /dev/null +++ b/paseo-omp/shared/account-tags.ts @@ -0,0 +1,38 @@ +const PLAN_LABELS: Record = { + free: "Free", + go: "Go", + plus: "Plus", + pro: "Pro", + prolite: "Pro Lite", + max: "Max", + team: "Team", + business: "Business", + self_serve_business_prolite: "Business", + self_serve_business_usage_based: "Business", + enterprise: "Enterprise", + enterprise_cbp_automation: "Enterprise", + enterprise_cbp_usage_based: "Enterprise", + edu: "Edu", +}; + +/** + * Plan and organization badges for one login, e.g. ["Business", "Sec Tech Team"] or ["Personal"]. + * `plan` is the raw plan OMP's usage report names (Codex `planType`, Copilot `plan`). + */ +export function accountTags(input: { + plan: string | null; + organization: string | null; + email: string | null; +}): string[] { + const { plan, organization, email } = input; + const tags: string[] = []; + if (plan) { + tags.push(PLAN_LABELS[plan.toLowerCase()] ?? plan.charAt(0).toUpperCase() + plan.slice(1)); + } + // Codex reports its plan as the organization name too; that is not an organization. + if (organization && organization.toLowerCase() !== plan?.toLowerCase()) { + // Anthropic names a personal account's default organization after its email. + tags.push(email && organization === `${email}'s Organization` ? "Personal" : organization); + } + return [...new Set(tags)]; +} diff --git a/paseo-omp/shared/omp-accounts.ts b/paseo-omp/shared/omp-accounts.ts index 208ec274..f0f3732c 100644 --- a/paseo-omp/shared/omp-accounts.ts +++ b/paseo-omp/shared/omp-accounts.ts @@ -46,6 +46,8 @@ export const OmpAccountSchema = z.object({ /** OAuth logins have usage and resets; API keys have neither. */ oauth: z.boolean(), label: z.string(), + /** Plan and organization badges from OMP's usage report, e.g. "Business" or "Personal". */ + tags: z.array(z.string()), limits: z.array(OmpAccountLimitSchema), /** When OMP read the limits shown (epoch ms); null when it has no reading for this login. */ usageAt: z.number().int().nullable(), diff --git a/paseo-omp/shared/quota.ts b/paseo-omp/shared/quota.ts index 23f6f5e0..6caa3628 100644 --- a/paseo-omp/shared/quota.ts +++ b/paseo-omp/shared/quota.ts @@ -34,3 +34,27 @@ export const listOmpQuotas = defineRpc({ input: z.object({ store: OmpStoreSchema.optional() }), output: z.object({ quotas: z.array(OmpQuotaSchema) }), }); + +export const OmpSessionAccountSchema = z.object({ + /** OMP's credential id; `/session pin OAuth credential #` selects this login. */ + credentialId: z.number().int().nonnegative(), + label: z.string(), + /** OMP routes this session's requests to this login. */ + active: z.boolean(), + /** `OmpQuota.accountKey` values recorded for this login. */ + quotaAccountKeys: z.array(z.string()), +}); +export type OmpSessionAccount = z.infer; + +/** OAuth logins of the agent's current provider, as its live OMP session sees them. */ +export const listOmpSessionAccounts = defineRpc({ + name: "paseo-omp.list-session-accounts", + input: z.object({ + agentId: z.string().min(1).max(256), + provider: z + .string() + .regex(/^[a-z0-9][a-z0-9.-]*$/u) + .max(128), + }), + output: z.object({ accounts: z.array(OmpSessionAccountSchema) }), +}); diff --git a/paseo-omp/tests/helpers/provider-harness.ts b/paseo-omp/tests/helpers/provider-harness.ts index 26f2625d..50a22a6e 100644 --- a/paseo-omp/tests/helpers/provider-harness.ts +++ b/paseo-omp/tests/helpers/provider-harness.ts @@ -22,6 +22,7 @@ import type { OmpHostToolResult, OmpHostToolUpdate, OmpImage, + OmpLogoutAccount, OmpMessage, OmpModel, OmpPersistedSessionMessages, @@ -563,6 +564,12 @@ export class FakeOmpSession implements OmpRuntimeSession { if (this.subagentControlError) throw this.subagentControlError; } + logoutAccounts: OmpLogoutAccount[] = []; + + async getLogoutAccounts(_providerId: string) { + return this.logoutAccounts; + } + getSubagentMessages(selector: { subagentId?: string; sessionFile?: string }) { this.subagentMessageRequests.push(selector); const key = selector.subagentId ?? selector.sessionFile; diff --git a/paseo-omp/tests/omp-accounts-state.test.ts b/paseo-omp/tests/omp-accounts-state.test.ts index 889e4533..384a591d 100644 --- a/paseo-omp/tests/omp-accounts-state.test.ts +++ b/paseo-omp/tests/omp-accounts-state.test.ts @@ -15,6 +15,7 @@ function account(provider: string, credentialId: number): OmpAccount { credentialId, oauth: true, label: `${provider}-${credentialId}`, + tags: [], limits: [], usageAt: null, usageIsRecorded: false, diff --git a/paseo-omp/tests/omp-accounts.test.ts b/paseo-omp/tests/omp-accounts.test.ts index 54c266de..55faf660 100644 --- a/paseo-omp/tests/omp-accounts.test.ts +++ b/paseo-omp/tests/omp-accounts.test.ts @@ -335,6 +335,56 @@ describe.skipIf(ON_WINDOWS)("listing", () => { expect(usedBy(4)).toBe(0.9); }); + test("tags each login with its plan and organization instead of repeating it in the label", async () => { + const view = await ( + await install({ + usage: { + reports: [ + { + provider: "anthropic", + fetchedAt: NOW, + limits: [limit("anthropic:5h", 0.25)], + metadata: { + accountId: "acc-a", + email: "a@example.test", + orgName: "Org A", + }, + }, + { + provider: "anthropic", + fetchedAt: NOW, + limits: [limit("anthropic:5h", 0.9)], + metadata: { + accountId: "acc-b", + email: "b@example.test", + orgName: "b@example.test's Organization", + }, + }, + { + provider: "openai-codex", + fetchedAt: NOW, + limits: [limit("openai-codex:5h", 0.1)], + metadata: { + accountId: "acc-c", + planType: "self_serve_business_prolite", + orgName: "self_serve_business_prolite", + }, + }, + ], + }, + }) + ).list(undefined, false); + const shown = view.accounts.map(({ label, tags }) => ({ label, tags })); + + expect(shown).toEqual([ + { label: "a@example.test", tags: ["Org A"] }, + // OMP's label names Org B, but the report says this login is the personal organization. + { label: "b@example.test (Org B)", tags: ["Personal"] }, + { label: "c@example.test", tags: ["Business"] }, + { label: "key", tags: [] }, + ]); + }); + test("does not guess between same-provider logins it cannot tell apart", async () => { const accounts = await install({ resets: { accounts: [] }, diff --git a/paseo-omp/tests/provider-subagent-control.test.ts b/paseo-omp/tests/provider-subagent-control.test.ts index a3189586..b5d0fd0b 100644 --- a/paseo-omp/tests/provider-subagent-control.test.ts +++ b/paseo-omp/tests/provider-subagent-control.test.ts @@ -456,6 +456,7 @@ describe("OMP subagent controls", () => { const controls = (): OmpSubagentControls => ({ cancelSubagent: async () => false, steerSubagent: async () => {}, + listProviderAccounts: async () => [], }); const older = controls(); const newer = controls(); diff --git a/paseo-omp/tests/quota-popover.test.tsx b/paseo-omp/tests/quota-popover.test.tsx index 6a0efff2..05b5c5e3 100644 --- a/paseo-omp/tests/quota-popover.test.tsx +++ b/paseo-omp/tests/quota-popover.test.tsx @@ -4,17 +4,38 @@ import { act, type ReactNode } from "react"; import { createRoot, type Root } from "react-dom/client"; import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; import { QuotaPopover } from "../client/quota-popover"; -import type { OmpQuota } from "../shared/quota"; +import type { OmpQuota, OmpSessionAccount } from "../shared/quota"; -const recorded = vi.hoisted(() => ({ quotas: [] as OmpQuota[] })); +const recorded = vi.hoisted(() => ({ + quotas: [] as OmpQuota[], + logins: [] as OmpSessionAccount[], + sent: [] as Array<{ agentId: string; text: string }>, +})); vi.mock("@getpaseo/plugin/client", () => ({ - useAgent: () => ({ provider: "omp", model: "anthropic/example" }), + useAgent: () => ({ provider: "omp", model: "anthropic/example", status: "idle" }), useRpc: () => vi.fn(), + usePaseo: () => ({ + agents: { + ref: (agentId: string) => ({ + send: async (text: string) => { + recorded.sent.push({ agentId, text }); + }, + }), + }, + }), })); vi.mock("@getpaseo/plugin/client/ui", () => ({ Icon: () => null })); vi.mock("@tanstack/react-query", () => ({ - useQuery: () => ({ data: recorded, isLoading: false, error: null }), + useQuery: (options: { queryKey: readonly unknown[] }) => ({ + data: + options.queryKey[1] === "session-accounts" + ? { accounts: recorded.logins } + : { quotas: recorded.quotas }, + isLoading: false, + error: null, + }), + useQueryClient: () => ({ invalidateQueries: async () => {} }), })); vi.mock("react-native", () => ({ View: (props: { @@ -31,6 +52,15 @@ vi.mock("react-native", () => ({ ), Text: (props: { children?: ReactNode }) => {props.children}, + Pressable: (props: { + children?: ReactNode; + accessibilityLabel?: string; + onPress?: () => void; + }) => ( + + ), })); const props: PluginButtonContentProps = { @@ -83,6 +113,8 @@ let root: Root; beforeEach(() => { vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); recorded.quotas = []; + recorded.logins = []; + recorded.sent = []; container = document.createElement("div"); document.body.append(container); root = createRoot(container); @@ -164,4 +196,34 @@ describe("quota popover reconciliation", () => { "same@example.invalid · Business · Example Team", ); }); + + test("shows the account this session uses on top and switches to another on request", async () => { + recorded.logins = [ + { credentialId: 3, label: "same@example.invalid", active: false, quotaAccountKeys: ["a"] }, + { credentialId: 5, label: "other", active: true, quotaAccountKeys: ["b"] }, + ]; + await render([ + quota("a", "weekly", 0.9), + { ...quota("b", "weekly", 0.2), email: "b@x.invalid" }, + ]); + + const banner = container.querySelector('[data-accessibility-label="This session uses other"]'); + expect(banner?.textContent).toContain("b@x.invalid"); + const inUse = heading("b@x.invalid"); + expect(inUse.contains(text("IN USE"))).toBe(true); + // The account in use leads its provider even though the other one has more usage. + expect( + inUse.compareDocumentPosition(heading("same@example.invalid")) & + Node.DOCUMENT_POSITION_FOLLOWING, + ).toBeTruthy(); + expect(container.querySelector('[aria-label="Use b@x.invalid for this session"]')).toBeNull(); + + const button = container.querySelector( + '[aria-label="Use same@example.invalid for this session"]', + ) as HTMLButtonElement; + await act(async () => button.click()); + expect(recorded.sent).toEqual([ + { agentId: "synthetic-agent", text: "/session pin OAuth credential #3" }, + ]); + }); }); diff --git a/paseo-omp/tests/quota-state.test.ts b/paseo-omp/tests/quota-state.test.ts index 04d48b8e..55d9ef5a 100644 --- a/paseo-omp/tests/quota-state.test.ts +++ b/paseo-omp/tests/quota-state.test.ts @@ -1,3 +1,4 @@ +import { createHash } from "node:crypto"; import { mkdtemp, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -10,11 +11,19 @@ import { quotaProviderIconName, quotaRecordedLabel, quotaResetLabel, + quotaSessionAccounts, quotaSeverityForProvider, quotaSummaryForProvider, quotasForProvider, + sessionPinCommand, } from "../client/quota-state"; -import { listOmpQuotasFrom, resolveListOmpQuotas } from "../server/quota"; +import { OmpRpcRequestRejectedError } from "../server/provider/omp-rpc-transport"; +import { + listOmpQuotasFrom, + resolveListOmpQuotas, + resolveListOmpSessionAccounts, +} from "../server/quota"; +import { OmpSubagentControlRegistry, type OmpSubagentControls } from "../server/subagents"; import type { OmpQuota } from "../shared/quota"; const quotaRoots: string[] = []; @@ -743,6 +752,117 @@ describe("OMP quota reader", () => { }); }); +describe("session account", () => { + const sha = (value: string) => createHash("sha256").update(value).digest("hex"); + const teamA = "oauth|account:team|email:a@example.invalid|org:team"; + const teamB = "oauth|account:team|email:b@example.invalid|org:team"; + const personal = "oauth|account:me|email:a@example.invalid|org:mine"; + + async function database(): Promise { + const root = await mkdtemp(join(tmpdir(), "paseo-omp-session-accounts-")); + quotaRoots.push(root); + const path = join(root, "agent.db"); + const db = new DatabaseSync(path); + db.exec(`CREATE TABLE usage_history (provider TEXT, account_key TEXT); + CREATE TABLE auth_credentials (id INTEGER PRIMARY KEY, provider TEXT, data TEXT)`); + const usage = db.prepare("INSERT INTO usage_history VALUES ('openai-codex', ?)"); + for (const key of [teamA, teamB, personal]) usage.run(key); + const credential = db.prepare("INSERT INTO auth_credentials VALUES (?, 'openai-codex', ?)"); + const data = (email: string, accountId: string, orgId: string) => + JSON.stringify({ email, accountId, orgId, access: "secret-token" }); + credential.run(1, data("a@example.invalid", "team", "team")); + credential.run(2, data("b@example.invalid", "team", "team")); + credential.run(3, data("a@example.invalid", "me", "mine")); + db.close(); + return path; + } + + function registryWith(controls: Partial): OmpSubagentControlRegistry { + const registry = new OmpSubagentControlRegistry(); + registry.register("agent-1", { + cancelSubagent: async () => false, + steerSubagent: async () => {}, + listProviderAccounts: async () => [], + ...controls, + }); + return registry; + } + + test("links each login to its own usage when team seats share an account id and emails repeat across orgs", async () => { + const login = (credentialId: number, active = false) => ({ + credentialId, + provider: "openai-codex", + label: `login ${credentialId}`, + type: "oauth" as const, + active, + }); + const registry = registryWith({ + listProviderAccounts: async () => [ + login(2, true), + login(1), + login(3), + { ...login(9), type: "api_key" }, + ], + }); + + const result = await resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "openai-codex" }, + registry, + await database(), + ); + + expect(result.accounts).toEqual([ + { credentialId: 2, label: "login 2", active: true, quotaAccountKeys: [sha(teamB)] }, + { credentialId: 1, label: "login 1", active: false, quotaAccountKeys: [sha(teamA)] }, + { credentialId: 3, label: "login 3", active: false, quotaAccountKeys: [sha(personal)] }, + ]); + }); + + test("explains an OMP too old to list logins and an agent without a live session", async () => { + const path = await database(); + const outdated = registryWith({ + listProviderAccounts: async () => { + throw new OmpRpcRequestRejectedError(undefined, "unsupported_command"); + }, + }); + + await expect( + resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "openai-codex" }, + outdated, + path, + ), + ).rejects.toThrow("Update OMP to show which login this session uses"); + await expect( + resolveListOmpSessionAccounts({ agentId: "other", provider: "openai-codex" }, outdated, path), + ).rejects.toThrow("This agent has no running OMP Plugin session"); + }); + + test("puts the account in use first and builds the pin command OMP accepts", () => { + const groups = quotaProviderGroups( + [ + { ...quotas[0], accountKey: "busy", usedFraction: 0.9 }, + { ...quotas[0], accountKey: "idle", usedFraction: 0.1 }, + { ...quotas[0], accountKey: "unlinked", usedFraction: 0.5 }, + ], + "anthropic", + ); + const linked = quotaSessionAccounts(groups[0].accounts, [ + { credentialId: 4, label: "busy", active: false, quotaAccountKeys: ["busy"] }, + { credentialId: 7, label: "idle", active: true, quotaAccountKeys: ["idle"] }, + ]); + + expect( + linked.map(({ accountKey, inUse, login }) => [accountKey, inUse, login?.credentialId]), + ).toEqual([ + ["idle", true, 7], + ["busy", false, 4], + ["unlinked", false, undefined], + ]); + expect(sessionPinCommand(4)).toBe("/session pin OAuth credential #4"); + }); +}); + describe("profile alias and opaque-model quotas", () => { test("recognizes native and profile plugin model providers without guessing opaque ids", () => { expect(quotaProviderFromSession("omp-plugin", "anthropic/claude-fable-5")).toBe("anthropic"); From 5cabeec5e02ec6f2491c8be61dd3b9532ad2cfc5 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 17:16:51 +0900 Subject: [PATCH 05/18] fix(paseo-omp): name the session's account for bundled omp agents instead of failing - Without a live OMP Plugin runtime, read the pin OMP recorded for the agent's stored session id (session:sticky::). - Stop surfacing the host-wrapped 'no running OMP Plugin session' error in the quota popover. --- paseo-omp/README.md | 2 +- paseo-omp/client/quota-popover.tsx | 7 +- paseo-omp/index.server.ts | 10 ++- paseo-omp/server/quota.ts | 121 +++++++++++++++++++++++++--- paseo-omp/tests/quota-state.test.ts | 82 ++++++++++++++++--- 5 files changed, 187 insertions(+), 35 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 35862d7f..1a3562e5 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Each login shows plan and organization badges from its usage report, such as **Business**, **Pro Lite**, **Personal** or an organization name, and the label drops OMP's parenthesized organization once a badge shows it. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. For a live OMP Plugin session, the popover asks the session's OMP runtime (`get_logout_accounts`) which login it uses: **THIS SESSION USES** at the top names it, its account leads the current provider marked **IN USE**, and **Use for this session** on another linked login sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login links to recorded usage by OMP's identity rule (organization, then email, then account id); a provider with one login and one usage account links without one. Without a live session, or on an OMP that cannot list logins, **CURRENT PROVIDER** identifies only the session's provider. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover names the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). **THIS SESSION USES** at the top names that login, its account leads the current provider marked **IN USE**, and **Use for this session** on another linked login sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login links to recorded usage by OMP's identity rule (organization, then email, then account id); a provider with one login and one usage account links without one. A session that has not yet sent a request to the provider has no recorded pin; its logins are still listed for switching and **CURRENT PROVIDER** identifies only the provider. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index 2d004da5..e166e62c 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -316,11 +316,8 @@ export function QuotaPopover(props: PluginButtonContentProps) { ) : null} {sessionAccounts.error ? ( - - {sessionAccounts.error instanceof Error - ? sessionAccounts.error.message - : "Could not read which account this session uses."} - + // The host wraps handler errors in transport details; only a short notice belongs here. + Could not read which account this session uses. ) : null} {switchError ? {switchError} : null} {session.status === "running" && logins.length > 1 ? ( diff --git a/paseo-omp/index.server.ts b/paseo-omp/index.server.ts index 92b0101a..5ffa1ef4 100644 --- a/paseo-omp/index.server.ts +++ b/paseo-omp/index.server.ts @@ -52,7 +52,11 @@ import { createOmpProvider } from "./server/provider/registration"; import { OmpPublicError } from "./server/provider/security"; import { OmpSessionLimit } from "./server/provider/session-limit"; import { resolveGetOmpProviderHealth } from "./server/provider-diagnostics"; -import { resolveListOmpQuotas, resolveListOmpSessionAccounts } from "./server/quota"; +import { + resolveListOmpQuotas, + resolveListOmpSessionAccounts, + sessionIdFromPaseo, +} from "./server/quota"; import { ompRuleNoticeRow } from "./server/rule-notices"; import { OmpSubagentControlRegistry, @@ -162,8 +166,8 @@ export default function contribute(server: PluginServerContext) { server.handle(listHubProcesses, resolveListHubProcesses); server.handle(tailHubLog, resolveTailHubLog); server.handle(listOmpQuotas, scoped(resolveListOmpQuotas)); - server.handle(listOmpSessionAccounts, (input) => - resolveListOmpSessionAccounts(input, subagentControlRegistry), + server.handle(listOmpSessionAccounts, (input, { paseo }) => + resolveListOmpSessionAccounts(input, subagentControlRegistry, sessionIdFromPaseo(paseo)), ); server.handle( listOmpAccounts, diff --git a/paseo-omp/server/quota.ts b/paseo-omp/server/quota.ts index 7d51ae1c..4e68186b 100644 --- a/paseo-omp/server/quota.ts +++ b/paseo-omp/server/quota.ts @@ -2,6 +2,7 @@ import { createHash } from "node:crypto"; import { join } from "node:path"; import { DatabaseSync } from "node:sqlite"; import type { RpcInput, RpcOutput } from "@getpaseo/plugin"; +import type { PluginHandlerContext } from "@getpaseo/plugin/server"; import { z } from "zod"; import type { listOmpQuotas, listOmpSessionAccounts, OmpQuota } from "../shared/quota"; import { ompDataDir } from "./paths"; @@ -265,24 +266,91 @@ export function quotaAccountKeysFor( return matched; } +/** Finds the OMP session id Paseo stored for an agent; null when the agent has none. */ +export type OmpSessionIdLookup = (agentId: string) => Promise; + +/** Paseo's bundled `omp` provider and this plugin's providers both persist OMP's session id. */ +export function sessionIdFromPaseo(paseo: PluginHandlerContext["paseo"]): OmpSessionIdLookup { + return async (agentId) => { + try { + const persistence = (await paseo.agents.ref(agentId).refresh())?.agent.persistence; + if (!persistence || !/^omp(-|$)/u.test(persistence.provider)) return null; + return persistence.sessionId || null; + } catch { + return null; + } + }; +} + +const StickySchema = z.object({ type: z.string(), credentialId: z.number().int() }); + +/** + * The provider's stored OAuth logins with the one OMP pinned to `sessionId` marked active. OMP + * persists that pin as `session:sticky::` for 30 days past its last use; a + * session that never sent a request to the provider has none. Only identity fields are read. + */ +export function storedSessionLogins( + path: string, + provider: string, + sessionId: string, + nowSec = Math.floor(Date.now() / 1000), +): OmpLogoutAccount[] { + try { + const database = new DatabaseSync(path, { readOnly: true, timeout: 500 }); + try { + const sticky = database + .prepare("SELECT value FROM cache WHERE key = ? AND expires_at > ?") + .get(`session:sticky:${provider}:${sessionId}`, nowSec); + let active: number | null = null; + if (typeof sticky?.value === "string") { + try { + const parsed = StickySchema.safeParse(JSON.parse(sticky.value)); + if (parsed.success && parsed.data.type === "oauth") active = parsed.data.credentialId; + } catch { + // An unreadable pin only loses the active marker. + } + } + const text = (value: unknown) => (typeof value === "string" && value.trim()) || null; + return database + .prepare( + `SELECT id, json_extract(data, '$.email') AS email, + json_extract(data, '$.accountId') AS accountId, + json_extract(data, '$.orgName') AS orgName + FROM auth_credentials + WHERE provider = ? AND credential_type = 'oauth' AND disabled_cause IS NULL + ORDER BY id`, + ) + .all(provider) + .flatMap((row) => { + if (typeof row.id !== "number") return []; + // OMP's own label: the email or account id, then the organization in parentheses. + const base = text(row.email) ?? text(row.accountId) ?? `OAuth credential #${row.id}`; + const org = text(row.orgName); + return [ + { + credentialId: row.id, + provider, + label: org && org !== base ? `${base} (${org})` : base, + type: "oauth" as const, + active: row.id === active, + }, + ]; + }); + } finally { + database.close(); + } + } catch { + return []; + } +} + export async function resolveListOmpSessionAccounts( input: RpcInput, registry: OmpSubagentControlRegistry, + findSessionId: OmpSessionIdLookup, databasePath = defaultDatabasePath(), ): Promise> { - const controls = registry.get(input.agentId); - if (!controls) throw new OmpPublicError("This agent has no running OMP Plugin session"); - let logins: OmpLogoutAccount[]; - try { - logins = await controls.listProviderAccounts(input.provider); - } catch (error) { - if (isOmpPublicError(error)) throw error; - if (error instanceof OmpRpcRequestRejectedError && error.code === "unsupported_command") { - throw new OmpPublicError("Update OMP to show which login this session uses"); - } - // Native OMP error text is never forwarded. - throw new OmpPublicError("OMP could not list this session's logins"); - } + const logins = await sessionLogins(input, registry, findSessionId, databasePath); const oauth = logins.filter((login) => login.type === "oauth"); const keys = quotaAccountKeysFor( databasePath, @@ -298,3 +366,30 @@ export async function resolveListOmpSessionAccounts( })), }; } + +/** + * A live OMP Plugin session answers itself. Any other OMP session (Paseo's bundled `omp` provider, + * or a plugin session not open in this daemon) falls back to the pin OMP recorded for it. + */ +async function sessionLogins( + input: RpcInput, + registry: OmpSubagentControlRegistry, + findSessionId: OmpSessionIdLookup, + databasePath: string, +): Promise { + const controls = registry.get(input.agentId); + if (!controls) { + const sessionId = await findSessionId(input.agentId); + return sessionId ? storedSessionLogins(databasePath, input.provider, sessionId) : []; + } + try { + return await controls.listProviderAccounts(input.provider); + } catch (error) { + if (isOmpPublicError(error)) throw error; + if (error instanceof OmpRpcRequestRejectedError && error.code === "unsupported_command") { + throw new OmpPublicError("Update OMP to show which login this session uses"); + } + // Native OMP error text is never forwarded. + throw new OmpPublicError("OMP could not list this session's logins"); + } +} diff --git a/paseo-omp/tests/quota-state.test.ts b/paseo-omp/tests/quota-state.test.ts index 55d9ef5a..8304daca 100644 --- a/paseo-omp/tests/quota-state.test.ts +++ b/paseo-omp/tests/quota-state.test.ts @@ -764,19 +764,38 @@ describe("session account", () => { const path = join(root, "agent.db"); const db = new DatabaseSync(path); db.exec(`CREATE TABLE usage_history (provider TEXT, account_key TEXT); - CREATE TABLE auth_credentials (id INTEGER PRIMARY KEY, provider TEXT, data TEXT)`); + CREATE TABLE auth_credentials (id INTEGER PRIMARY KEY, provider TEXT, + credential_type TEXT, data TEXT, disabled_cause TEXT); + CREATE TABLE cache (key TEXT PRIMARY KEY, value TEXT, expires_at INTEGER)`); const usage = db.prepare("INSERT INTO usage_history VALUES ('openai-codex', ?)"); for (const key of [teamA, teamB, personal]) usage.run(key); - const credential = db.prepare("INSERT INTO auth_credentials VALUES (?, 'openai-codex', ?)"); - const data = (email: string, accountId: string, orgId: string) => - JSON.stringify({ email, accountId, orgId, access: "secret-token" }); - credential.run(1, data("a@example.invalid", "team", "team")); - credential.run(2, data("b@example.invalid", "team", "team")); - credential.run(3, data("a@example.invalid", "me", "mine")); + const credential = db.prepare( + "INSERT INTO auth_credentials VALUES (?, 'openai-codex', 'oauth', ?, ?)", + ); + const data = (email: string, accountId: string, orgId: string, orgName: string) => + JSON.stringify({ email, accountId, orgId, orgName, access: "secret-token" }); + credential.run(1, data("a@example.invalid", "team", "team", "Team"), null); + credential.run(2, data("b@example.invalid", "team", "team", "Team"), null); + credential.run(3, data("a@example.invalid", "me", "mine", "a@example.invalid"), null); + credential.run(4, data("gone@example.invalid", "x", "x", "X"), "user"); + const pin = db.prepare("INSERT INTO cache VALUES (?, ?, ?)"); + const future = Math.floor(Date.now() / 1000) + 3_600; + pin.run( + "session:sticky:openai-codex:bundled-session", + JSON.stringify({ type: "oauth", index: 1, credentialId: 2, lastUsedAtMs: 1 }), + future, + ); + pin.run( + "session:sticky:openai-codex:expired-session", + JSON.stringify({ type: "oauth", index: 0, credentialId: 1, lastUsedAtMs: 1 }), + 1, + ); db.close(); return path; } + const noSession = async () => null; + function registryWith(controls: Partial): OmpSubagentControlRegistry { const registry = new OmpSubagentControlRegistry(); registry.register("agent-1", { @@ -808,6 +827,7 @@ describe("session account", () => { const result = await resolveListOmpSessionAccounts( { agentId: "agent-1", provider: "openai-codex" }, registry, + noSession, await database(), ); @@ -818,8 +838,7 @@ describe("session account", () => { ]); }); - test("explains an OMP too old to list logins and an agent without a live session", async () => { - const path = await database(); + test("explains an OMP too old to list logins", async () => { const outdated = registryWith({ listProviderAccounts: async () => { throw new OmpRpcRequestRejectedError(undefined, "unsupported_command"); @@ -830,12 +849,49 @@ describe("session account", () => { resolveListOmpSessionAccounts( { agentId: "agent-1", provider: "openai-codex" }, outdated, - path, + noSession, + await database(), ), ).rejects.toThrow("Update OMP to show which login this session uses"); - await expect( - resolveListOmpSessionAccounts({ agentId: "other", provider: "openai-codex" }, outdated, path), - ).rejects.toThrow("This agent has no running OMP Plugin session"); + }); + + test("reads the pin OMP recorded for a session no OMP Plugin runtime owns, such as Paseo's bundled omp", async () => { + const path = await database(); + const empty = new OmpSubagentControlRegistry(); + const forSession = (sessionId: string | null) => async (agentId: string) => + agentId === "bundled-agent" ? sessionId : null; + const list = (sessionId: string | null) => + resolveListOmpSessionAccounts( + { agentId: "bundled-agent", provider: "openai-codex" }, + empty, + forSession(sessionId), + path, + ); + + expect((await list("bundled-session")).accounts).toEqual([ + { + credentialId: 1, + label: "a@example.invalid (Team)", + active: false, + quotaAccountKeys: [sha(teamA)], + }, + { + credentialId: 2, + label: "b@example.invalid (Team)", + active: true, + quotaAccountKeys: [sha(teamB)], + }, + { + credentialId: 3, + label: "a@example.invalid", + active: false, + quotaAccountKeys: [sha(personal)], + }, + ]); + // An expired pin marks nothing; the logins stay switchable. + expect((await list("expired-session")).accounts.some((login) => login.active)).toBe(false); + // No stored session at all is not an error: the popover simply cannot name the account. + expect((await list(null)).accounts).toEqual([]); }); test("puts the account in use first and builds the pin command OMP accepts", () => { From 9909ae760cf9f09077f1d6a752e54235c62272d5 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 17:28:41 +0900 Subject: [PATCH 06/18] fix(paseo-omp): drop the session card and give each account a visible Switch button - IN USE on the account row already names the session's account; remove the separate top card. - Move the switch into the account's name row as an accent pill with an icon. --- paseo-omp/README.md | 2 +- paseo-omp/client/quota-popover.tsx | 112 ++++++++++--------------- paseo-omp/tests/quota-popover.test.tsx | 8 +- 3 files changed, 48 insertions(+), 74 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 1a3562e5..06eb3dba 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Each login shows plan and organization badges from its usage report, such as **Business**, **Pro Lite**, **Personal** or an organization name, and the label drops OMP's parenthesized organization once a badge shows it. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover names the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). **THIS SESSION USES** at the top names that login, its account leads the current provider marked **IN USE**, and **Use for this session** on another linked login sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login links to recorded usage by OMP's identity rule (organization, then email, then account id); a provider with one login and one usage account links without one. A session that has not yet sent a request to the provider has no recorded pin; its logins are still listed for switching and **CURRENT PROVIDER** identifies only the provider. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). That account leads the current provider marked **IN USE**, and every other linked login of the provider has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login links to recorded usage by OMP's identity rule (organization, then email, then account id); a provider with one login and one usage account links without one. A session that has not yet sent a request to the provider has no recorded pin; its logins can still be switched and **CURRENT PROVIDER** identifies only the provider. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index e166e62c..5913d830 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -79,31 +79,6 @@ export function QuotaPopover(props: PluginButtonContentProps) { root: { gap: layout.compact ? 8 : 10, minWidth: layout.compact ? undefined : 260 }, muted: { color: theme.colors.foregroundMuted, fontSize: 13 }, error: { color: theme.colors.statusDanger, fontSize: 13 }, - sessionCard: { - gap: 4, - padding: layout.compact ? 10 : 12, - borderRadius: 10, - borderWidth: 2, - borderColor: theme.colors.accent, - backgroundColor: theme.colors.surface1, - }, - sessionHeading: { - color: theme.colors.foregroundMuted, - fontSize: 10, - fontWeight: "700" as const, - }, - sessionLabelRow: { - flexDirection: "row" as const, - alignItems: "center" as const, - flexWrap: "wrap" as const, - gap: 6, - }, - sessionLabel: { - color: theme.colors.foreground, - fontSize: 14, - fontWeight: "700" as const, - flexShrink: 1, - }, group: (current: boolean) => ({ gap: 6, padding: layout.compact ? 10 : 12, @@ -174,18 +149,23 @@ export function QuotaPopover(props: PluginButtonContentProps) { borderColor: theme.colors.border, overflow: "hidden" as const, }, + // Accent outline plus an icon so the switch reads as an action, not another badge. switch: { - alignSelf: "flex-start" as const, + flexDirection: "row" as const, + alignItems: "center" as const, + gap: 4, + flexShrink: 0, + marginLeft: "auto" as const, paddingHorizontal: 8, - paddingVertical: 4, + paddingVertical: 3, borderWidth: 1, - borderColor: theme.colors.border, - borderRadius: 8, - backgroundColor: theme.colors.surface2, + borderColor: theme.colors.accent, + borderRadius: 999, }, - switchPressed: { opacity: 0.72 }, + switchBelow: { alignSelf: "flex-start" as const, marginLeft: 0 }, + switchPressed: { backgroundColor: theme.colors.surface2 }, switchDisabled: { opacity: 0.45 }, - switchText: { color: theme.colors.foreground, fontSize: 11, fontWeight: "600" as const }, + switchText: { color: theme.colors.accent, fontSize: 11, fontWeight: "700" as const }, }), [layout.compact, theme], ); @@ -196,12 +176,11 @@ export function QuotaPopover(props: PluginButtonContentProps) { const groups = quotaProviderGroups(quotas.data?.quotas ?? [], currentProvider); const hasCurrent = groups.some((group) => group.provider === currentProvider); const logins = sessionAccounts.data?.accounts ?? []; - const activeLogin = logins.find((login) => login.active) ?? null; + const hasActive = logins.some((login) => login.active); const currentAccounts = quotaSessionAccounts( groups.find((group) => group.provider === currentProvider)?.accounts ?? [], logins, ); - const activeAccount = currentAccounts.find((account) => account.inUse) ?? null; function renderTags(tags: readonly string[], style: object) { return ( @@ -215,6 +194,33 @@ export function QuotaPopover(props: PluginButtonContentProps) { ); } + function renderSwitch( + account: QuotaSessionAccountGroup, + login: OmpSessionAccount, + inHeading: boolean, + ) { + const busy = switching !== null; + return ( + void switchTo(login)} + style={({ pressed }) => [ + styles.switch, + inHeading ? null : styles.switchBelow, + pressed ? styles.switchPressed : null, + busy ? styles.switchDisabled : null, + ]} + > + + + {switching === login.credentialId ? "Switching…" : "Switch"} + + + ); + } + function renderAccount(account: QuotaSessionAccountGroup, index: number) { const login = account.login; return ( @@ -244,6 +250,7 @@ export function QuotaPopover(props: PluginButtonContentProps) { ) : null} {account.tags.length > 0 ? renderTags(account.tags, styles.headingTags) : null} {account.inUse ? IN USE : null} + {login && !account.inUse ? renderSwitch(account, login, true) : null}
) : account.tags.length > 0 ? ( renderTags(account.tags, styles.tags) @@ -275,46 +282,13 @@ export function QuotaPopover(props: PluginButtonContentProps) { ); })} - {login && !account.inUse ? ( - void switchTo(login)} - style={({ pressed }) => [ - styles.switch, - pressed ? styles.switchPressed : null, - switching !== null ? styles.switchDisabled : null, - ]} - > - - {switching === login.credentialId ? "Switching…" : "Use for this session"} - - - ) : null} + {login && !account.inUse && !account.label ? renderSwitch(account, login, false) : null} ); } return ( - {activeLogin ? ( - - THIS SESSION USES - - - {activeAccount?.label ?? activeLogin.label} - - {activeAccount && activeAccount.tags.length > 0 - ? renderTags(activeAccount.tags, styles.tags) - : null} - - {quotaProviderLabel(currentProvider)} - - ) : null} {sessionAccounts.error ? ( // The host wraps handler errors in transport details; only a short notice belongs here. Could not read which account this session uses. @@ -327,7 +301,7 @@ export function QuotaPopover(props: PluginButtonContentProps) { Last recorded usage from the local agent database, not read live from the provider. - {currentProvider && !activeLogin ? ( + {currentProvider && !hasActive ? ( CURRENT PROVIDER identifies the provider, not the account used by this session. diff --git a/paseo-omp/tests/quota-popover.test.tsx b/paseo-omp/tests/quota-popover.test.tsx index 05b5c5e3..ae4a205e 100644 --- a/paseo-omp/tests/quota-popover.test.tsx +++ b/paseo-omp/tests/quota-popover.test.tsx @@ -197,7 +197,7 @@ describe("quota popover reconciliation", () => { ); }); - test("shows the account this session uses on top and switches to another on request", async () => { + test("marks the account this session uses and switches to another from its heading", async () => { recorded.logins = [ { credentialId: 3, label: "same@example.invalid", active: false, quotaAccountKeys: ["a"] }, { credentialId: 5, label: "other", active: true, quotaAccountKeys: ["b"] }, @@ -207,8 +207,6 @@ describe("quota popover reconciliation", () => { { ...quota("b", "weekly", 0.2), email: "b@x.invalid" }, ]); - const banner = container.querySelector('[data-accessibility-label="This session uses other"]'); - expect(banner?.textContent).toContain("b@x.invalid"); const inUse = heading("b@x.invalid"); expect(inUse.contains(text("IN USE"))).toBe(true); // The account in use leads its provider even though the other one has more usage. @@ -218,9 +216,11 @@ describe("quota popover reconciliation", () => { ).toBeTruthy(); expect(container.querySelector('[aria-label="Use b@x.invalid for this session"]')).toBeNull(); - const button = container.querySelector( + const other = heading("same@example.invalid"); + const button = other.querySelector( '[aria-label="Use same@example.invalid for this session"]', ) as HTMLButtonElement; + expect(button.textContent).toBe("Switch"); await act(async () => button.click()); expect(recorded.sent).toEqual([ { agentId: "synthetic-agent", text: "/session pin OAuth credential #3" }, From eab33ee31c296fa4d4057767553a091649f7d621 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 17:31:53 +0900 Subject: [PATCH 07/18] fix(paseo-omp): drop redundant notices from the quota popover - Each limit row already says when it was recorded; the pill title says it is not live. - The popover closes on Switch, so the turn-timing note was never seen after switching. - Label the store only for a named profile or custom store. --- paseo-omp/README.md | 2 +- paseo-omp/client/quota-popover.tsx | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 06eb3dba..65868034 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -67,7 +67,7 @@ At startup the plugin discovers directory names under `~/.omp/profiles/` (or `PI Separate provider identities let the model picker request the correct profile catalog before an agent exists. Existing `omp-plugin` and bundled `omp` agents retain their provider; they are not migrated automatically. Profile names use OMP's lowercase grammar, including dotted names such as `team.prod`. -The OMP sidebar and memory panel expose an explicit store selector. Settings, plugins, quota, history, memory and diagnostics use that selection, and profile-agent popovers derive it from the provider ID. OMP-compatible XDG data and state roots are honored when a migrated profile uses them. Default-provider views are labelled **Daemon default store**; changing `providerOptions.command` on the default provider does not make those views profile-aware. Workspace configuration remains project-scoped, with the selected profile supplying inherited settings. Hub records are daemon-wide. The RPCs also accept an explicit absolute `store.agentDir` for custom stores; it is mutually exclusive with `store.profile`. +The OMP sidebar and memory panel expose an explicit store selector. Settings, plugins, quota, history, memory and diagnostics use that selection, and profile-agent popovers derive it from the provider ID. OMP-compatible XDG data and state roots are honored when a migrated profile uses them. Default-provider views are labelled **Daemon default store**, except the quota popover, which names only a profile or custom store; changing `providerOptions.command` on the default provider does not make those views profile-aware. Workspace configuration remains project-scoped, with the selected profile supplying inherited settings. Hub records are daemon-wide. The RPCs also accept an explicit absolute `store.agentDir` for custom stores; it is mutually exclusive with `store.profile`. Profile selection is request-local: concurrent clients cannot change each other's process environment or cached results. Settings edits affect the selected store immediately. diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index 5913d830..35f63cfe 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -294,13 +294,8 @@ export function QuotaPopover(props: PluginButtonContentProps) { Could not read which account this session uses. ) : null} {switchError ? {switchError} : null} - {session.status === "running" && logins.length > 1 ? ( - Switching takes effect after the current turn finishes. - ) : null} - {storeLabel(store)} - - Last recorded usage from the local agent database, not read live from the provider. - + {/* The default store needs no label; a named profile's usage is worth telling apart. */} + {store ? {storeLabel(store)} : null} {currentProvider && !hasActive ? ( CURRENT PROVIDER identifies the provider, not the account used by this session. From ae26ffd93b676d24c0413354506669d1520e42ee Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 20:33:59 +0900 Subject: [PATCH 08/18] fix(paseo-omp): show the in-use account's usage in the quota pill without truncation - Summarize the session's account in use instead of the provider's busiest account. - Show only the percentage beside the provider icon; the tooltip names the provider and account. --- paseo-omp/README.md | 2 +- paseo-omp/client/quota-state.ts | 47 ++++++++++++++++++++------ paseo-omp/index.client.tsx | 48 +++++++++++++++++++-------- paseo-omp/tests/profile-pills.test.ts | 2 +- paseo-omp/tests/quota-state.test.ts | 36 +++++++++++++++++--- 5 files changed, 105 insertions(+), 30 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 65868034..50a6e7e7 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Each login shows plan and organization badges from its usage report, such as **Business**, **Pro Lite**, **Personal** or an organization name, and the label drops OMP's parenthesized organization once a badge shows it. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). That account leads the current provider marked **IN USE**, and every other linked login of the provider has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login links to recorded usage by OMP's identity rule (organization, then email, then account id); a provider with one login and one usage account links without one. A session that has not yet sent a request to the provider has no recorded pin; its logins can still be switched and **CURRENT PROVIDER** identifies only the provider. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). That account leads the current provider marked **IN USE**, and every other linked login of the provider has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login links to recorded usage by OMP's identity rule (organization, then email, then account id); a provider with one login and one usage account links without one. A session that has not yet sent a request to the provider has no recorded pin; its logins can still be switched and **CURRENT PROVIDER** identifies only the provider. The composer pill shows the provider icon and the highest recorded usage of the account in use, such as **19%**; its tooltip names the provider and that account. When the account in use is unknown or has no recorded usage, the pill shows the highest usage across the provider's accounts and its tooltip says **all accounts**. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/client/quota-state.ts b/paseo-omp/client/quota-state.ts index a1ab7487..5237f5bc 100644 --- a/paseo-omp/client/quota-state.ts +++ b/paseo-omp/client/quota-state.ts @@ -62,31 +62,58 @@ export function quotasForProvider( : []; } +/** + * The quotas the pill summarizes: the session's account in use when OMP named one and its usage is + * recorded, otherwise every account of the provider. + */ +export function quotasInUse( + quotas: readonly OmpQuota[], + provider: string | null, + includeAll: boolean, + inUse: OmpSessionAccount | null, +): OmpQuota[] { + const matching = quotasForProvider(quotas, provider, includeAll); + if (!provider || !inUse) return matching; + const own = matching.filter((quota) => inUse.quotaAccountKeys.includes(quota.accountKey)); + return own.length > 0 ? own : matching; +} + +/** + * The pill shows only the percentage beside the provider icon, so a long provider name never + * truncates the number; the title names the provider and the account it describes. + */ export function quotaSummaryForProvider( quotas: readonly OmpQuota[], provider: string | null, includeAll = false, -): { visible: boolean; label: string } { - const matching = quotasForProvider(quotas, provider, includeAll); - const label = provider ? quotaProviderLabel(provider) : "Quotas"; + inUse: OmpSessionAccount | null = null, +): { visible: boolean; label: string; title: string } { + const matching = quotasInUse(quotas, provider, includeAll, inUse); + const own = + provider !== null && + inUse !== null && + matching.some((quota) => inUse.quotaAccountKeys.includes(quota.accountKey)); const used = matching.flatMap((quota) => quota.usedFraction === null ? [] : [quota.usedFraction], ); - if (used.length === 0) { - return provider - ? { visible: true, label: `${quotaProviderLabel(provider)} · —` } - : { visible: includeAll, label: "Quotas · —" }; + const peak = used.length === 0 ? null : `${Math.round(Math.max(...used) * 100)}%`; + const scope = provider + ? [quotaProviderLabel(provider), own && inUse ? inUse.label : "all accounts"].join(" · ") + : "All providers"; + const title = `${scope} · ${peak ?? "no recorded usage"} (last recorded usage, not live)`; + if (!provider) { + return { visible: includeAll, label: `Quotas · ${peak ?? "—"}`, title }; } - const peak = Math.round(Math.max(...used) * 100); - return { visible: true, label: `${label} · ${peak}%` }; + return { visible: true, label: peak ?? "—", title }; } export function quotaSeverityForProvider( quotas: readonly OmpQuota[], provider: string | null, includeAll = false, + inUse: OmpSessionAccount | null = null, ): QuotaSeverity { - const used = quotasForProvider(quotas, provider, includeAll).flatMap((quota) => + const used = quotasInUse(quotas, provider, includeAll, inUse).flatMap((quota) => quota.usedFraction === null ? [] : [quota.usedFraction], ); return used.length === 0 ? "unknown" : quotaSeverityFromFraction(Math.max(...used)); diff --git a/paseo-omp/index.client.tsx b/paseo-omp/index.client.tsx index eabeeb15..0b9a461c 100644 --- a/paseo-omp/index.client.tsx +++ b/paseo-omp/index.client.tsx @@ -61,7 +61,7 @@ import { import { OMP_MCP_AUTH_TIMELINE_KIND, ompMcpAuthorizationTimelineSchema } from "./shared/mcp"; import { type OmpStore, storeForProvider } from "./shared/omp-store"; import { ompImageTimelineSchema, transformOmpImageToolItem } from "./shared/provider-image"; -import { listOmpQuotas } from "./shared/quota"; +import { listOmpQuotas, listOmpSessionAccounts, type OmpSessionAccount } from "./shared/quota"; import { OMP_RULE_NOTICE_KIND, ompRuleNoticeSchema } from "./shared/rule-notices"; import { OMP_SUBAGENT_STRIP_KIND, ompSubagentStripSchema } from "./shared/subagents"; @@ -496,18 +496,26 @@ export default function contribute(client: PluginClientContext) { try { const result = await loadStoreQuotas(targets[0].entry.store); if (disposed || !preferences?.quota) return; - for (const { agentId, entry, handle } of targets) { - const current = pills.get(agentId); - if (current !== entry || current.quota !== handle) continue; - const severity = quotaSeverityForProvider(result.quotas, entry.quotaProvider, true); - handle.update({ - ...quotaSummaryForProvider(result.quotas, entry.quotaProvider, true), - ...(severity === entry.quotaSeverity - ? {} - : { icon: quotaProviderIcon(entry.quotaProvider, severity) }), - }); - entry.quotaSeverity = severity; - } + await Promise.all( + targets.map(async ({ agentId, entry, handle }) => { + const inUse = await accountInUse(agentId, entry.quotaProvider); + const current = pills.get(agentId); + if (disposed || current !== entry || current.quota !== handle) return; + const severity = quotaSeverityForProvider( + result.quotas, + entry.quotaProvider, + true, + inUse, + ); + handle.update({ + ...quotaSummaryForProvider(result.quotas, entry.quotaProvider, true, inUse), + ...(severity === entry.quotaSeverity + ? {} + : { icon: quotaProviderIcon(entry.quotaProvider, severity) }), + }); + entry.quotaSeverity = severity; + }), + ); } catch { // Retain only this store's last result. Failure never falls back to another profile. } @@ -518,6 +526,20 @@ export default function contribute(client: PluginClientContext) { } } + /** The login OMP routes this agent's provider requests to, or null when it cannot say. */ + async function accountInUse( + agentId: string, + provider: string | null, + ): Promise { + if (!provider) return null; + try { + const { accounts } = await client.rpc(listOmpSessionAccounts, { agentId, provider }); + return accounts.find((account) => account.active) ?? null; + } catch { + return null; + } + } + async function refreshComposerPillSettings(): Promise { if (settingsReadRunning || disposed) return; settingsReadRunning = true; diff --git a/paseo-omp/tests/profile-pills.test.ts b/paseo-omp/tests/profile-pills.test.ts index 3ebec612..7f11cb2b 100644 --- a/paseo-omp/tests/profile-pills.test.ts +++ b/paseo-omp/tests/profile-pills.test.ts @@ -143,7 +143,7 @@ test("owned agent directory updates reconcile new agent pills and cached quota r expect.objectContaining({ visible: true, label: "Quotas · 20%" }), ); expect(quota("default").update).toHaveBeenLastCalledWith( - expect.objectContaining({ visible: true, label: "Anthropic · 50%" }), + expect.objectContaining({ visible: true, label: "50%" }), ); expect(quota("codex").update).not.toHaveBeenCalled(); expect( diff --git a/paseo-omp/tests/quota-state.test.ts b/paseo-omp/tests/quota-state.test.ts index 8304daca..f5382436 100644 --- a/paseo-omp/tests/quota-state.test.ts +++ b/paseo-omp/tests/quota-state.test.ts @@ -79,12 +79,35 @@ describe("session-specific quota selection", () => { expect(quotasForProvider(quotas, "anthropic")).toEqual([quotas[0]]); expect(quotaSummaryForProvider(quotas, "anthropic")).toEqual({ visible: true, - label: "Anthropic · 25%", + label: "25%", + title: "Anthropic · all accounts · 25% (last recorded usage, not live)", }); - expect(quotaSummaryForProvider(quotas, "azure")).toEqual({ + expect(quotaSummaryForProvider(quotas, "azure")).toMatchObject({ visible: true, label: "—" }); + }); + + test("summarizes the account in use, not the provider's busiest account", () => { + const rows: OmpQuota[] = [ + { ...quotas[0], accountKey: "spent", usedFraction: 1 }, + { ...quotas[0], accountKey: "working", usedFraction: 0.19 }, + ]; + const working = { + credentialId: 5, + label: "me@example.invalid (Team)", + active: true, + quotaAccountKeys: ["working"], + }; + + expect(quotaSummaryForProvider(rows, "anthropic", false, working)).toEqual({ visible: true, - label: "Azure · —", + label: "19%", + title: "Anthropic · me@example.invalid (Team) · 19% (last recorded usage, not live)", }); + expect(quotaSeverityForProvider(rows, "anthropic", false, working)).toBe("ok"); + // Without an account in use, or with no recorded usage for it, the provider's peak stands. + expect(quotaSummaryForProvider(rows, "anthropic").label).toBe("100%"); + expect( + quotaSummaryForProvider(rows, "anthropic", false, { ...working, quotaAccountKeys: [] }).label, + ).toBe("100%"); }); test("maps each provider to a distinct icon and severity bucket", () => { @@ -928,12 +951,15 @@ describe("profile alias and opaque-model quotas", () => { expect(quotaProviderFromSession("omp-plugin-team-beta", "omp:model:opaque-hash")).toBeNull(); }); test("opaque OMP models retain an explicitly aggregate quota pill", () => { - expect(quotaSummaryForProvider(quotas, null, true)).toEqual({ + expect(quotaSummaryForProvider(quotas, null, true)).toMatchObject({ visible: true, label: "Quotas · 90%", }); expect(quotaSeverityForProvider(quotas, null, true)).toBe("danger"); - expect(quotaSummaryForProvider([], null, true)).toEqual({ visible: true, label: "Quotas · —" }); + expect(quotaSummaryForProvider([], null, true)).toMatchObject({ + visible: true, + label: "Quotas · —", + }); expect(quotaSummaryForProvider(quotas, null).visible).toBe(false); }); }); From 902632b0394bed981b4bbac140494477047838f5 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:04:08 +0900 Subject: [PATCH 09/18] feat(paseo-omp): draw provider brand marks in the quota pill and popover - Ship the Claude, OpenAI, Copilot, Antigravity and Grok marks Paseo uses as currentColor SVG. - Keep Lucide icons for other providers; severity still tints the mark. --- paseo-omp/client/provider-brand.ts | 31 +++++++++++++++++++ paseo-omp/client/provider-icon.tsx | 5 +-- paseo-omp/client/quota-popover.tsx | 4 +-- paseo-omp/client/quota-state.ts | 17 ---------- .../shared/provider-icons/antigravity.svg | 1 + paseo-omp/shared/provider-icons/claude.svg | 1 + paseo-omp/shared/provider-icons/codex.svg | 1 + paseo-omp/shared/provider-icons/copilot.svg | 1 + paseo-omp/shared/provider-icons/grok.svg | 1 + paseo-omp/tests/quota-state.test.ts | 24 +++++++++++--- 10 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 paseo-omp/client/provider-brand.ts create mode 100644 paseo-omp/shared/provider-icons/antigravity.svg create mode 100644 paseo-omp/shared/provider-icons/claude.svg create mode 100644 paseo-omp/shared/provider-icons/codex.svg create mode 100644 paseo-omp/shared/provider-icons/copilot.svg create mode 100644 paseo-omp/shared/provider-icons/grok.svg diff --git a/paseo-omp/client/provider-brand.ts b/paseo-omp/client/provider-brand.ts new file mode 100644 index 00000000..02c22209 --- /dev/null +++ b/paseo-omp/client/provider-brand.ts @@ -0,0 +1,31 @@ +import type { PluginIcon } from "@getpaseo/plugin/client"; +import antigravitySvg from "../shared/provider-icons/antigravity.svg"; +import claudeSvg from "../shared/provider-icons/claude.svg"; +import codexSvg from "../shared/provider-icons/codex.svg"; +import copilotSvg from "../shared/provider-icons/copilot.svg"; +import grokSvg from "../shared/provider-icons/grok.svg"; + +// Paseo's provider brand icons are host-internal: a host icon name such as "claude" fails button +// validation and draws nothing through `Icon`. The same marks ship here as inline SVG that paints +// with `currentColor`, so the host tints them like any icon; other providers use Lucide. +const BRAND_ICONS: Record = { + anthropic: { svg: claudeSvg }, + "antigravity-cli": { svg: antigravitySvg }, + "github-copilot": { svg: copilotSvg }, + "google-antigravity": { svg: antigravitySvg }, + openai: { svg: codexSvg }, + "openai-codex": { svg: codexSvg }, + xai: { svg: grokSvg }, + "xai-oauth": { svg: grokSvg }, +}; + +const LUCIDE_ICONS: Record = { + azure: "Cloud", + cursor: "MousePointer2", +}; + +/** The provider's brand mark when known, else the Lucide icon closest to it, else a gauge. */ +export function providerIcon(provider: string | null): PluginIcon { + if (!provider) return "Gauge"; + return BRAND_ICONS[provider] ?? LUCIDE_ICONS[provider] ?? "Gauge"; +} diff --git a/paseo-omp/client/provider-icon.tsx b/paseo-omp/client/provider-icon.tsx index 63b29c25..8bd67695 100644 --- a/paseo-omp/client/provider-icon.tsx +++ b/paseo-omp/client/provider-icon.tsx @@ -2,7 +2,8 @@ import type { PluginButtonIconProps } from "@getpaseo/plugin/client"; import { Icon } from "@getpaseo/plugin/client/ui"; import type { ComponentType } from "react"; import { View } from "react-native"; -import { type QuotaSeverity, quotaProviderIconName } from "./quota-state"; +import { providerIcon } from "./provider-brand"; +import type { QuotaSeverity } from "./quota-state"; export function quotaProviderIcon( provider: string | null, @@ -19,7 +20,7 @@ export function quotaProviderIcon( : color; return ( - + ); } diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index 35f63cfe..d32e223a 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -6,6 +6,7 @@ import { Pressable, Text, View } from "react-native"; import { storeForProvider, storeLabel } from "../shared/omp-store"; import { listOmpQuotas, listOmpSessionAccounts, type OmpSessionAccount } from "../shared/quota"; import { ompStoreKey } from "./omp-store-state"; +import { providerIcon } from "./provider-brand"; import { type QuotaProviderGroup, type QuotaSessionAccountGroup, @@ -13,7 +14,6 @@ import { quotaDetailLabel, quotaProviderFromSession, quotaProviderGroups, - quotaProviderIconName, quotaProviderLabel, quotaSessionAccounts, quotaSeverityFromFraction, @@ -318,7 +318,7 @@ export function QuotaPopover(props: PluginButtonContentProps) { diff --git a/paseo-omp/client/quota-state.ts b/paseo-omp/client/quota-state.ts index 5237f5bc..48b7f86e 100644 --- a/paseo-omp/client/quota-state.ts +++ b/paseo-omp/client/quota-state.ts @@ -9,23 +9,6 @@ const PROVIDER_LABELS: Record = { "openai-codex": "OpenAI", }; -// Paseo's own provider brand icons (@getpaseo/protocol names such as "claude" or "omp") are -// host-internal: passing one as a button `icon` string fails host validation, and rendering it -// through `Icon` draws nothing. Plugin icons resolve Lucide names only, so each provider maps -// to the Lucide vector closest to its mark. -const PROVIDER_ICON_NAMES: Record = { - anthropic: "Asterisk", - azure: "Cloud", - cursor: "MousePointer2", - "google-antigravity": "Gem", - openai: "Atom", - "openai-codex": "Atom", -}; - -export function quotaProviderIconName(provider: string | null): string { - return (provider ? PROVIDER_ICON_NAMES[provider] : undefined) ?? "Gauge"; -} - export type QuotaSeverity = "ok" | "warning" | "danger" | "unknown"; export function quotaSeverityFromFraction(fraction: number | null): QuotaSeverity { diff --git a/paseo-omp/shared/provider-icons/antigravity.svg b/paseo-omp/shared/provider-icons/antigravity.svg new file mode 100644 index 00000000..9aa99c41 --- /dev/null +++ b/paseo-omp/shared/provider-icons/antigravity.svg @@ -0,0 +1 @@ +Antigravity diff --git a/paseo-omp/shared/provider-icons/claude.svg b/paseo-omp/shared/provider-icons/claude.svg new file mode 100644 index 00000000..6af48e81 --- /dev/null +++ b/paseo-omp/shared/provider-icons/claude.svg @@ -0,0 +1 @@ +Claude diff --git a/paseo-omp/shared/provider-icons/codex.svg b/paseo-omp/shared/provider-icons/codex.svg new file mode 100644 index 00000000..0da7c8ca --- /dev/null +++ b/paseo-omp/shared/provider-icons/codex.svg @@ -0,0 +1 @@ +OpenAI diff --git a/paseo-omp/shared/provider-icons/copilot.svg b/paseo-omp/shared/provider-icons/copilot.svg new file mode 100644 index 00000000..b103751f --- /dev/null +++ b/paseo-omp/shared/provider-icons/copilot.svg @@ -0,0 +1 @@ +GitHub Copilot diff --git a/paseo-omp/shared/provider-icons/grok.svg b/paseo-omp/shared/provider-icons/grok.svg new file mode 100644 index 00000000..dedbc3b1 --- /dev/null +++ b/paseo-omp/shared/provider-icons/grok.svg @@ -0,0 +1 @@ +Grok diff --git a/paseo-omp/tests/quota-state.test.ts b/paseo-omp/tests/quota-state.test.ts index f5382436..d09b788e 100644 --- a/paseo-omp/tests/quota-state.test.ts +++ b/paseo-omp/tests/quota-state.test.ts @@ -4,11 +4,11 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { DatabaseSync } from "node:sqlite"; import { afterEach, describe, expect, test } from "vitest"; +import { providerIcon } from "../client/provider-brand"; import { quotaDetailLabel, quotaProviderFromSession, quotaProviderGroups, - quotaProviderIconName, quotaRecordedLabel, quotaResetLabel, quotaSessionAccounts, @@ -111,10 +111,24 @@ describe("session-specific quota selection", () => { }); test("maps each provider to a distinct icon and severity bucket", () => { - expect(quotaProviderIconName("anthropic")).toBe("Asterisk"); - expect(quotaProviderIconName("cursor")).toBe("MousePointer2"); - expect(quotaProviderIconName("azure")).toBe("Cloud"); - expect(quotaProviderIconName("unknown-vendor")).toBe("Gauge"); + const brand = (provider: string) => providerIcon(provider) as { svg: string }; + // Brand marks for the providers Paseo itself draws; same company, same mark. + expect(brand("anthropic").svg).toEqual(expect.any(String)); + expect(brand("openai-codex")).toEqual(brand("openai")); + expect(brand("xai-oauth")).toEqual(brand("xai")); + expect(brand("antigravity-cli")).toEqual(brand("google-antigravity")); + expect( + new Set( + ["anthropic", "openai-codex", "github-copilot", "antigravity-cli", "xai-oauth"].map( + (provider) => brand(provider).svg, + ), + ).size, + ).toBe(5); + // Others keep the closest Lucide icon. + expect(providerIcon("cursor")).toBe("MousePointer2"); + expect(providerIcon("azure")).toBe("Cloud"); + expect(providerIcon("unknown-vendor")).toBe("Gauge"); + expect(providerIcon(null)).toBe("Gauge"); expect(quotaSeverityForProvider(quotas, "anthropic")).toBe("ok"); expect(quotaSeverityForProvider(quotas, "cursor")).toBe("danger"); expect(quotaSeverityForProvider(quotas, "azure")).toBe("unknown"); From 7090206daaf70f056e31ab7f1417a8618c29186d Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:08:53 +0900 Subject: [PATCH 10/18] feat(paseo-omp): lay OMP account cards out in one to three columns with provider marks - Provider headings on the Accounts tab show the provider's brand mark. - Account cards share a row by the width available: one, two or three per row. --- paseo-omp/client/omp-accounts-section.tsx | 66 ++++++++++++++++------ paseo-omp/client/omp-accounts-state.ts | 10 ++++ paseo-omp/tests/omp-accounts-state.test.ts | 14 +++++ 3 files changed, 74 insertions(+), 16 deletions(-) diff --git a/paseo-omp/client/omp-accounts-section.tsx b/paseo-omp/client/omp-accounts-section.tsx index 69cfae8c..813d6d6b 100644 --- a/paseo-omp/client/omp-accounts-section.tsx +++ b/paseo-omp/client/omp-accounts-section.tsx @@ -10,7 +10,7 @@ import { useToast, } from "@getpaseo/plugin/client/ui"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { type ReactNode, useRef, useState } from "react"; +import { type ReactElement, type ReactNode, useRef, useState } from "react"; import { Pressable, Text, View } from "react-native"; import { cancelOmpAccountLogin, @@ -31,6 +31,8 @@ import { import { type OmpStore, storeLabel } from "../shared/omp-store"; import { openOmpExternalUrl } from "./external-url"; import { + ACCOUNT_GRID_GAP, + accountGridColumns, accountGroups, accountsPollInterval, balanceLine, @@ -41,6 +43,7 @@ import { } from "./omp-accounts-state"; import type { OmpConfigStyles } from "./omp-config-styles"; import { ompStoreKey } from "./omp-store-state"; +import { providerIcon } from "./provider-brand"; import { quotaResetLabel, quotaSeverityFromFraction } from "./quota-state"; type Theme = PluginSurfaceProps["theme"]; @@ -189,7 +192,7 @@ function AccountCard({ const reserveShown = reserveOptions(account, defaultReservePct); const age = usageAgeLabel(account); return ( - + 0 ? (width - ACCOUNT_GRID_GAP * (columns - 1)) / columns : undefined; + return ( + setWidth(event.nativeEvent.layout.width)} + style={{ flexDirection: "row", flexWrap: "wrap", gap: ACCOUNT_GRID_GAP }} + > + {children.map((child) => ( + // Each wrapper takes its card's key, so a removed login never shifts another card's state. + + {child} + + ))} + + ); +} + type SettingRow = { path: OmpAccountsSettingPath; label: string; @@ -838,7 +867,10 @@ export function OmpAccountsSection({ ) : null} {groups.map(({ provider, accounts: logins }) => ( - {provider.name} + + + {provider.name} + {view?.balance .filter((preview) => preview.provider === provider.id) .map((preview) => ( @@ -846,19 +878,21 @@ export function OmpAccountsSection({ {balanceLine(preview)} ))} - {logins.map((account) => ( - setPending({ kind: "remove", account })} - onRedeem={() => setPending({ kind: "reset", account })} - onSteer={(change) => steer.mutate({ kind: "account", account, ...change })} - /> - ))} + + {logins.map((account) => ( + setPending({ kind: "remove", account })} + onRedeem={() => setPending({ kind: "reset", account })} + onSteer={(change) => steer.mutate({ kind: "account", account, ...change })} + /> + ))} + ))} {view?.installed && view.fetchedAt !== null ? ( diff --git a/paseo-omp/client/omp-accounts-state.ts b/paseo-omp/client/omp-accounts-state.ts index ddaed253..c22dab4c 100644 --- a/paseo-omp/client/omp-accounts-state.ts +++ b/paseo-omp/client/omp-accounts-state.ts @@ -63,6 +63,16 @@ export function accountsPollInterval(view: OmpAccountsView | undefined): number return view?.logins.some(loginIsOpen) ? OPEN_LOGIN_POLL_MS : IDLE_POLL_MS; } +/** Narrowest an account card gets before the grid drops a column; its reserve picker needs it. */ +export const ACCOUNT_CARD_MIN_WIDTH = 340; +export const ACCOUNT_GRID_GAP = 10; + +/** One, two or three account cards per row, as many as fit `width` at the minimum card width. */ +export function accountGridColumns(width: number): 1 | 2 | 3 { + const fits = Math.floor((width + ACCOUNT_GRID_GAP) / (ACCOUNT_CARD_MIN_WIDTH + ACCOUNT_GRID_GAP)); + return fits >= 3 ? 3 : fits === 2 ? 2 : 1; +} + export function usedPercent(usedFraction: number): number { return Math.min(100, Math.round(usedFraction * 100)); } diff --git a/paseo-omp/tests/omp-accounts-state.test.ts b/paseo-omp/tests/omp-accounts-state.test.ts index 384a591d..17b58e3f 100644 --- a/paseo-omp/tests/omp-accounts-state.test.ts +++ b/paseo-omp/tests/omp-accounts-state.test.ts @@ -1,5 +1,8 @@ import { describe, expect, test } from "vitest"; import { + ACCOUNT_CARD_MIN_WIDTH, + ACCOUNT_GRID_GAP, + accountGridColumns, accountGroups, accountsPollInterval, balanceLine, @@ -155,3 +158,14 @@ describe("labels", () => { ); }); }); + +describe("account grid", () => { + test("fits one, two or three cards per row and never squeezes a card under its minimum", () => { + expect(accountGridColumns(0)).toBe(1); + expect(accountGridColumns(ACCOUNT_CARD_MIN_WIDTH * 2 + ACCOUNT_GRID_GAP - 1)).toBe(1); + expect(accountGridColumns(ACCOUNT_CARD_MIN_WIDTH * 2 + ACCOUNT_GRID_GAP)).toBe(2); + expect(accountGridColumns(ACCOUNT_CARD_MIN_WIDTH * 3 + ACCOUNT_GRID_GAP * 2)).toBe(3); + // A very wide page still caps at three cards per row. + expect(accountGridColumns(5_000)).toBe(3); + }); +}); From 340b43b88059a25f9ac77f99810d20cf579d0952 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:13:13 +0900 Subject: [PATCH 11/18] feat(paseo-omp): mark each OMP account card with its provider - Cards wrap into columns away from their provider heading, so each shows the provider mark before its name. --- paseo-omp/client/omp-accounts-section.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/paseo-omp/client/omp-accounts-section.tsx b/paseo-omp/client/omp-accounts-section.tsx index 813d6d6b..9b73ccc0 100644 --- a/paseo-omp/client/omp-accounts-section.tsx +++ b/paseo-omp/client/omp-accounts-section.tsx @@ -203,6 +203,8 @@ function AccountCard({ flexShrink: 1, }} > + {/* Cards wrap into columns away from their provider heading, so each names its own. */} + {account.label} From 4058833ab8c1abb33a8705a6c36affbd90cd7199 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:19:04 +0900 Subject: [PATCH 12/18] fix(paseo-omp): give OMP account cards a fixed width that wraps - Measuring the grid's own width fed back into the card widths, so resizing flipped between two and three columns. - Cards are now 440px wide and wrap as many to a row as the page fits; a narrower page shrinks the card. --- paseo-omp/client/omp-accounts-section.tsx | 24 ++++++++-------------- paseo-omp/client/omp-accounts-state.ts | 10 --------- paseo-omp/tests/omp-accounts-state.test.ts | 14 ------------- 3 files changed, 9 insertions(+), 39 deletions(-) diff --git a/paseo-omp/client/omp-accounts-section.tsx b/paseo-omp/client/omp-accounts-section.tsx index 9b73ccc0..68a7ddae 100644 --- a/paseo-omp/client/omp-accounts-section.tsx +++ b/paseo-omp/client/omp-accounts-section.tsx @@ -31,8 +31,6 @@ import { import { type OmpStore, storeLabel } from "../shared/omp-store"; import { openOmpExternalUrl } from "./external-url"; import { - ACCOUNT_GRID_GAP, - accountGridColumns, accountGroups, accountsPollInterval, balanceLine, @@ -282,25 +280,21 @@ function AccountCard({ ); } +/** Fixed account card width: wide enough for the label, badges and the reserve picker on one row. */ +const ACCOUNT_CARD_WIDTH = 440; +const ACCOUNT_GRID_GAP = 10; + /** - * Lays account cards out one, two or three to a row by the width it gets, so a wide window shows - * several logins side by side instead of stretching each one across the page. + * Fixed-width account cards that wrap, as many to a row as the page fits, instead of each card + * stretching across the page. Nothing is measured, so resizing never flips the column count back. + * A page narrower than one card shrinks the card to the page. */ function AccountGrid({ children }: { children: ReactElement[] }) { - const [width, setWidth] = useState(0); - const columns = accountGridColumns(width); - const cardWidth = width > 0 ? (width - ACCOUNT_GRID_GAP * (columns - 1)) / columns : undefined; return ( - setWidth(event.nativeEvent.layout.width)} - style={{ flexDirection: "row", flexWrap: "wrap", gap: ACCOUNT_GRID_GAP }} - > + {children.map((child) => ( // Each wrapper takes its card's key, so a removed login never shifts another card's state. - + {child} ))} diff --git a/paseo-omp/client/omp-accounts-state.ts b/paseo-omp/client/omp-accounts-state.ts index c22dab4c..ddaed253 100644 --- a/paseo-omp/client/omp-accounts-state.ts +++ b/paseo-omp/client/omp-accounts-state.ts @@ -63,16 +63,6 @@ export function accountsPollInterval(view: OmpAccountsView | undefined): number return view?.logins.some(loginIsOpen) ? OPEN_LOGIN_POLL_MS : IDLE_POLL_MS; } -/** Narrowest an account card gets before the grid drops a column; its reserve picker needs it. */ -export const ACCOUNT_CARD_MIN_WIDTH = 340; -export const ACCOUNT_GRID_GAP = 10; - -/** One, two or three account cards per row, as many as fit `width` at the minimum card width. */ -export function accountGridColumns(width: number): 1 | 2 | 3 { - const fits = Math.floor((width + ACCOUNT_GRID_GAP) / (ACCOUNT_CARD_MIN_WIDTH + ACCOUNT_GRID_GAP)); - return fits >= 3 ? 3 : fits === 2 ? 2 : 1; -} - export function usedPercent(usedFraction: number): number { return Math.min(100, Math.round(usedFraction * 100)); } diff --git a/paseo-omp/tests/omp-accounts-state.test.ts b/paseo-omp/tests/omp-accounts-state.test.ts index 17b58e3f..384a591d 100644 --- a/paseo-omp/tests/omp-accounts-state.test.ts +++ b/paseo-omp/tests/omp-accounts-state.test.ts @@ -1,8 +1,5 @@ import { describe, expect, test } from "vitest"; import { - ACCOUNT_CARD_MIN_WIDTH, - ACCOUNT_GRID_GAP, - accountGridColumns, accountGroups, accountsPollInterval, balanceLine, @@ -158,14 +155,3 @@ describe("labels", () => { ); }); }); - -describe("account grid", () => { - test("fits one, two or three cards per row and never squeezes a card under its minimum", () => { - expect(accountGridColumns(0)).toBe(1); - expect(accountGridColumns(ACCOUNT_CARD_MIN_WIDTH * 2 + ACCOUNT_GRID_GAP - 1)).toBe(1); - expect(accountGridColumns(ACCOUNT_CARD_MIN_WIDTH * 2 + ACCOUNT_GRID_GAP)).toBe(2); - expect(accountGridColumns(ACCOUNT_CARD_MIN_WIDTH * 3 + ACCOUNT_GRID_GAP * 2)).toBe(3); - // A very wide page still caps at three cards per row. - expect(accountGridColumns(5_000)).toBe(3); - }); -}); From 14bab7fb2769f38af8c26c05acefb76e3c3b9e34 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:20:52 +0900 Subject: [PATCH 13/18] fix(paseo-omp): right-align the IN USE badge like the Switch button - The badge sits at the end of the account's name row, where the other accounts show Switch. --- paseo-omp/client/quota-popover.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index d32e223a..ead36d90 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -249,7 +249,10 @@ export function QuotaPopover(props: PluginButtonContentProps) { {` · ${account.suffix}`} ) : null} {account.tags.length > 0 ? renderTags(account.tags, styles.headingTags) : null} - {account.inUse ? IN USE : null} + {/* Right-aligned like the Switch button the other accounts have in this spot. */} + {account.inUse ? ( + IN USE + ) : null} {login && !account.inUse ? renderSwitch(account, login, true) : null} ) : account.tags.length > 0 ? ( From 8277368355ac5ce96ca889571e6ec12524db4115 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:33:02 +0900 Subject: [PATCH 14/18] docs(paseo-omp): use a placeholder organization in the account tag example - The example named a real organization; this repository is public. --- paseo-omp/shared/account-tags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paseo-omp/shared/account-tags.ts b/paseo-omp/shared/account-tags.ts index 4bf5ada0..7c8efb8b 100644 --- a/paseo-omp/shared/account-tags.ts +++ b/paseo-omp/shared/account-tags.ts @@ -16,7 +16,7 @@ const PLAN_LABELS: Record = { }; /** - * Plan and organization badges for one login, e.g. ["Business", "Sec Tech Team"] or ["Personal"]. + * Plan and organization badges for one login, e.g. ["Business", "Example Team"] or ["Personal"]. * `plan` is the raw plan OMP's usage report names (Codex `planType`, Copilot `plan`). */ export function accountTags(input: { From c55430be13dbee7f4a70d4b6150c9dd88b5dc8ed Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:38:56 +0900 Subject: [PATCH 15/18] fix(paseo-omp): scope session accounts to the agent's store and match logins like OMP - Read a profile agent's logins, pin and usage from its own store, chosen on the server from the provider Paseo reports. - Gate login-to-usage links on the organization as OMP does, absent on one side included. - Link without an identity only when neither the single login nor the single usage account has one. --- paseo-omp/README.md | 2 +- paseo-omp/index.server.ts | 4 +- paseo-omp/server/quota.ts | 107 +++++++---- paseo-omp/tests/quota-state.test.ts | 278 ++++++++++++++++++++++------ 4 files changed, 296 insertions(+), 95 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 50a6e7e7..976e2c06 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Each login shows plan and organization badges from its usage report, such as **Business**, **Pro Lite**, **Personal** or an organization name, and the label drops OMP's parenthesized organization once a badge shows it. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). That account leads the current provider marked **IN USE**, and every other linked login of the provider has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login links to recorded usage by OMP's identity rule (organization, then email, then account id); a provider with one login and one usage account links without one. A session that has not yet sent a request to the provider has no recorded pin; its logins can still be switched and **CURRENT PROVIDER** identifies only the provider. The composer pill shows the provider icon and the highest recorded usage of the account in use, such as **19%**; its tooltip names the provider and that account. When the account in use is unknown or has no recorded usage, the pill shows the highest usage across the provider's accounts and its tooltip says **all accounts**. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). Both read the agent's own store: a named-profile agent never reads the daemon default store. That account leads the current provider marked **IN USE**, and every other login linked to recorded usage has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login without recorded usage has no row, so it cannot be switched to from the popover. A login links to recorded usage by OMP's identity rule: the organization must match, including being absent on both sides, then the email decides, else the account id. Only a provider whose single login and single usage account both lack an identity (Copilot) links without one. A session that has not yet sent a request to the provider has no recorded pin; its linked logins can still be switched to and **CURRENT PROVIDER** identifies only the provider. The composer pill shows the provider icon and the highest recorded usage of the account in use, such as **19%**; its tooltip names the provider and that account. When the account in use is unknown or has no recorded usage, the pill shows the highest usage across the provider's accounts and its tooltip says **all accounts**. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/index.server.ts b/paseo-omp/index.server.ts index 5ffa1ef4..5ab442f1 100644 --- a/paseo-omp/index.server.ts +++ b/paseo-omp/index.server.ts @@ -55,7 +55,7 @@ import { resolveGetOmpProviderHealth } from "./server/provider-diagnostics"; import { resolveListOmpQuotas, resolveListOmpSessionAccounts, - sessionIdFromPaseo, + sessionAgentFromPaseo, } from "./server/quota"; import { ompRuleNoticeRow } from "./server/rule-notices"; import { @@ -167,7 +167,7 @@ export default function contribute(server: PluginServerContext) { server.handle(tailHubLog, resolveTailHubLog); server.handle(listOmpQuotas, scoped(resolveListOmpQuotas)); server.handle(listOmpSessionAccounts, (input, { paseo }) => - resolveListOmpSessionAccounts(input, subagentControlRegistry, sessionIdFromPaseo(paseo)), + resolveListOmpSessionAccounts(input, subagentControlRegistry, sessionAgentFromPaseo(paseo)), ); server.handle( listOmpAccounts, diff --git a/paseo-omp/server/quota.ts b/paseo-omp/server/quota.ts index 4e68186b..d49c4fff 100644 --- a/paseo-omp/server/quota.ts +++ b/paseo-omp/server/quota.ts @@ -4,8 +4,9 @@ import { DatabaseSync } from "node:sqlite"; import type { RpcInput, RpcOutput } from "@getpaseo/plugin"; import type { PluginHandlerContext } from "@getpaseo/plugin/server"; import { z } from "zod"; +import { storeForProvider } from "../shared/omp-store"; import type { listOmpQuotas, listOmpSessionAccounts, OmpQuota } from "../shared/quota"; -import { ompDataDir } from "./paths"; +import { ompDataDir, withOmpStore } from "./paths"; import type { OmpLogoutAccount } from "./provider/omp-rpc-protocol"; import { OmpRpcRequestRejectedError } from "./provider/omp-rpc-transport"; import { isOmpPublicError, OmpPublicError } from "./provider/security"; @@ -206,16 +207,29 @@ function usageKeyIdentity(accountKey: string): LoginIdentity { }; } -/** OMP's own rule: differing orgs never match, an email on both sides decides, else the account id. */ +/** + * OMP's own rule (`oauthMatchesActiveIdentity`): the organization gates the identity, so differing + * organizations, or one present on only one side, never match; an email on both sides then + * decides, else the account id. A record with no base identity matches on the organization alone. + */ function sameLogin(login: LoginIdentity, usage: LoginIdentity): boolean { - if (login.orgId && usage.orgId && login.orgId !== usage.orgId) return false; + if (login.orgId !== null || usage.orgId !== null) { + if (login.orgId !== usage.orgId) return false; + if (usage.email === null && usage.accountId === null) return true; + } if (login.email && usage.email) return login.email.toLowerCase() === usage.email.toLowerCase(); return login.accountId !== null && login.accountId === usage.accountId; } +function hasIdentity(identity: LoginIdentity): boolean { + return identity.email !== null || identity.accountId !== null; +} + /** - * The usage accounts recorded for each login. Only identity fields leave the credential row; a - * provider with one login and one usage account needs none (Copilot keys hold only a fingerprint). + * The usage accounts recorded for each login. Only identity fields leave the credential row. A login + * with an identity always has to match it. Only when neither the provider's single login nor its + * single usage account carries one (Copilot keys hold a credential fingerprint) are the two linked + * unchecked. */ export function quotaAccountKeysFor( path: string, @@ -231,10 +245,6 @@ export function quotaAccountKeysFor( .prepare("SELECT DISTINCT account_key AS accountKey FROM usage_history WHERE provider = ?") .all(provider) .flatMap(({ accountKey }) => (typeof accountKey === "string" ? [accountKey] : [])); - if (credentialIds.length === 1 && usageKeys.length === 1) { - matched.set(credentialIds[0], [hashAccountKey(usageKeys[0])]); - return matched; - } const rows = database .prepare( `SELECT id, json_extract(data, '$.email') AS email, @@ -243,19 +253,26 @@ export function quotaAccountKeysFor( FROM auth_credentials WHERE id IN (${credentialIds.map(() => "?").join(", ")})`, ) .all(...credentialIds); + const text = (value: unknown) => (typeof value === "string" && value.trim()) || null; for (const row of rows) { if (typeof row.id !== "number") continue; - const text = (value: unknown) => (typeof value === "string" && value.trim()) || null; const login = { email: text(row.email), accountId: text(row.accountId), orgId: text(row.orgId), }; - if (!login.email && !login.accountId) continue; - matched.set( - row.id, - usageKeys.filter((key) => sameLogin(login, usageKeyIdentity(key))).map(hashAccountKey), - ); + if (hasIdentity(login)) { + matched.set( + row.id, + usageKeys.filter((key) => sameLogin(login, usageKeyIdentity(key))).map(hashAccountKey), + ); + } else if ( + credentialIds.length === 1 && + usageKeys.length === 1 && + !hasIdentity(usageKeyIdentity(usageKeys[0])) + ) { + matched.set(row.id, [hashAccountKey(usageKeys[0])]); + } } } finally { database.close(); @@ -266,16 +283,19 @@ export function quotaAccountKeysFor( return matched; } -/** Finds the OMP session id Paseo stored for an agent; null when the agent has none. */ -export type OmpSessionIdLookup = (agentId: string) => Promise; +/** The agent's provider and, for an OMP session Paseo persisted, OMP's session id. */ +export type OmpSessionAgent = { provider: string; sessionId: string | null }; +export type OmpSessionAgentLookup = (agentId: string) => Promise; /** Paseo's bundled `omp` provider and this plugin's providers both persist OMP's session id. */ -export function sessionIdFromPaseo(paseo: PluginHandlerContext["paseo"]): OmpSessionIdLookup { +export function sessionAgentFromPaseo(paseo: PluginHandlerContext["paseo"]): OmpSessionAgentLookup { return async (agentId) => { try { - const persistence = (await paseo.agents.ref(agentId).refresh())?.agent.persistence; - if (!persistence || !/^omp(-|$)/u.test(persistence.provider)) return null; - return persistence.sessionId || null; + const agent = (await paseo.agents.ref(agentId).refresh())?.agent; + if (!agent) return null; + const persistence = agent.persistence; + const omp = persistence && /^omp(-|$)/u.test(persistence.provider); + return { provider: agent.provider, sessionId: (omp && persistence.sessionId) || null }; } catch { return null; } @@ -344,27 +364,35 @@ export function storedSessionLogins( } } +/** + * Logins and usage come from the agent's own store: a named-profile agent never reads the daemon + * default store, whose credential ids belong to other accounts. The store follows the provider + * Paseo reports for the agent, not anything the client sends. + */ export async function resolveListOmpSessionAccounts( input: RpcInput, registry: OmpSubagentControlRegistry, - findSessionId: OmpSessionIdLookup, - databasePath = defaultDatabasePath(), + findAgent: OmpSessionAgentLookup, ): Promise> { - const logins = await sessionLogins(input, registry, findSessionId, databasePath); - const oauth = logins.filter((login) => login.type === "oauth"); - const keys = quotaAccountKeysFor( - databasePath, - input.provider, - oauth.map((login) => login.credentialId), - ); - return { - accounts: oauth.map((login) => ({ - credentialId: login.credentialId, - label: login.label, - active: login.active, - quotaAccountKeys: keys.get(login.credentialId) ?? [], - })), - }; + const agent = await findAgent(input.agentId); + return await withOmpStore(storeForProvider(agent?.provider), async () => { + const databasePath = defaultDatabasePath(); + const logins = await sessionLogins(input, registry, agent?.sessionId ?? null, databasePath); + const oauth = logins.filter((login) => login.type === "oauth"); + const keys = quotaAccountKeysFor( + databasePath, + input.provider, + oauth.map((login) => login.credentialId), + ); + return { + accounts: oauth.map((login) => ({ + credentialId: login.credentialId, + label: login.label, + active: login.active, + quotaAccountKeys: keys.get(login.credentialId) ?? [], + })), + }; + }); } /** @@ -374,12 +402,11 @@ export async function resolveListOmpSessionAccounts( async function sessionLogins( input: RpcInput, registry: OmpSubagentControlRegistry, - findSessionId: OmpSessionIdLookup, + sessionId: string | null, databasePath: string, ): Promise { const controls = registry.get(input.agentId); if (!controls) { - const sessionId = await findSessionId(input.agentId); return sessionId ? storedSessionLogins(databasePath, input.provider, sessionId) : []; } try { diff --git a/paseo-omp/tests/quota-state.test.ts b/paseo-omp/tests/quota-state.test.ts index d09b788e..4dd76017 100644 --- a/paseo-omp/tests/quota-state.test.ts +++ b/paseo-omp/tests/quota-state.test.ts @@ -1,9 +1,9 @@ import { createHash } from "node:crypto"; -import { mkdtemp, rm } from "node:fs/promises"; +import { mkdir, mkdtemp, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { DatabaseSync } from "node:sqlite"; -import { afterEach, describe, expect, test } from "vitest"; +import { afterEach, describe, expect, test, vi } from "vitest"; import { providerIcon } from "../client/provider-brand"; import { quotaDetailLabel, @@ -794,44 +794,109 @@ describe("session account", () => { const teamA = "oauth|account:team|email:a@example.invalid|org:team"; const teamB = "oauth|account:team|email:b@example.invalid|org:team"; const personal = "oauth|account:me|email:a@example.invalid|org:mine"; + const LOCATION_ENV = [ + "PASEO_OMP_AGENT_DIR", + "OMP_AGENT_DIR", + "PI_CODING_AGENT_DIR", + "OMP_PROFILE", + "PI_PROFILE", + "PI_CONFIG_DIR", + "XDG_DATA_HOME", + ]; - async function database(): Promise { + afterEach(() => { + vi.unstubAllEnvs(); + }); + + /** A fresh HOME, so the daemon default store is `/.omp/agent` and profiles sit beside it. */ + async function home(): Promise { const root = await mkdtemp(join(tmpdir(), "paseo-omp-session-accounts-")); quotaRoots.push(root); - const path = join(root, "agent.db"); - const db = new DatabaseSync(path); + for (const name of LOCATION_ENV) vi.stubEnv(name, undefined); + vi.stubEnv("HOME", root); + return root; + } + + type Login = { + id: number; + email?: string; + accountId?: string; + orgId?: string; + orgName?: string; + disabled?: boolean; + }; + + /** OMP's tables with only the columns this reads; tokens sit beside identity as in OMP. */ + async function store( + agentDir: string, + seed: { + provider: string; + usage: string[]; + logins: Login[]; + pins?: Array<[sessionId: string, credentialId: number, expiresAtSec: number]>; + }, + ): Promise { + await mkdir(agentDir, { recursive: true }); + const db = new DatabaseSync(join(agentDir, "agent.db")); db.exec(`CREATE TABLE usage_history (provider TEXT, account_key TEXT); CREATE TABLE auth_credentials (id INTEGER PRIMARY KEY, provider TEXT, credential_type TEXT, data TEXT, disabled_cause TEXT); CREATE TABLE cache (key TEXT PRIMARY KEY, value TEXT, expires_at INTEGER)`); - const usage = db.prepare("INSERT INTO usage_history VALUES ('openai-codex', ?)"); - for (const key of [teamA, teamB, personal]) usage.run(key); - const credential = db.prepare( - "INSERT INTO auth_credentials VALUES (?, 'openai-codex', 'oauth', ?, ?)", - ); - const data = (email: string, accountId: string, orgId: string, orgName: string) => - JSON.stringify({ email, accountId, orgId, orgName, access: "secret-token" }); - credential.run(1, data("a@example.invalid", "team", "team", "Team"), null); - credential.run(2, data("b@example.invalid", "team", "team", "Team"), null); - credential.run(3, data("a@example.invalid", "me", "mine", "a@example.invalid"), null); - credential.run(4, data("gone@example.invalid", "x", "x", "X"), "user"); - const pin = db.prepare("INSERT INTO cache VALUES (?, ?, ?)"); - const future = Math.floor(Date.now() / 1000) + 3_600; - pin.run( - "session:sticky:openai-codex:bundled-session", - JSON.stringify({ type: "oauth", index: 1, credentialId: 2, lastUsedAtMs: 1 }), - future, - ); - pin.run( - "session:sticky:openai-codex:expired-session", - JSON.stringify({ type: "oauth", index: 0, credentialId: 1, lastUsedAtMs: 1 }), - 1, - ); + for (const key of seed.usage) { + db.prepare("INSERT INTO usage_history VALUES (?, ?)").run(seed.provider, key); + } + for (const { id, disabled, ...identity } of seed.logins) { + db.prepare("INSERT INTO auth_credentials VALUES (?, ?, 'oauth', ?, ?)").run( + id, + seed.provider, + JSON.stringify({ ...identity, access: "secret-token" }), + disabled ? "user" : null, + ); + } + for (const [sessionId, credentialId, expiresAt] of seed.pins ?? []) { + db.prepare("INSERT INTO cache VALUES (?, ?, ?)").run( + `session:sticky:${seed.provider}:${sessionId}`, + JSON.stringify({ type: "oauth", index: 0, credentialId, lastUsedAtMs: 1 }), + expiresAt, + ); + } db.close(); - return path; } - const noSession = async () => null; + const future = () => Math.floor(Date.now() / 1000) + 3_600; + + const codexTeam = (agentDir: string) => + store(agentDir, { + provider: "openai-codex", + usage: [teamA, teamB, personal], + logins: [ + { id: 1, email: "a@example.invalid", accountId: "team", orgId: "team", orgName: "Team" }, + { id: 2, email: "b@example.invalid", accountId: "team", orgId: "team", orgName: "Team" }, + { + id: 3, + email: "a@example.invalid", + accountId: "me", + orgId: "mine", + orgName: "a@example.invalid", + }, + { + id: 4, + email: "gone@example.invalid", + accountId: "x", + orgId: "x", + orgName: "X", + disabled: true, + }, + ], + pins: [ + ["bundled-session", 2, future()], + ["expired-session", 1, 1], + ], + }); + + const agentLookup = + (provider: string, sessionId: string | null = null) => + async () => ({ provider, sessionId }); function registryWith(controls: Partial): OmpSubagentControlRegistry { const registry = new OmpSubagentControlRegistry(); @@ -844,28 +909,29 @@ describe("session account", () => { return registry; } + const runtimeLogin = (credentialId: number, active = false) => ({ + credentialId, + provider: "openai-codex", + label: `login ${credentialId}`, + type: "oauth" as const, + active, + }); + test("links each login to its own usage when team seats share an account id and emails repeat across orgs", async () => { - const login = (credentialId: number, active = false) => ({ - credentialId, - provider: "openai-codex", - label: `login ${credentialId}`, - type: "oauth" as const, - active, - }); + await codexTeam(join(await home(), ".omp", "agent")); const registry = registryWith({ listProviderAccounts: async () => [ - login(2, true), - login(1), - login(3), - { ...login(9), type: "api_key" }, + runtimeLogin(2, true), + runtimeLogin(1), + runtimeLogin(3), + { ...runtimeLogin(9), type: "api_key" }, ], }); const result = await resolveListOmpSessionAccounts( { agentId: "agent-1", provider: "openai-codex" }, registry, - noSession, - await database(), + agentLookup("omp-plugin"), ); expect(result.accounts).toEqual([ @@ -876,6 +942,7 @@ describe("session account", () => { }); test("explains an OMP too old to list logins", async () => { + await codexTeam(join(await home(), ".omp", "agent")); const outdated = registryWith({ listProviderAccounts: async () => { throw new OmpRpcRequestRejectedError(undefined, "unsupported_command"); @@ -886,23 +953,18 @@ describe("session account", () => { resolveListOmpSessionAccounts( { agentId: "agent-1", provider: "openai-codex" }, outdated, - noSession, - await database(), + agentLookup("omp-plugin"), ), ).rejects.toThrow("Update OMP to show which login this session uses"); }); test("reads the pin OMP recorded for a session no OMP Plugin runtime owns, such as Paseo's bundled omp", async () => { - const path = await database(); - const empty = new OmpSubagentControlRegistry(); - const forSession = (sessionId: string | null) => async (agentId: string) => - agentId === "bundled-agent" ? sessionId : null; + await codexTeam(join(await home(), ".omp", "agent")); const list = (sessionId: string | null) => resolveListOmpSessionAccounts( { agentId: "bundled-agent", provider: "openai-codex" }, - empty, - forSession(sessionId), - path, + new OmpSubagentControlRegistry(), + agentLookup("omp", sessionId), ); expect((await list("bundled-session")).accounts).toEqual([ @@ -931,6 +993,118 @@ describe("session account", () => { expect((await list(null)).accounts).toEqual([]); }); + test("reads a profile agent's logins and usage from that profile, never the default store", async () => { + const root = await home(); + const profileUsage = "oauth|account:p|email:profile@example.invalid"; + const defaultUsage = "oauth|account:d|email:default@example.invalid"; + // The same credential id is a different account in each store. + await store(join(root, ".omp", "agent"), { + provider: "anthropic", + usage: [defaultUsage], + logins: [{ id: 1, email: "default@example.invalid", accountId: "d" }], + pins: [["session-1", 1, future()]], + }); + await store(join(root, ".omp", "profiles", "team-a", "agent"), { + provider: "anthropic", + usage: [profileUsage], + logins: [{ id: 1, email: "profile@example.invalid", accountId: "p" }], + pins: [["session-1", 1, future()]], + }); + const list = (provider: string) => + resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "anthropic" }, + new OmpSubagentControlRegistry(), + agentLookup(provider, "session-1"), + ); + + expect((await list("omp-plugin-team-a")).accounts).toEqual([ + { + credentialId: 1, + label: "profile@example.invalid", + active: true, + quotaAccountKeys: [sha(profileUsage)], + }, + ]); + expect((await list("omp")).accounts).toEqual([ + { + credentialId: 1, + label: "default@example.invalid", + active: true, + quotaAccountKeys: [sha(defaultUsage)], + }, + ]); + }); + + test("never hands a removed login's leftover usage to the login that replaced it", async () => { + const root = await home(); + await store(join(root, ".omp", "agent"), { + provider: "anthropic", + usage: ["oauth|account:old|email:old@example.invalid|org:o"], + logins: [{ id: 7, email: "new@example.invalid", accountId: "new", orgId: "o" }], + pins: [["session-1", 7, future()]], + }); + const result = await resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "anthropic" }, + new OmpSubagentControlRegistry(), + agentLookup("omp", "session-1"), + ); + + expect(result.accounts).toEqual([ + expect.objectContaining({ credentialId: 7, quotaAccountKeys: [] }), + ]); + }); + + test("links a provider's only login and usage account when neither names an identity, as Copilot's do", async () => { + const root = await home(); + const copilot = "oauth|enterprise:ghe.example.invalid|secret:abc123"; + await store(join(root, ".omp", "agent"), { + provider: "github-copilot", + usage: [copilot], + logins: [{ id: 8 }], + pins: [["session-1", 8, future()]], + }); + + const result = await resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "github-copilot" }, + new OmpSubagentControlRegistry(), + agentLookup("omp", "session-1"), + ); + + expect(result.accounts).toEqual([ + expect.objectContaining({ credentialId: 8, quotaAccountKeys: [sha(copilot)] }), + ]); + }); + + test("keeps an organization-scoped login apart from the same email's org-less usage, as OMP does", async () => { + const root = await home(); + const orgless = "oauth|account:same|email:same@example.invalid"; + const scoped = "oauth|account:same|email:same@example.invalid|org:corp"; + await store(join(root, ".omp", "agent"), { + provider: "anthropic", + usage: [orgless, scoped], + logins: [ + { id: 1, email: "same@example.invalid", accountId: "same", orgId: "corp" }, + { id: 2, email: "same@example.invalid", accountId: "same" }, + ], + }); + + const result = await resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "anthropic" }, + registryWith({ + listProviderAccounts: async () => [ + { ...runtimeLogin(1), provider: "anthropic" }, + { ...runtimeLogin(2), provider: "anthropic" }, + ], + }), + agentLookup("omp-plugin"), + ); + + expect(result.accounts.map((login) => [login.credentialId, login.quotaAccountKeys])).toEqual([ + [1, [sha(scoped)]], + [2, [sha(orgless)]], + ]); + }); + test("puts the account in use first and builds the pin command OMP accepts", () => { const groups = quotaProviderGroups( [ From a1f9a260fb319d042e763b6c2630e2290220f965 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:42:04 +0900 Subject: [PATCH 16/18] fix(paseo-omp): mark a provider's only login in use and close two account-matching gaps - A provider's only stored login is the one in use before any pin; it showed Switch instead of IN USE. - Answer nothing when Paseo cannot look up the agent, instead of reading the default store. - Treat the organization as identity, so an org-only login never links unchecked to another org's usage. --- paseo-omp/README.md | 2 +- paseo-omp/server/quota.ts | 15 +++++++--- paseo-omp/tests/quota-state.test.ts | 44 +++++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index 976e2c06..ea2b5d00 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Each login shows plan and organization badges from its usage report, such as **Business**, **Pro Lite**, **Personal** or an organization name, and the label drops OMP's parenthesized organization once a badge shows it. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). Both read the agent's own store: a named-profile agent never reads the daemon default store. That account leads the current provider marked **IN USE**, and every other login linked to recorded usage has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login without recorded usage has no row, so it cannot be switched to from the popover. A login links to recorded usage by OMP's identity rule: the organization must match, including being absent on both sides, then the email decides, else the account id. Only a provider whose single login and single usage account both lack an identity (Copilot) links without one. A session that has not yet sent a request to the provider has no recorded pin; its linked logins can still be switched to and **CURRENT PROVIDER** identifies only the provider. The composer pill shows the provider icon and the highest recorded usage of the account in use, such as **19%**; its tooltip names the provider and that account. When the account in use is unknown or has no recorded usage, the pill shows the highest usage across the provider's accounts and its tooltip says **all accounts**. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). Both read the agent's own store: a named-profile agent never reads the daemon default store, and an agent Paseo cannot look up gets no account marks. A provider's only stored login is in use even before the session records a pin for it, since OMP has no other account to route to. That account leads the current provider marked **IN USE**, and every other login linked to recorded usage has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login without recorded usage has no row, so it cannot be switched to from the popover. A login links to recorded usage by OMP's identity rule: the organization must match, including being absent on both sides, then the email decides, else the account id. Only a provider whose single login and single usage account both lack any identity, organization included (Copilot), links without one. A session that has not yet sent a request to the provider has no recorded pin; its linked logins can still be switched to and **CURRENT PROVIDER** identifies only the provider. The composer pill shows the provider icon and the highest recorded usage of the account in use, such as **19%**; its tooltip names the provider and that account. When the account in use is unknown or has no recorded usage, the pill shows the highest usage across the provider's accounts and its tooltip says **all accounts**. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/server/quota.ts b/paseo-omp/server/quota.ts index d49c4fff..9f5a2cf9 100644 --- a/paseo-omp/server/quota.ts +++ b/paseo-omp/server/quota.ts @@ -221,8 +221,9 @@ function sameLogin(login: LoginIdentity, usage: LoginIdentity): boolean { return login.accountId !== null && login.accountId === usage.accountId; } +/** Any field OMP's identity rule compares, the organization included. */ function hasIdentity(identity: LoginIdentity): boolean { - return identity.email !== null || identity.accountId !== null; + return identity.email !== null || identity.accountId !== null || identity.orgId !== null; } /** @@ -375,20 +376,26 @@ export async function resolveListOmpSessionAccounts( findAgent: OmpSessionAgentLookup, ): Promise> { const agent = await findAgent(input.agentId); - return await withOmpStore(storeForProvider(agent?.provider), async () => { + // Without the agent its store is unknown; answering from the default store could name another + // store's login that happens to share a credential id. + if (!agent) return { accounts: [] }; + return await withOmpStore(storeForProvider(agent.provider), async () => { const databasePath = defaultDatabasePath(); - const logins = await sessionLogins(input, registry, agent?.sessionId ?? null, databasePath); + const logins = await sessionLogins(input, registry, agent.sessionId, databasePath); const oauth = logins.filter((login) => login.type === "oauth"); const keys = quotaAccountKeysFor( databasePath, input.provider, oauth.map((login) => login.credentialId), ); + // With one stored login and nothing else to authenticate with, OMP has no other account to + // route to, so that login is the one in use even before the session records a pin for it. + const sole = logins.length === 1 && oauth.length === 1; return { accounts: oauth.map((login) => ({ credentialId: login.credentialId, label: login.label, - active: login.active, + active: login.active || sole, quotaAccountKeys: keys.get(login.credentialId) ?? [], })), }; diff --git a/paseo-omp/tests/quota-state.test.ts b/paseo-omp/tests/quota-state.test.ts index 4dd76017..27917add 100644 --- a/paseo-omp/tests/quota-state.test.ts +++ b/paseo-omp/tests/quota-state.test.ts @@ -1054,14 +1054,14 @@ describe("session account", () => { ]); }); - test("links a provider's only login and usage account when neither names an identity, as Copilot's do", async () => { + test("treats a provider's only login as in use before any pin, and links it to its sole identity-less usage", async () => { const root = await home(); const copilot = "oauth|enterprise:ghe.example.invalid|secret:abc123"; + // No pin: the session has not sent a Copilot request yet, as for a freshly opened agent. await store(join(root, ".omp", "agent"), { provider: "github-copilot", usage: [copilot], logins: [{ id: 8 }], - pins: [["session-1", 8, future()]], }); const result = await resolveListOmpSessionAccounts( @@ -1071,10 +1071,48 @@ describe("session account", () => { ); expect(result.accounts).toEqual([ - expect.objectContaining({ credentialId: 8, quotaAccountKeys: [sha(copilot)] }), + expect.objectContaining({ credentialId: 8, active: true, quotaAccountKeys: [sha(copilot)] }), ]); }); + test("compares organizations even for a provider's only login and usage account", async () => { + const root = await home(); + const list = async (usage: string) => { + await rm(join(root, ".omp"), { recursive: true, force: true }); + await store(join(root, ".omp", "agent"), { + provider: "anthropic", + usage: [usage], + logins: [{ id: 5, orgId: "a" }], + }); + return resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "anthropic" }, + new OmpSubagentControlRegistry(), + agentLookup("omp", "session-1"), + ); + }; + + expect((await list("oauth|org:b")).accounts[0]?.quotaAccountKeys).toEqual([]); + expect((await list("oauth|org:a")).accounts[0]?.quotaAccountKeys).toEqual([sha("oauth|org:a")]); + }); + + test("answers nothing when Paseo cannot name the agent, even with its runtime still registered", async () => { + const root = await home(); + // A login in the default store shares the credential id the profile runtime reports. + await store(join(root, ".omp", "agent"), { + provider: "openai-codex", + usage: [teamA], + logins: [{ id: 2, email: "a@example.invalid", accountId: "team", orgId: "team" }], + }); + + const result = await resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "openai-codex" }, + registryWith({ listProviderAccounts: async () => [runtimeLogin(2, true)] }), + async () => null, + ); + + expect(result).toEqual({ accounts: [] }); + }); + test("keeps an organization-scoped login apart from the same email's org-less usage, as OMP does", async () => { const root = await home(); const orgless = "oauth|account:same|email:same@example.invalid"; From 55a5c479a7cb6159f509e5f41bbb990962238c70 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:46:26 +0900 Subject: [PATCH 17/18] fix(paseo-omp): show ONLY LOGIN for a provider's sole credential instead of claiming IN USE - Keep OMP's own in-use answer; one stored login does not prove use when an environment or explicit key serves the session. - Count stored API keys too, so an OAuth login beside a key is not the only one. - The sole login shows ONLY LOGIN where Switch would be, with no Switch. --- paseo-omp/README.md | 2 +- paseo-omp/client/quota-popover.tsx | 11 ++- paseo-omp/server/quota.ts | 29 +++++--- paseo-omp/shared/quota.ts | 7 +- paseo-omp/tests/quota-popover.test.tsx | 28 +++++++- paseo-omp/tests/quota-state.test.ts | 98 +++++++++++++++++++++++--- 6 files changed, 152 insertions(+), 23 deletions(-) diff --git a/paseo-omp/README.md b/paseo-omp/README.md index ea2b5d00..ac93dbc3 100644 --- a/paseo-omp/README.md +++ b/paseo-omp/README.md @@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Each login shows plan and organization badges from its usage report, such as **Business**, **Pro Lite**, **Personal** or an organization name, and the label drops OMP's parenthesized organization once a badge shows it. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts). -The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). Both read the agent's own store: a named-profile agent never reads the daemon default store, and an agent Paseo cannot look up gets no account marks. A provider's only stored login is in use even before the session records a pin for it, since OMP has no other account to route to. That account leads the current provider marked **IN USE**, and every other login linked to recorded usage has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login without recorded usage has no row, so it cannot be switched to from the popover. A login links to recorded usage by OMP's identity rule: the organization must match, including being absent on both sides, then the email decides, else the account id. Only a provider whose single login and single usage account both lack any identity, organization included (Copilot), links without one. A session that has not yet sent a request to the provider has no recorded pin; its linked logins can still be switched to and **CURRENT PROVIDER** identifies only the provider. The composer pill shows the provider icon and the highest recorded usage of the account in use, such as **19%**; its tooltip names the provider and that account. When the account in use is unknown or has no recorded usage, the pill shows the highest usage across the provider's accounts and its tooltip says **all accounts**. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. +The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage, and a divider separates each account. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. The popover marks the login the session uses: a live OMP Plugin session answers through its OMP runtime (`get_logout_accounts`); any other OMP session, including Paseo's bundled **omp** provider, is matched through the session id Paseo stored for the agent to the pin OMP recorded (`session:sticky::`, kept 30 days past its last use). Both read the agent's own store: a named-profile agent never reads the daemon default store, and an agent Paseo cannot look up gets no account marks. That account leads the current provider marked **IN USE**, and every other login linked to recorded usage has an accent **Switch** button at the end of its name row, which sends `/session pin OAuth credential #` to the session, so the switch and OMP's reply appear in the chat timeline. A login that is the provider's only stored credential, API keys included, shows **ONLY LOGIN** in that spot instead of **Switch**; being the only stored login does not prove use, since an environment or explicit key can still serve the session, so it gets **IN USE** only when OMP reports or recorded it. A login without recorded usage has no row, so it cannot be switched to from the popover. A login links to recorded usage by OMP's identity rule: the organization must match, including being absent on both sides, then the email decides, else the account id. Only a provider whose single login and single usage account both lack any identity, organization included (Copilot), links without one. A session that has not yet sent a request to the provider has no recorded pin; its linked logins can still be switched to and **CURRENT PROVIDER** identifies only the provider. The composer pill shows the provider icon and the highest recorded usage of the account in use, such as **19%**; its tooltip names the provider and that account. When the account in use is unknown or has no recorded usage, the pill shows the highest usage across the provider's accounts and its tooltip says **all accounts**. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**. Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers). diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index ead36d90..41bf5170 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -252,8 +252,13 @@ export function QuotaPopover(props: PluginButtonContentProps) { {/* Right-aligned like the Switch button the other accounts have in this spot. */} {account.inUse ? ( IN USE + ) : login?.onlyLogin ? ( + // The provider's only stored credential: nothing to switch to, but its use unproven. + ONLY LOGIN ) : null} - {login && !account.inUse ? renderSwitch(account, login, true) : null} + {login && !account.inUse && !login.onlyLogin + ? renderSwitch(account, login, true) + : null} ) : account.tags.length > 0 ? ( renderTags(account.tags, styles.tags) @@ -285,7 +290,9 @@ export function QuotaPopover(props: PluginButtonContentProps) { ); })} - {login && !account.inUse && !account.label ? renderSwitch(account, login, false) : null} + {login && !account.inUse && !login.onlyLogin && !account.label + ? renderSwitch(account, login, false) + : null} ); } diff --git a/paseo-omp/server/quota.ts b/paseo-omp/server/quota.ts index 9f5a2cf9..d9375d5a 100644 --- a/paseo-omp/server/quota.ts +++ b/paseo-omp/server/quota.ts @@ -332,18 +332,30 @@ export function storedSessionLogins( } } const text = (value: unknown) => (typeof value === "string" && value.trim()) || null; + // Every stored credential, API keys included, so "the only login" counts what OMP can use. return database .prepare( - `SELECT id, json_extract(data, '$.email') AS email, + `SELECT id, credential_type AS type, json_extract(data, '$.email') AS email, json_extract(data, '$.accountId') AS accountId, json_extract(data, '$.orgName') AS orgName FROM auth_credentials - WHERE provider = ? AND credential_type = 'oauth' AND disabled_cause IS NULL + WHERE provider = ? AND disabled_cause IS NULL ORDER BY id`, ) .all(provider) - .flatMap((row) => { + .flatMap((row): OmpLogoutAccount[] => { if (typeof row.id !== "number") return []; + if (row.type !== "oauth") { + return [ + { + credentialId: row.id, + provider, + label: `API key #${row.id}`, + type: "api_key", + active: false, + }, + ]; + } // OMP's own label: the email or account id, then the organization in parentheses. const base = text(row.email) ?? text(row.accountId) ?? `OAuth credential #${row.id}`; const org = text(row.orgName); @@ -352,7 +364,7 @@ export function storedSessionLogins( credentialId: row.id, provider, label: org && org !== base ? `${base} (${org})` : base, - type: "oauth" as const, + type: "oauth", active: row.id === active, }, ]; @@ -388,14 +400,15 @@ export async function resolveListOmpSessionAccounts( input.provider, oauth.map((login) => login.credentialId), ); - // With one stored login and nothing else to authenticate with, OMP has no other account to - // route to, so that login is the one in use even before the session records a pin for it. - const sole = logins.length === 1 && oauth.length === 1; + // One stored credential does not prove use (an environment or explicit key can serve the + // session), so OMP's own `active` stands and the sole login is only flagged as such. + const onlyLogin = logins.length === 1 && oauth.length === 1; return { accounts: oauth.map((login) => ({ credentialId: login.credentialId, label: login.label, - active: login.active || sole, + active: login.active, + onlyLogin, quotaAccountKeys: keys.get(login.credentialId) ?? [], })), }; diff --git a/paseo-omp/shared/quota.ts b/paseo-omp/shared/quota.ts index 6caa3628..8c793a77 100644 --- a/paseo-omp/shared/quota.ts +++ b/paseo-omp/shared/quota.ts @@ -39,8 +39,13 @@ export const OmpSessionAccountSchema = z.object({ /** OMP's credential id; `/session pin OAuth credential #` selects this login. */ credentialId: z.number().int().nonnegative(), label: z.string(), - /** OMP routes this session's requests to this login. */ + /** OMP routes this session's requests to this login, as OMP itself reports or recorded it. */ active: z.boolean(), + /** + * The provider's only stored credential of any kind. Not proof of use: an environment or explicit + * key can still serve the session, so it is shown apart from `active` and never offered a switch. + */ + onlyLogin: z.boolean(), /** `OmpQuota.accountKey` values recorded for this login. */ quotaAccountKeys: z.array(z.string()), }); diff --git a/paseo-omp/tests/quota-popover.test.tsx b/paseo-omp/tests/quota-popover.test.tsx index ae4a205e..c441cd83 100644 --- a/paseo-omp/tests/quota-popover.test.tsx +++ b/paseo-omp/tests/quota-popover.test.tsx @@ -199,8 +199,14 @@ describe("quota popover reconciliation", () => { test("marks the account this session uses and switches to another from its heading", async () => { recorded.logins = [ - { credentialId: 3, label: "same@example.invalid", active: false, quotaAccountKeys: ["a"] }, - { credentialId: 5, label: "other", active: true, quotaAccountKeys: ["b"] }, + { + credentialId: 3, + label: "same@example.invalid", + active: false, + onlyLogin: false, + quotaAccountKeys: ["a"], + }, + { credentialId: 5, label: "other", active: true, onlyLogin: false, quotaAccountKeys: ["b"] }, ]; await render([ quota("a", "weekly", 0.9), @@ -226,4 +232,22 @@ describe("quota popover reconciliation", () => { { agentId: "synthetic-agent", text: "/session pin OAuth credential #3" }, ]); }); + + test("labels a provider's only login without a Switch button or an IN USE claim", async () => { + recorded.logins = [ + { + credentialId: 8, + label: "same@example.invalid", + active: false, + onlyLogin: true, + quotaAccountKeys: ["a"], + }, + ]; + await render([quota("a", "weekly", 0.3)]); + + const only = heading("same@example.invalid"); + expect(only.contains(text("ONLY LOGIN"))).toBe(true); + expect(container.textContent).not.toContain("IN USE"); + expect(container.querySelector('[aria-label$="for this session"]')).toBeNull(); + }); }); diff --git a/paseo-omp/tests/quota-state.test.ts b/paseo-omp/tests/quota-state.test.ts index 27917add..9cc2936c 100644 --- a/paseo-omp/tests/quota-state.test.ts +++ b/paseo-omp/tests/quota-state.test.ts @@ -94,6 +94,7 @@ describe("session-specific quota selection", () => { credentialId: 5, label: "me@example.invalid (Team)", active: true, + onlyLogin: false, quotaAccountKeys: ["working"], }; @@ -824,6 +825,8 @@ describe("session account", () => { orgId?: string; orgName?: string; disabled?: boolean; + /** A stored API key instead of an OAuth login. */ + apiKey?: boolean; }; /** OMP's tables with only the columns this reads; tokens sit beside identity as in OMP. */ @@ -845,10 +848,11 @@ describe("session account", () => { for (const key of seed.usage) { db.prepare("INSERT INTO usage_history VALUES (?, ?)").run(seed.provider, key); } - for (const { id, disabled, ...identity } of seed.logins) { - db.prepare("INSERT INTO auth_credentials VALUES (?, ?, 'oauth', ?, ?)").run( + for (const { id, disabled, apiKey, ...identity } of seed.logins) { + db.prepare("INSERT INTO auth_credentials VALUES (?, ?, ?, ?, ?)").run( id, seed.provider, + apiKey ? "api_key" : "oauth", JSON.stringify({ ...identity, access: "secret-token" }), disabled ? "user" : null, ); @@ -935,9 +939,27 @@ describe("session account", () => { ); expect(result.accounts).toEqual([ - { credentialId: 2, label: "login 2", active: true, quotaAccountKeys: [sha(teamB)] }, - { credentialId: 1, label: "login 1", active: false, quotaAccountKeys: [sha(teamA)] }, - { credentialId: 3, label: "login 3", active: false, quotaAccountKeys: [sha(personal)] }, + { + credentialId: 2, + label: "login 2", + active: true, + onlyLogin: false, + quotaAccountKeys: [sha(teamB)], + }, + { + credentialId: 1, + label: "login 1", + active: false, + onlyLogin: false, + quotaAccountKeys: [sha(teamA)], + }, + { + credentialId: 3, + label: "login 3", + active: false, + onlyLogin: false, + quotaAccountKeys: [sha(personal)], + }, ]); }); @@ -972,18 +994,21 @@ describe("session account", () => { credentialId: 1, label: "a@example.invalid (Team)", active: false, + onlyLogin: false, quotaAccountKeys: [sha(teamA)], }, { credentialId: 2, label: "b@example.invalid (Team)", active: true, + onlyLogin: false, quotaAccountKeys: [sha(teamB)], }, { credentialId: 3, label: "a@example.invalid", active: false, + onlyLogin: false, quotaAccountKeys: [sha(personal)], }, ]); @@ -1022,6 +1047,7 @@ describe("session account", () => { credentialId: 1, label: "profile@example.invalid", active: true, + onlyLogin: true, quotaAccountKeys: [sha(profileUsage)], }, ]); @@ -1030,6 +1056,7 @@ describe("session account", () => { credentialId: 1, label: "default@example.invalid", active: true, + onlyLogin: true, quotaAccountKeys: [sha(defaultUsage)], }, ]); @@ -1054,7 +1081,7 @@ describe("session account", () => { ]); }); - test("treats a provider's only login as in use before any pin, and links it to its sole identity-less usage", async () => { + test("flags a provider's only login without claiming it is in use, and links its sole identity-less usage", async () => { const root = await home(); const copilot = "oauth|enterprise:ghe.example.invalid|secret:abc123"; // No pin: the session has not sent a Copilot request yet, as for a freshly opened agent. @@ -1071,7 +1098,48 @@ describe("session account", () => { ); expect(result.accounts).toEqual([ - expect.objectContaining({ credentialId: 8, active: true, quotaAccountKeys: [sha(copilot)] }), + { + credentialId: 8, + label: "OAuth credential #8", + active: false, + onlyLogin: true, + quotaAccountKeys: [sha(copilot)], + }, + ]); + }); + + test("keeps the runtime's not-in-use answer for a sole login, as when an environment key serves the session", async () => { + await home(); + const result = await resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "openai-codex" }, + registryWith({ listProviderAccounts: async () => [runtimeLogin(2, false)] }), + agentLookup("omp-plugin"), + ); + + expect(result.accounts).toEqual([ + expect.objectContaining({ credentialId: 2, active: false, onlyLogin: true }), + ]); + }); + + test("does not call an OAuth login the only one when a stored API key sits beside it", async () => { + const root = await home(); + await store(join(root, ".omp", "agent"), { + provider: "anthropic", + usage: [], + logins: [ + { id: 1, email: "a@example.invalid", accountId: "a" }, + { id: 2, apiKey: true }, + ], + }); + + const result = await resolveListOmpSessionAccounts( + { agentId: "agent-1", provider: "anthropic" }, + new OmpSubagentControlRegistry(), + agentLookup("omp", "session-1"), + ); + + expect(result.accounts).toEqual([ + expect.objectContaining({ credentialId: 1, active: false, onlyLogin: false }), ]); }); @@ -1153,8 +1221,20 @@ describe("session account", () => { "anthropic", ); const linked = quotaSessionAccounts(groups[0].accounts, [ - { credentialId: 4, label: "busy", active: false, quotaAccountKeys: ["busy"] }, - { credentialId: 7, label: "idle", active: true, quotaAccountKeys: ["idle"] }, + { + credentialId: 4, + label: "busy", + active: false, + onlyLogin: false, + quotaAccountKeys: ["busy"], + }, + { + credentialId: 7, + label: "idle", + active: true, + onlyLogin: false, + quotaAccountKeys: ["idle"], + }, ]); expect( From b94de9224b3a6c2e98029fcdda38d28b30fe69a3 Mon Sep 17 00:00:00 2001 From: JangMinSeok Date: Mon, 16 Nov 2026 21:48:39 +0900 Subject: [PATCH 18/18] fix(paseo-omp): show IN USE and ONLY LOGIN for accounts without a name - An account with no email or account id has no heading row; its state now sits below its limits, where Switch goes. --- paseo-omp/client/quota-popover.tsx | 11 ++++++++--- paseo-omp/tests/quota-popover.test.tsx | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/paseo-omp/client/quota-popover.tsx b/paseo-omp/client/quota-popover.tsx index 41bf5170..c2e24199 100644 --- a/paseo-omp/client/quota-popover.tsx +++ b/paseo-omp/client/quota-popover.tsx @@ -290,9 +290,14 @@ export function QuotaPopover(props: PluginButtonContentProps) { ); })} - {login && !account.inUse && !login.onlyLogin && !account.label - ? renderSwitch(account, login, false) - : null} + {/* An unnamed account has no heading row, so its state sits below its limits. */} + {!account.label && account.inUse ? ( + IN USE + ) : !account.label && login?.onlyLogin ? ( + ONLY LOGIN + ) : login && !account.inUse && !account.label ? ( + renderSwitch(account, login, false) + ) : null} ); } diff --git a/paseo-omp/tests/quota-popover.test.tsx b/paseo-omp/tests/quota-popover.test.tsx index c441cd83..9d72105e 100644 --- a/paseo-omp/tests/quota-popover.test.tsx +++ b/paseo-omp/tests/quota-popover.test.tsx @@ -250,4 +250,26 @@ describe("quota popover reconciliation", () => { expect(container.textContent).not.toContain("IN USE"); expect(container.querySelector('[aria-label$="for this session"]')).toBeNull(); }); + + test("shows an unnamed account's state below its limits, where it has no heading", async () => { + const unnamed = { ...quota("a", "weekly", 0.3), email: null }; + const login = { + credentialId: 8, + label: "OAuth credential #8", + active: false, + onlyLogin: true, + quotaAccountKeys: ["a"], + }; + + recorded.logins = [login]; + await render([unnamed]); + expect(container.querySelector('[role="heading"]')).toBeNull(); + expect(text("ONLY LOGIN")).toBeTruthy(); + expect(container.querySelector('[aria-label$="for this session"]')).toBeNull(); + + recorded.logins = [{ ...login, active: true, onlyLogin: false }]; + await render([unnamed]); + expect(text("IN USE")).toBeTruthy(); + expect(container.textContent).not.toContain("ONLY LOGIN"); + }); });