Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions web/app/devbox/devbox-creator.tsx
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Hardcoded English strings not routed through next-intl

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 useTranslations or any next-intl API. The project already supports 20 locales defined in web/i18n/routing.ts, and no corresponding keys were added to any file under web/messages/. The same applies to the <title> and description metadata in layout.tsx. A visitor whose browser language is Japanese, Arabic, or any non-English locale will receive a fully English UI, which violates the cmux-full-internationalization rule 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!

Comment on lines +30 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

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 message/action/reason, which are not locale-resolved in this client flow. This route should read UI copy from next-intl (or equivalent) and map API error codes to localized keys for every supported locale.

Suggested direction
const 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 web/i18n/routing.ts and web/messages/.”

Also applies to: 79-79, 85-159

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/app/devbox/devbox-creator.tsx` around lines 29 - 38, Replace hardcoded
strings in userMessage with localized messages: import and call
useTranslations("devbox") in the component that calls userMessage, change
userMessage(status: number, body: VmErrorBody | null) to accept a translator (or
move its logic into the component) and map status/body to locale keys (e.g.
t("errors.unauthenticated") for 401, t("errors.<mapped_key>") for known API
error codes or body.action/body.reason), avoid directly surface
body.message/action/reason to users, and fall back to t("errors.generic", {
status }) when no mapping exists; ensure translation keys
(errors.unauthenticated, errors.generic, and specific mapped keys) are added to
the devbox namespace in your i18n messages and routing.

Source: 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate create race on submit

Medium Severity

The create handler only blocks repeat submits with isCreating state, which updates on the next render. A second submit in the same tick (for example a quick double-click) can run before that update and send another POST /api/vm with a fresh idempotency-key, provisioning two devboxes for one action.

Fix in Cursor Fix in Web

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Localize the devbox creator copy

AGENTS.md requires every user-facing web string to be localized across the supported message catalogs (web/messages/en.json and web/messages/ja.json). This new devbox page hard-codes visible copy such as the heading, prompt text, labels, buttons, errors, and metadata, so the Japanese surface cannot be translated and the required localization audit cannot pass; please move the copy into localized messages and add both locales.

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>
);
}
45 changes: 45 additions & 0 deletions web/app/devbox/layout.tsx
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Localize route metadata and language attributes.

Line 16-Line 27 and Line 37 hardcode English metadata and lang="en", so this route cannot reflect active locale. For web/** user-facing surfaces, metadata and language context should come from locale-specific sources and be covered across all locales configured in web/i18n/routing.ts and web/messages/*.

As per coding guidelines: “Web UI, API responses, and user-facing data must use locale-specific sources … update all locales listed in web/i18n/routing.ts and every matching file in web/messages/,” and “All user-facing strings must be localized.”

Also applies to: 37-37

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/app/devbox/layout.tsx` around lines 15 - 29, The exported metadata object
(metadata) and the hardcoded lang="en" in web/app/devbox/layout.tsx must be made
locale-aware: load the current locale from your routing helper
(web/i18n/routing.ts) or next/navigation params, fetch localized
title/description from web/messages/<locale> (or the app i18n utility), and
build metadata (title, description, openGraph.url/siteName/alternates) and the
html lang attribute dynamically using those localized strings and the active
locale; update the Layout component (where metadata and lang are used) and
ensure you populate metadata.alternates/metadataBase per-locale and cover all
locales listed in web/i18n/routing.ts and corresponding web/messages/* entries.

Source: 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>
);
}
26 changes: 26 additions & 0 deletions web/app/devbox/page.tsx
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

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 /devbox page incomplete for non-default locales.

As per coding guidelines: “Web UI … must use locale-specific sources … and update all locales listed in web/i18n/routing.ts and every matching file in web/messages/.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/app/devbox/page.tsx` around lines 8 - 18, The header currently hardcodes
user-facing strings ("devbox.new" inside the Link and "cmux" inside the anchor)
in web/app/devbox/page.tsx; replace these literals by loading the locale
messages and using the appropriate message keys (e.g., a key for the page title
and one for the partner link) via your i18n helper used elsewhere in the app,
update web/i18n/routing.ts to include the new route’s message keys if required,
and add the corresponding translations in every file under web/messages/ for
each locale so the Link and anchor render locale-backed text instead of
hardcoded strings.

Source: Coding guidelines


<section className="flex flex-1 items-center justify-center py-16">
<DevboxCreator />
</section>
</div>
</main>
);
}
7 changes: 7 additions & 0 deletions web/devbox-routing.ts
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";
}
11 changes: 9 additions & 2 deletions web/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import { type NextRequest, NextResponse } from "next/server";
import createMiddleware from "next-intl/middleware";
import { routing } from "./i18n/routing";
import { isAgentPageVariantPath } from "./app/lib/agent-page-paths";
import { shouldRewriteToDevbox } from "./devbox-routing";

const intlMiddleware = createMiddleware(routing);

export default function middleware(request: NextRequest) {
export function proxy(request: NextRequest) {
const host = request.headers.get("host") ?? "";

if (shouldRewriteToDevbox(host, request.nextUrl.pathname)) {
const url = request.nextUrl.clone();
url.pathname = "/devbox";
return NextResponse.rewrite(url);
}

// 301 redirect cmux.dev (and www.cmux.dev) to cmux.com, preserving path and query
if (host === "cmux.dev" || host === "www.cmux.dev") {
const url = new URL(request.url);
Expand All @@ -18,7 +25,7 @@ export default function middleware(request: NextRequest) {

const { pathname } = request.nextUrl;

// Temporary redirect: /changelog → /docs/changelog, preserving any locale prefix.
// Temporary redirect: /changelog -> /docs/changelog, preserving any locale prefix.
const changelogMatch = pathname.match(/^(\/[a-z]{2}(?:-[A-Z]{2})?)?\/changelog\/?$/);
if (changelogMatch) {
const url = request.nextUrl.clone();
Expand Down
16 changes: 16 additions & 0 deletions web/tests/devbox-proxy.test.ts
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add coverage for the explicit /devbox allowlist branch.

Line 6-9 only verifies /, but shouldRewriteToDevbox also explicitly returns true for /devbox (web/devbox-routing.ts Line 6). Add a positive assertion for that branch to prevent silent regression.

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
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/tests/devbox-proxy.test.ts` around lines 5 - 15, The test suite for
shouldRewriteToDevbox is missing coverage for the explicit "/devbox" allowlist
branch in web/devbox-routing.ts; add positive assertions that
shouldRewriteToDevbox("devbox.new", "/devbox") (and similarly for
"www.devbox.new" and "devbox.new:443") return true so the explicit branch is
exercised and protected from regression.

});
Loading