From fb1f316d9b95700168a64bc025672bd695cb39dd Mon Sep 17 00:00:00 2001 From: peppa-bot Date: Thu, 26 Nov 2026 19:03:54 +0000 Subject: [PATCH 1/6] =?UTF-8?q?PEP-280:=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D1=8B=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BA=D1=80=D1=8B=D1=82=D1=8B=D0=B5=20=D0=BF=D0=BE=20=D1=83?= =?UTF-8?q?=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E;=20=D1=81?= =?UTF-8?q?=D1=83=D0=BF=D0=B5=D1=80=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BA=D1=80=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=20=D0=BF=D1=83?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D1=87=D0=BD=D1=8B=D0=B5=20=D0=B2=20=C2=ABGit?= =?UTF-8?q?ea=C2=BB?= 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)/actions.ts | 2 +- apps/web/app/(app)/gitea/actions.ts | 30 +++++ apps/web/app/(app)/gitea/page.tsx | 41 ++++++- apps/web/app/(app)/help/page.tsx | 2 +- apps/web/app/(app)/projects/new/page.tsx | 4 +- .../pep-280-private-by-default/.openspec.yaml | 2 + .../pep-280-private-by-default/design.md | 32 +++++ .../pep-280-private-by-default/proposal.md | 33 ++++++ .../specs/gitea-integration/spec.md | 26 +++++ .../specs/project-provisioning/spec.md | 109 +++++++++++++++++ .../pep-280-private-by-default/tasks.md | 18 +++ packages/cli/src/index.ts | 7 +- packages/core/src/chats.ts | 2 + packages/mcp/src/manager.ts | 6 +- packages/runner/src/provision.ts | 4 +- packages/runner/src/share.ts | 32 ++++- packages/shared/src/i18n/en/admin.ts | 5 + packages/shared/src/i18n/en/help.ts | 4 +- packages/shared/src/i18n/en/project.ts | 2 + packages/shared/src/i18n/en/runner.ts | 2 + packages/shared/src/i18n/kk/admin.ts | 5 + packages/shared/src/i18n/kk/help.ts | 4 +- packages/shared/src/i18n/kk/project.ts | 2 + packages/shared/src/i18n/kk/runner.ts | 2 + packages/testkit/src/mock-gitea.ts | 12 +- packages/testkit/test/repo-visibility.test.ts | 110 +++++++++++++----- 26 files changed, 447 insertions(+), 51 deletions(-) create mode 100644 apps/web/app/(app)/gitea/actions.ts create mode 100644 openspec/changes/pep-280-private-by-default/.openspec.yaml create mode 100644 openspec/changes/pep-280-private-by-default/design.md create mode 100644 openspec/changes/pep-280-private-by-default/proposal.md create mode 100644 openspec/changes/pep-280-private-by-default/specs/gitea-integration/spec.md create mode 100644 openspec/changes/pep-280-private-by-default/specs/project-provisioning/spec.md create mode 100644 openspec/changes/pep-280-private-by-default/tasks.md diff --git a/apps/web/app/(app)/actions.ts b/apps/web/app/(app)/actions.ts index c759ead5..40cc4b7d 100644 --- a/apps/web/app/(app)/actions.ts +++ b/apps/web/app/(app)/actions.ts @@ -392,7 +392,7 @@ export async function createProjectAction(f: FormData) { key: str(f, "key"), name: str(f, "name"), existing: str(f, "mode") === "existing", - visibility: str(f, "visibility") === "private" ? "private" : "public", + visibility: str(f, "visibility") === "public" ? "public" : "private", // PEP-280: closed unless chosen ownerId: user.id, }); return `/p/${p.key}?created=1`; diff --git a/apps/web/app/(app)/gitea/actions.ts b/apps/web/app/(app)/gitea/actions.ts new file mode 100644 index 00000000..5e2de2e5 --- /dev/null +++ b/apps/web/app/(app)/gitea/actions.ts @@ -0,0 +1,30 @@ +"use server"; +// «Gitea» (PEP-280): the superadmin closes one public repository at a time. + +import { PeppaError, requireSuperadmin } from "@peppa/core"; +import { makeRepoPrivate } from "@peppa/runner"; +import { revalidatePath } from "next/cache"; +import { redirect } from "next/navigation"; +import { asWebActor, requireUser } from "@/lib/auth"; +import { db } from "@/lib/db"; +import { getT } from "@/lib/i18n"; + +const str = (f: FormData, k: string) => String(f.get(k) ?? "").trim(); + +/** «Сделать закрытым»: back to the same list with what was closed, or the reason it was not. */ +export async function makeRepoPrivateAction(f: FormData) { + const user = asWebActor(await requireUser()); + const back = new URLSearchParams(); + for (const k of ["q", "show"]) if (str(f, k)) back.set(k, str(f, k)); + try { + await requireSuperadmin(db, user); + const r = await makeRepoPrivate(db, user, str(f, "repo")); + back.set("closed", r.fullName); + } catch (e) { + const t = await getT(); + const msg = e instanceof PeppaError ? t.text(e.message) : t("Ошибка: {message}", { message: (e as Error).message }); + back.set("error", msg.slice(0, 300)); + } + revalidatePath("/gitea"); + redirect(`/gitea${back.size ? `?${back}` : ""}`); +} diff --git a/apps/web/app/(app)/gitea/page.tsx b/apps/web/app/(app)/gitea/page.tsx index 6139dd7b..fb310622 100644 --- a/apps/web/app/(app)/gitea/page.tsx +++ b/apps/web/app/(app)/gitea/page.tsx @@ -3,13 +3,14 @@ import Link from "next/link"; import { notFound } from "next/navigation"; import { ExternalLink, GitBranch, Lock } from "lucide-react"; import { giteaServerOverview, isSuperadmin, type GiteaServerRepo } from "@peppa/core"; -import { ago, Empty, Notice, PageHeader, Section } from "@/components/common"; +import { ago, Empty, Flash, Notice, PageHeader, Section } from "@/components/common"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Workspace } from "@/components/Workspace"; import { requireUser } from "@/lib/auth"; +import { makeRepoPrivateAction } from "./actions"; import { db } from "@/lib/db"; import { getT } from "@/lib/i18n"; import type { Translator } from "@peppa/shared/i18n"; @@ -19,9 +20,10 @@ export async function generateMetadata() { return { title: t("Gitea — FORGE") }; } -type Params = { q?: string; show?: string }; +type Params = { q?: string; show?: string; closed?: string; error?: string }; +type Show = "all" | "linked" | "unlinked" | "public"; -function RepoRow({ r, t }: { r: GiteaServerRepo; t: Translator }) { +function RepoRow({ r, t, q, show }: { r: GiteaServerRepo; t: Translator; q: string; show: Show }) { return (
  • @@ -49,6 +51,18 @@ function RepoRow({ r, t }: { r: GiteaServerRepo; t: Translator }) { )}
    {r.description &&
    {r.description}
    } + {!r.private && ( + // PEP-280: one repository at a time; opening it again is the owner's decision in the project settings. +
    + + {q && } + {show !== "all" && } + +
    + )}
    {t("ветка {branch} · обновлён {when} · {size}", { branch: r.defaultBranch || "—", when: ago(r.updatedAt, t), size: r.sizeKb >= 1024 ? `${(r.sizeKb / 1024).toFixed(1)} MB` : `${r.sizeKb} KB` })}
    @@ -63,10 +77,13 @@ export default async function GiteaPage({ searchParams }: { searchParams: Promis const q = await searchParams; const o = await giteaServerOverview(db); const needle = (q.q ?? "").trim().toLowerCase(); - const show = q.show === "linked" || q.show === "unlinked" ? q.show : "all"; + const show: Show = q.show === "linked" || q.show === "unlinked" || q.show === "public" ? q.show : "all"; const repos = o.repos.filter( - (r) => (!needle || r.fullName.toLowerCase().includes(needle) || r.description.toLowerCase().includes(needle)) && (show === "all" || (show === "linked") === !!r.project), + (r) => + (!needle || r.fullName.toLowerCase().includes(needle) || r.description.toLowerCase().includes(needle)) && + (show === "all" || (show === "public" ? !r.private : (show === "linked") === !!r.project)), ); + const open = o.repos.filter((r) => !r.private).length; const owners = new Map(); for (const r of o.repos) owners.set(r.owner, (owners.get(r.owner) ?? 0) + 1); const linked = o.repos.filter((r) => r.project).length; @@ -100,9 +117,20 @@ export default async function GiteaPage({ searchParams }: { searchParams: Promis {[...owners].sort((a, b) => b[1] - a[1]).map(([owner, n]) => `${owner} ${n}`).join(", ")} )} + {o.repos.length > 0 && ( +
    + {open > 0 ? ( + {t("Публичных: {n} — их видит любой, у кого есть доступ к Gitea", { n: open })} + ) : ( + {t("Публичных нет")} + )} +
    + )} + {q.closed && {t("{repo} теперь закрытый: его видят только владелец, участники и бот", { repo: q.closed })}} + {o.error && {t("Gitea не ответила: {error}", { error: o.error })}}
    @@ -112,6 +140,7 @@ export default async function GiteaPage({ searchParams }: { searchParams: Promis +