Repository navigation
Add devbox.new creator #5677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add devbox.new creator #5677
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| "use client"; | ||
|
|
||
| import Link from "next/link"; | ||
| import { useState } from "react"; | ||
| import type { FormEvent } from "react"; | ||
|
|
||
| type CreatedDevbox = { | ||
| id: string; | ||
| provider?: string; | ||
| image?: string; | ||
| imageVersion?: string; | ||
| createdAt?: string; | ||
| }; | ||
|
|
||
| type VmErrorBody = { | ||
| error?: string; | ||
| message?: string; | ||
| action?: string; | ||
| reason?: string; | ||
| }; | ||
|
|
||
| function createIdempotencyKey() { | ||
| if (typeof crypto !== "undefined" && "randomUUID" in crypto) { | ||
| return crypto.randomUUID(); | ||
| } | ||
| return `${Date.now()}-${Math.random().toString(36).slice(2)}`; | ||
| } | ||
|
|
||
| function userMessage(status: number, body: VmErrorBody | null) { | ||
| if (status === 401) { | ||
| return "Sign in first, then create the devbox again."; | ||
| } | ||
|
|
||
| const pieces = [body?.message, body?.action ?? body?.reason].filter( | ||
| Boolean, | ||
| ); | ||
| return pieces.join(" ") || `Devbox create failed with status ${status}.`; | ||
| } | ||
|
Comment on lines
+30
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Localize all form/error/success copy and map API errors to locale keys. Line 31, Line 37, Line 79, and Line 89-Line 155 hardcode user-visible strings. Also, Line 34-Line 37 directly surfaces backend Suggested directionconst t = useTranslations("devbox");
setError(t("errors.unauthenticated"));
// map body.error/status => t("errors.<key>")
<h1>{t("title")}</h1>
<textarea placeholder={t("promptPlaceholder")} />
<button>{isCreating ? t("creating") : t("create")}</button>As per coding guidelines: “Web UI, API response copy, and user-facing web data must use locale-specific sources and be represented across all locales in Also applies to: 79-79, 85-159 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| export function DevboxCreator() { | ||
| const [prompt, setPrompt] = useState(""); | ||
| const [isCreating, setIsCreating] = useState(false); | ||
| const [created, setCreated] = useState<CreatedDevbox | null>(null); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| async function submit(event: FormEvent<HTMLFormElement>) { | ||
| event.preventDefault(); | ||
| if (isCreating) return; | ||
|
|
||
| setIsCreating(true); | ||
| setError(null); | ||
| setCreated(null); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate create race on submitMedium Severity The create handler only blocks repeat submits with Reviewed by Cursor Bugbot for commit 1fed97b. Configure here. |
||
|
|
||
| try { | ||
| const response = await fetch("/api/vm", { | ||
| method: "POST", | ||
| headers: { | ||
| "content-type": "application/json", | ||
| "idempotency-key": createIdempotencyKey(), | ||
| }, | ||
| body: JSON.stringify({ | ||
| initialPrompt: prompt.trim() || undefined, | ||
| source: "devbox.new", | ||
| }), | ||
| }); | ||
|
|
||
| const body = (await response.json().catch(() => null)) as | ||
| | CreatedDevbox | ||
| | VmErrorBody | ||
| | null; | ||
|
|
||
| if (!response.ok) { | ||
| setError(userMessage(response.status, body as VmErrorBody | null)); | ||
| return; | ||
| } | ||
|
|
||
| setCreated(body as CreatedDevbox); | ||
| } catch (err) { | ||
| setError(err instanceof Error ? err.message : "Devbox create failed."); | ||
| } finally { | ||
| setIsCreating(false); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div className="w-full"> | ||
| <div className="mb-8 text-center"> | ||
| <h1 className="text-3xl font-semibold tracking-tight sm:text-5xl"> | ||
| Create a devbox | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
AGENTS.md requires every user-facing web string to be localized across the supported message catalogs ( Useful? React with 👍 / 👎. |
||
| </h1> | ||
| <p className="mx-auto mt-4 max-w-xl text-base leading-7 text-muted sm:text-lg"> | ||
| Start a fresh cmux Cloud VM. Add the first prompt now, attach from | ||
| cmux when it is ready. | ||
| </p> | ||
| </div> | ||
|
|
||
| <form onSubmit={submit} className="space-y-4"> | ||
| <label htmlFor="devbox-prompt" className="sr-only"> | ||
| Initial prompt | ||
| </label> | ||
| <textarea | ||
| id="devbox-prompt" | ||
| value={prompt} | ||
| onChange={(event) => setPrompt(event.target.value)} | ||
| placeholder="What should this devbox work on?" | ||
| rows={5} | ||
| className="min-h-36 w-full resize-y rounded-lg border border-border bg-background px-4 py-3 text-base leading-6 outline-none transition-colors placeholder:text-muted focus:border-foreground" | ||
| /> | ||
| <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"> | ||
| <Link | ||
| href="/handler/sign-in?after_auth_return_to=/devbox" | ||
| className="text-sm text-muted underline underline-offset-4 transition-colors hover:text-foreground" | ||
| > | ||
| Sign in | ||
| </Link> | ||
| <button | ||
| type="submit" | ||
| disabled={isCreating} | ||
| className="inline-flex h-11 items-center justify-center rounded-md bg-foreground px-5 text-sm font-medium text-background transition-opacity disabled:cursor-not-allowed disabled:opacity-55" | ||
| > | ||
| {isCreating ? "Creating..." : "Create devbox"} | ||
| </button> | ||
| </div> | ||
| </form> | ||
|
|
||
| {error ? ( | ||
| <p | ||
| role="alert" | ||
| className="mt-5 rounded-md border border-red-500/35 bg-red-500/10 px-4 py-3 text-sm leading-6 text-foreground" | ||
| > | ||
| {error} | ||
| </p> | ||
| ) : null} | ||
|
|
||
| {created ? ( | ||
| <section className="mt-6 rounded-lg border border-border bg-code-bg p-4"> | ||
| <h2 className="text-sm font-semibold">Devbox created</h2> | ||
| <dl className="mt-3 grid gap-2 text-sm"> | ||
| <div className="flex flex-wrap gap-x-3 gap-y-1"> | ||
| <dt className="text-muted">ID</dt> | ||
| <dd className="font-mono">{created.id}</dd> | ||
| </div> | ||
| {created.provider ? ( | ||
| <div className="flex flex-wrap gap-x-3 gap-y-1"> | ||
| <dt className="text-muted">Provider</dt> | ||
| <dd>{created.provider}</dd> | ||
| </div> | ||
| ) : null} | ||
| </dl> | ||
| <div className="mt-4 space-y-2"> | ||
| <code className="block overflow-x-auto rounded-md border border-border bg-background px-3 py-2 text-sm"> | ||
| cmux vm attach {created.id} | ||
| </code> | ||
| <code className="block overflow-x-auto rounded-md border border-border bg-background px-3 py-2 text-sm"> | ||
| cmux vm ssh {created.id} | ||
| </code> | ||
| </div> | ||
| </section> | ||
| ) : null} | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import type { Metadata } from "next"; | ||
| import { Geist, Geist_Mono } from "next/font/google"; | ||
| import "../globals.css"; | ||
|
|
||
| const geistSans = Geist({ | ||
| variable: "--font-geist-sans", | ||
| subsets: ["latin"], | ||
| }); | ||
|
|
||
| const geistMono = Geist_Mono({ | ||
| variable: "--font-geist-mono", | ||
| subsets: ["latin"], | ||
| }); | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: "devbox.new", | ||
| description: "Create a new cmux devbox from a prompt.", | ||
| metadataBase: new URL("https://devbox.new"), | ||
| alternates: { | ||
| canonical: "https://devbox.new", | ||
| }, | ||
| openGraph: { | ||
| title: "devbox.new", | ||
| description: "Create a new cmux devbox from a prompt.", | ||
| url: "https://devbox.new", | ||
| siteName: "devbox.new", | ||
| type: "website", | ||
| }, | ||
| }; | ||
|
Comment on lines
+2
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Localize route metadata and language attributes. Line 16-Line 27 and Line 37 hardcode English metadata and As per coding guidelines: “Web UI, API responses, and user-facing data must use locale-specific sources … update all locales listed in Also applies to: 37-37 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| export default function DevboxLayout({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) { | ||
| return ( | ||
| <html lang="en" suppressHydrationWarning> | ||
| <body | ||
| className={`${geistSans.variable} ${geistMono.variable} bg-background font-sans text-foreground antialiased`} | ||
| > | ||
| {children} | ||
| </body> | ||
| </html> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import Link from "next/link"; | ||
| import { DevboxCreator } from "./devbox-creator"; | ||
|
|
||
| export default function DevboxPage() { | ||
| return ( | ||
| <main className="min-h-screen px-5 py-6 sm:px-8"> | ||
| <div className="mx-auto flex min-h-[calc(100vh-3rem)] w-full max-w-3xl flex-col"> | ||
| <header className="flex items-center justify-between gap-4 text-sm"> | ||
| <Link href="/" className="font-semibold tracking-tight"> | ||
| devbox.new | ||
| </Link> | ||
| <a | ||
| href="https://cmux.com" | ||
| className="text-muted transition-colors hover:text-foreground" | ||
| > | ||
| cmux | ||
| </a> | ||
| </header> | ||
|
Comment on lines
+8
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move page header copy to locale-backed messages. Line 10 and Line 16 introduce user-facing text as hardcoded literals in JSX. This bypasses the locale message source and leaves the new As per coding guidelines: “Web UI … must use locale-specific sources … and update all locales listed in 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| <section className="flex flex-1 items-center justify-center py-16"> | ||
| <DevboxCreator /> | ||
| </section> | ||
| </div> | ||
| </main> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const devboxHosts = new Set(["devbox.new", "www.devbox.new"]); | ||
|
|
||
| export function shouldRewriteToDevbox(host: string | null, pathname: string) { | ||
| const normalizedHost = host?.split(":")[0]?.toLowerCase() ?? ""; | ||
| if (!devboxHosts.has(normalizedHost)) return false; | ||
| return pathname === "/" || pathname === "/devbox"; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { shouldRewriteToDevbox } from "../devbox-routing"; | ||
|
|
||
| describe("devbox.new host routing", () => { | ||
| test("rewrites the devbox.new homepage to the devbox creator", () => { | ||
| expect(shouldRewriteToDevbox("devbox.new", "/")).toBe(true); | ||
| expect(shouldRewriteToDevbox("www.devbox.new", "/")).toBe(true); | ||
| expect(shouldRewriteToDevbox("devbox.new:443", "/")).toBe(true); | ||
| }); | ||
|
|
||
| test("does not rewrite cmux.com or API paths", () => { | ||
| expect(shouldRewriteToDevbox("cmux.com", "/")).toBe(false); | ||
| expect(shouldRewriteToDevbox("devbox.new", "/api/vm")).toBe(false); | ||
| expect(shouldRewriteToDevbox("devbox.new", "/handler/sign-in")).toBe(false); | ||
| }); | ||
|
Comment on lines
+8
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Add coverage for the explicit Line 6-9 only verifies Suggested test diff describe("devbox.new host routing", () => {
test("rewrites the devbox.new homepage to the devbox creator", () => {
expect(shouldRewriteToDevbox("devbox.new", "/")).toBe(true);
expect(shouldRewriteToDevbox("www.devbox.new", "/")).toBe(true);
expect(shouldRewriteToDevbox("devbox.new:443", "/")).toBe(true);
+ expect(shouldRewriteToDevbox("devbox.new", "/devbox")).toBe(true);
});🤖 Prompt for AI Agents |
||
| }); | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every user-visible string in this file — the heading ("Create a devbox"), the subheading, the textarea placeholder ("What should this devbox work on?"), the button labels ("Create devbox", "Creating..."), the sign-in link, the success section heading ("Devbox created"), the field labels ("ID", "Provider"), and the two error messages — are hardcoded in English with no call to
useTranslationsor anynext-intlAPI. The project already supports 20 locales defined inweb/i18n/routing.ts, and no corresponding keys were added to any file underweb/messages/. The same applies to the<title>anddescriptionmetadata inlayout.tsx. A visitor whose browser language is Japanese, Arabic, or any non-English locale will receive a fully English UI, which violates thecmux-full-internationalizationrule that applies to every new production user-facing surface.Rule Used: Flag production user-facing text that is not fully... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!