From 186310a42bb9363f4ad68e3c8936f80541fde471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=81=D0=B5=D0=BB=D1=8C?= Date: Mon, 16 Nov 2026 21:12:50 +0500 Subject: [PATCH] =?UTF-8?q?PEP-177:=20every=20subscription=20shows=20whose?= =?UTF-8?q?=20it=20is=20=E2=80=94=20the=20person's=20name=20next=20to=20it?= =?UTF-8?q?;=20new=20pool=20subscriptions=20are=20named=20after=20their=20?= =?UTF-8?q?owner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- apps/web/app/(app)/subscriptions/page.tsx | 4 +++- apps/web/components/PoolSubscriptions.tsx | 1 + packages/core/src/subscription-care.ts | 4 ++++ packages/core/src/subscriptions.ts | 5 ++++- packages/runner/src/subscriptions.ts | 6 ++++-- packages/testkit/test/subscriptions.test.ts | 4 +++- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/web/app/(app)/subscriptions/page.tsx b/apps/web/app/(app)/subscriptions/page.tsx index 320fe248..14978795 100644 --- a/apps/web/app/(app)/subscriptions/page.tsx +++ b/apps/web/app/(app)/subscriptions/page.tsx @@ -99,6 +99,7 @@ function Problem({ s, login, t }: { s: SubscriptionView; login: PendingLogin | n
{s.name} + {s.ownerName && !s.name.includes(s.ownerName) && · {s.ownerName}} {PROVIDER_NAMES[s.provider]} {s.status === "auth_error" ? {t("ошибка входа")} : {t("вход не закончен · {ago}", { ago: ago(s.createdAt, t) })}}
@@ -165,7 +166,7 @@ function SetCard({ o, subs, t }: { o: PoolOverview; subs: SubscriptionView[]; t: {addable.map((s) => ( - + ))} @@ -260,6 +261,7 @@ export default async function Subscriptions({ searchParams }: { searchParams: Pr {loose.map((s) => (
  • {s.name} + {s.ownerName && !s.name.includes(s.ownerName) && · {s.ownerName}} {PROVIDER_NAMES[s.provider]}
    diff --git a/apps/web/components/PoolSubscriptions.tsx b/apps/web/components/PoolSubscriptions.tsx index 12f5669b..f3c6fbaa 100644 --- a/apps/web/components/PoolSubscriptions.tsx +++ b/apps/web/components/PoolSubscriptions.tsx @@ -28,6 +28,7 @@ export async function PoolSubscriptions({ o, action }: { o: PoolOverview; action {o.subscriptions.map((s) => (
  • {s.name} + {s.ownerName && !s.name.includes(s.ownerName) && · {s.ownerName}} {!s.name.includes(KIND[s.provider]) && {KIND[s.provider]}} {t.text(s.label)} {s.next && {t("следующая")}} diff --git a/packages/core/src/subscription-care.ts b/packages/core/src/subscription-care.ts index 14e4a49c..095f5d60 100644 --- a/packages/core/src/subscription-care.ts +++ b/packages/core/src/subscription-care.ts @@ -135,6 +135,8 @@ export interface PoolSubscriptionState { loan: Loan | null; /** PEP-170: the free subscription an agent of this pool moves to when its own runs out. */ next: boolean; + /** PEP-177: whose subscription (the person's name); null when the viewer must not see it. */ + ownerName: string | null; /** «в работе: 2 агента» / «свободна» / «лимит до 15:40» / «ждёт входа» / «ошибка входа». */ label: string; } @@ -225,6 +227,8 @@ export async function poolOverviews(db: Db, poolIds?: number[], now = new Date() const base = { id: s.id, name: viewer ? visibleSubscriptionName(s, viewer) : s.name, + // A neutral name for a non-admin hides whose it is too (PEP-121). + ownerName: viewer && visibleSubscriptionName(s, viewer) !== s.name ? null : s.ownerName, provider: s.provider, status: s.status, createdBy: s.createdBy, diff --git a/packages/core/src/subscriptions.ts b/packages/core/src/subscriptions.ts index ef66c92b..0cf43041 100644 --- a/packages/core/src/subscriptions.ts +++ b/packages/core/src/subscriptions.ts @@ -29,6 +29,8 @@ export const OPENCODE_KEY_ENV: Record = { export interface SubscriptionView extends Subscription { createdByLogin: string | null; + /** PEP-177: whose subscription — the person's name (login when there is no name). */ + ownerName: string | null; activeSessions: number; /** PEP-39: active sessions on it per project. */ projectSessions: Array<{ key: string; n: number }>; @@ -73,7 +75,7 @@ function countBySubscription(rows: ActiveRow[]): Map { export async function listSubscriptions(db: Db): Promise { const rows = await db - .select({ s: subscriptions, login: users.login }) + .select({ s: subscriptions, login: users.login, personName: users.name }) .from(subscriptions) .leftJoin(users, eq(subscriptions.createdBy, users.id)) .orderBy(asc(subscriptions.id)); @@ -88,6 +90,7 @@ export async function listSubscriptions(db: Db): Promise { return rows.map((r) => ({ ...r.s, createdByLogin: r.login, + ownerName: r.personName?.trim() || r.login, activeSessions: counts.get(r.s.id) ?? 0, projectSessions: perProject(r.s.id), poolIds: members.filter((m) => m.subscriptionId === r.s.id).map((m) => m.poolId), diff --git a/packages/runner/src/subscriptions.ts b/packages/runner/src/subscriptions.ts index cca2776a..c56d2c63 100644 --- a/packages/runner/src/subscriptions.ts +++ b/packages/runner/src/subscriptions.ts @@ -5,7 +5,7 @@ import { spawn } from "node:child_process"; import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { createSubscription, getSubscription, OPENCODE_KEY_ENV, PeppaError, subscriptionSecret, updateSubscription, type Subscription, getPool, listSubscriptions, poolSubscriptions, updatePool } from "@peppa/core"; +import { createSubscription, getSubscription, OPENCODE_KEY_ENV, PeppaError, subscriptionSecret, updateSubscription, type Subscription, getPool, listSubscriptions, poolSubscriptions, updatePool, getUser } from "@peppa/core"; import type { Db } from "@peppa/db"; import { parseResetTime } from "./limits.ts"; import { codexHome, mask, removeSubscription, setClaudeSubscriptionToken, setCodexApiKey, startClaudeLogin, startCodexLogin } from "./subscription-login.ts"; @@ -73,7 +73,9 @@ export async function addPoolSubscription(db: Db, o: { poolId: number; provider: const taken = new Set((await listSubscriptions(db)).map((x) => x.name)); let n = members.filter((x) => x.provider === o.provider).length + 1; while (taken.has(`${label} ${n} — ${pool.name}`)) n++; - const s = await addSubscription(db, { provider: o.provider, name: `${label} ${n} — ${pool.name}`, method: o.provider === "codex" ? "device" : "oauth", createdBy: o.createdBy }); + // PEP-177: the name says whose it is — «Claude 2 — asel», not the pool's name. + const who = (await getUser(db, o.createdBy).catch(() => null))?.login ?? pool.name; + const s = await addSubscription(db, { provider: o.provider, name: `${label} ${n} — ${who}`, method: o.provider === "codex" ? "device" : "oauth", createdBy: o.createdBy }); await updatePool(db, pool.id, { subscriptionIds: [...members.map((m) => m.id), s.id] }); return s; } diff --git a/packages/testkit/test/subscriptions.test.ts b/packages/testkit/test/subscriptions.test.ts index 801a5969..dc929f4f 100644 --- a/packages/testkit/test/subscriptions.test.ts +++ b/packages/testkit/test/subscriptions.test.ts @@ -392,9 +392,11 @@ describe("PEP-164: ещё одна подписка прямо в пул", () => const pool = await core.createPool(db, { name: "Пул ротации PEP-164", subscriptionIds: [first.id] }); const added = await runner.addPoolSubscription(db, { poolId: pool.id, provider: "claude", createdBy: asel.id }); assert.equal(added.status, "pending", "waits for the sign-in"); - assert.match(added.name, /^Claude 2 — Пул ротации PEP-164$/); + assert.match(added.name, /^Claude 2 — asel$/, "PEP-177: the name says whose it is"); const members = (await core.poolSubscriptions(db, pool.id)).map((s) => s.id); assert.deepEqual(members, [first.id, added.id], "already a member of the pool, the first one stays"); + const row = (await core.listSubscriptions(db)).find((x) => x.id === added.id)!; + assert.equal(row.ownerName, "asel", "PEP-177: the owner is shown next to the name"); const login = await runner.pendingLogin(db, added.id); assert.ok(login?.url, "the sign-in link is ready"); await runner.cancelLogin(db, added.id);