From 576a98c7d4ca5e28409f4fc9f395d09c229ebc9d Mon Sep 17 00:00:00 2001 From: pasta Date: Sat, 26 Sep 2026 17:56:03 -0500 Subject: [PATCH 1/4] feat(web): publish a release with assets from the browser Maintainers get a New release button on the releases page: assets upload to their own storage (the repo's browser-push policy), each verified through its public URL and recorded as {name, sha256, sizeBytes, uris}, the CLI's shape; then one release document names them, costed before signing. Like dg release create, assets never go to Platform chunks. Also fixes the default-policy form keeping a removed profile as a target. Co-Authored-By: Claude Opus 5.5 (1M context) --- forge-web/components/repo/new-release.tsx | 196 ++++++++++++++++++ .../components/repo/releases-content.tsx | 7 +- .../components/storage/storage-wizard.tsx | 2 +- forge-web/e2e/new-release.spec.ts | 86 ++++++++ forge-web/lib/repo/new-release.test.ts | 75 +++++++ forge-web/lib/repo/new-release.ts | 95 +++++++++ forge-web/lib/repo/writes.ts | 9 +- forge-web/lib/storage/index.ts | 2 + forge-web/lib/storage/upload.ts | 54 +++++ 9 files changed, 520 insertions(+), 6 deletions(-) create mode 100644 forge-web/components/repo/new-release.tsx create mode 100644 forge-web/e2e/new-release.spec.ts create mode 100644 forge-web/lib/repo/new-release.test.ts create mode 100644 forge-web/lib/repo/new-release.ts diff --git a/forge-web/components/repo/new-release.tsx b/forge-web/components/repo/new-release.tsx new file mode 100644 index 000000000..f91b4942e --- /dev/null +++ b/forge-web/components/repo/new-release.tsx @@ -0,0 +1,196 @@ +'use client' + +/** + * "New release" on the releases page (`ux-dx-spec.md` §5.9), maintainers only (consensus + * refuses anyone else's `release`). 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. + */ + +import { useState } from 'react' +import Link from 'next/link' +import { CheckCircle2, FilePlus2, Loader2, Plus, XCircle } from 'lucide-react' +import type { RepoHome } from '@/lib/view' +import { formatBytes } from '@/lib/view' +import { assetNamesProblem, publishRelease, releaseTextProblem, tagProblem, type AssetFile } from '@/lib/repo/new-release' +import { policyForRepo } from '@/lib/storage' +import { 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 { 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' + +/** Asset files read into memory at once; larger releases go through the CLI. */ +const MAX_TOTAL_BYTES = 256 * 1024 * 1024 + +type AssetState = 'waiting' | 'uploading' | 'done' | 'failed' + +export function NewReleaseButton({ home, onPublished }: { home: RepoHome; onPublished: () => void }): JSX.Element | null { + const { role } = useViewerRole(home.repo) + const [open, setOpen] = useState(false) + if (home.repo.kind !== 'v2' || role !== 'maintainer') return null + return ( + <> + + {open ? setOpen(false)} onPublished={onPublished} /> : null} + + ) +} + +function NewReleaseDialog({ home, onClose, onPublished }: { home: RepoHome; onClose: () => void; onPublished: () => void }): JSX.Element { + const repo = home.repo.kind === 'v2' ? home.repo : null + const { sdk, network } = useSdk() + const { signer } = useAuth() + const guard = useWriteGuard() + const draft = useIntent() + const { config } = useStorageConfig() + const [tag, setTag] = useState('') + const [title, setTitle] = useState('') + const [notes, setNotes] = useState('') + const [files, setFiles] = useState([]) + const [progress, setProgress] = useState>({}) + const [phase, setPhase] = useState<'edit' | 'publishing' | 'done'>('edit') + const [error, setError] = useState(null) + + const policy = config && repo ? policyForRepo(config, repo.repoId) : null + const total = files.reduce((s, f) => s + f.size, 0) + const problem = + tagProblem(tag.trim()) ?? + releaseTextProblem({ name: title, notes }) ?? + assetNamesProblem(files.map((f) => f.name)) ?? + (total > MAX_TOTAL_BYTES ? `assets over ${formatBytes(MAX_TOTAL_BYTES)} in total: publish large releases with dg release create` : null) ?? + (files.length > 0 && (policy === null || policy.targets.length === 0) ? 'choose where assets go first (Settings → Storage)' : null) + // The assets JSON holds, per file, its name, a 64-char hash, a size and up to 4 URLs: size the + // estimate on a typical entry (~220 bytes plus the name). + const assetsEstimate = files.map((f) => `${f.name}${'·'.repeat(110)}`).join('') + const cost = previewCreate('release', { tagName: tag, name: title, notes, assets: assetsEstimate }) + + const publish = async (): Promise => { + if (!sdk || !signer || !repo || problem !== null || !guard.check(cost.credits)) return + setPhase('publishing') + setError(null) + setProgress(Object.fromEntries(files.map((f) => [f.name, 'waiting' as AssetState]))) + try { + const assetFiles: AssetFile[] = [] + for (const f of files) assetFiles.push({ name: f.name, bytes: new Uint8Array(await f.arrayBuffer()) }) + await publishRelease( + sdk, + signer, + repo, + { tagName: tag.trim(), name: title.trim(), notes: notes.trim(), files: assetFiles, intent: draft.intent }, + { policy, profiles: config?.profiles ?? [] }, + (e) => { + if (e.step === 'upload' && e.event.phase === 'start') setProgress((p) => ({ ...p, [e.asset]: 'uploading' })) + if (e.step === 'upload' && e.event.phase === 'failed') setProgress((p) => ({ ...p, [e.asset]: 'failed' })) + if (e.step === 'uploaded') setProgress((p) => ({ ...p, [e.asset]: 'done' })) + }, + ) + invalidateSessionCache(`releases:${network}:`) + draft.renew() + setPhase('done') + onPublished() + setTimeout(onClose, 900) + } catch (e) { + setPhase('edit') + setError(writeErrorMessage(e).message) + } + } + + const busy = phase === 'publishing' + return ( + undefined : onClose} + title="Publish a release" + description="Maintainers only. Assets go to your own storage, hashed; the release itself is one small Platform document." + className="max-w-lg" + footer={ + <> + + + + } + > +
+ + setTag(e.target.value)} className="font-mono" placeholder="v1.0.0" disabled={busy} autoFocus /> + + + setTitle(e.target.value)} disabled={busy} /> + + +