diff --git a/forge-web/components/repo/new-release.tsx b/forge-web/components/repo/new-release.tsx new file mode 100644 index 000000000..edca2f28a --- /dev/null +++ b/forge-web/components/repo/new-release.tsx @@ -0,0 +1,315 @@ +'use client' + +/** + * "New release" on the releases page (`ux-dx-spec.md` §5.9), maintainers only (consensus + * refuses anyone else's `release`, and the role is re-read before anything uploads). Assets are + * uploaded to the publisher's own storage (the repo's browser-push policy from Settings → + * Storage), each verified and hashed, then one `release` document names them, with its cost + * shown before signing. Nothing goes to Platform but that one small document. + * + * Retries are safe: the write's intent is held by the button (it survives closing the dialog) + * and bound to the content, so "Retry" after an unconfirmed write finishes the same signed + * transition, and edited content always signs a new one. + */ + +import { useMemo, useState } from 'react' +import Link from 'next/link' +import { AlertTriangle, CheckCircle2, FilePlus2, Loader2, Plus, XCircle } from 'lucide-react' +import type { RepoHome } from '@/lib/view' +import { formatBytes } from '@/lib/view' +import type { ReleaseList } from '@/lib/repo' +import type { ReleaseAsset } from '@/lib/repo/writes' +import { + ReleaseWriteError, + assetFilesProblem, + assetPlanProblem, + plannedAsset, + publishRelease, + releaseTextProblem, + tagProblem, +} from '@/lib/repo/new-release' +import { externalTargets, policyForRepo } from '@/lib/storage' +import { UnconfirmedWriteError, previewCreate } from '@/lib/sdk' +import { invalidateSessionCache } from '@/lib/view/session-cache' +import { writeErrorMessage } from '@/lib/view/write-errors' +import { useAuth } from '@/contexts/auth-context' +import { useSdk } from '@/hooks/use-sdk' +import { useIntent } from '@/hooks/use-intent' +import { useStorageConfig } from '@/hooks/use-storage-config' +import { useUiStore } from '@/hooks/use-ui-store' +import { useViewerRole } from '@/hooks/use-repo-chrome' +import { useWriteGuard } from '@/hooks/use-write-guard' +import { Button } from '@/components/ui/button' +import { Dialog } from '@/components/ui/dialog' +import { Field, Input, Textarea } from '@/components/ui/input' +import { CostPreview } from '@/components/ui/cost-preview' +import { cn } from '@/lib/utils' + +type AssetState = { readonly state: 'waiting' | 'uploading' | 'failed' } | { readonly state: 'done'; readonly copies: number; readonly of: number } + +function AssetStateIcon({ state }: { state: AssetState | undefined }): JSX.Element | null { + switch (state?.state) { + case 'uploading': + return + case 'done': + return state.copies < state.of ? ( + + ) : ( + + ) + case 'failed': + return + default: + return null + } +} + +function stateText(s: AssetState | undefined): string { + if (s === undefined) return '' + if (s.state === 'done') return s.copies < s.of ? `stored, verified (${s.copies} of ${s.of} copies)` : `stored, verified (${s.copies} ${s.copies === 1 ? 'copy' : 'copies'})` + return s.state +} + +export function NewReleaseButton({ home, releases, onPublished }: { home: RepoHome; releases: ReleaseList | null; onPublished: () => void }): JSX.Element | null { + const { role, known } = useViewerRole(home.repo) + const [open, setOpen] = useState(false) + // Held here, not in the dialog: closing it must not lose a write's intent. + const draft = useIntent() + // A settled marker (no visible output): tests can tell "no button" from "not decided yet". + if (role !== 'maintainer') return known ?