Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 32 additions & 1 deletion plugins/team-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ none do, what is set up. The full checklist never renders on the home page.
| GitHub | gh on the server host, read by bb core | The built-in GitHub row in Environment variables is "logged in" (or overridden by your own `GH_TOKEN`) | Runs `gh auth login --web` on the server, shows the device code, waits for GitHub to approve it. |
| devbox | devbox-provider | Connected | Starts devbox-provider's connect; its callback finishes it. |
| Linear | linear | Connected. Optional: a server without it is still complete (unavailable until the server has an OAuth client ID) | Starts the linear plugin's connect; its callback finishes it. |
| Figma | Claude Code on the developer's machine | `figma` is configured at user scope and signed in. Optional: a server that never configures it is still complete (unavailable with no machine, or no `claude` on it) | Runs `claude mcp add --scope user` and `claude mcp login` on the machine, shows the authorization URL, and replays the pasted `http://localhost:<port>/callback` URL against Claude Code's listener. |
| A machine | bb | Any machine exists | Links to Devbox machines. |

The GitHub step is the point. bb core forwards the server host's gh login to
Expand All @@ -26,8 +27,38 @@ No credential passes through this plugin: Claude and Codex tokens go to
Account Pool through its RPCs, the devbox token to devbox-provider, the
Linear tokens to the linear plugin, and the GitHub token to gh's own file.

## Figma

Figma hosts a remote MCP server at `https://mcp.figma.com/mcp` that gives
Claude Code design context from a pasted Figma link. It signs in with browser
OAuth, and Claude Code's OAuth callback is a loopback listener on the machine
that runs `claude` — behind bb-gate, the developer's devbox, which has no
browser. The Figma step closes that gap the way the GitHub step closes the
terminal gap for `gh auth login`.

The step acts on the primary connected machine through this plugin's host
entry (`host.ts`), which runs where Claude Code does. It pins
`oauth.callbackPort` with `claude mcp add --transport http --scope user`, then
starts `claude mcp login` and shows the authorization URL. The developer opens
that URL on their laptop and approves it; the browser lands on a dead
`http://localhost:<port>/callback?code=…` page, and they paste that address
back into the step. The plugin replays it against Claude Code's own loopback
listener. Only the one-time code passes through the plugin, and it is useless
without the PKCE verifier held by Claude Code; the OAuth token lands in Claude
Code's own store on the machine and is never read by bb.

`claude mcp login` refuses to run without a terminal (it offers the
paste-the-redirect-URL prompt), so the host entry starts it under `script`,
which provides a pseudo-terminal. The step is `optional` until Figma is
configured, `todo` once it is configured or a sign-in is waiting, `done` once
Claude Code is signed in, and `unavailable` when no machine is connected or
`claude` is not on it. A server that never configures it is still complete.

No credential passes through this plugin for Figma either: only the one-time
authorization code, which the browser puts in the callback URL.

The checklist polls only while its page is visible, every ten seconds, or
every three while a GitHub sign-in is waiting for approval.
every three while a GitHub or Figma sign-in is waiting for approval.

## Deployment-wide machine variables

Expand Down
101 changes: 99 additions & 2 deletions plugins/team-setup/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const STEP_TITLES: Record<keyof Status["steps"], string> = {
github: "GitHub",
devbox: "devbox",
linear: "Linear",
figma: "Figma",
machine: "a machine",
};

Expand Down Expand Up @@ -147,6 +148,10 @@ interface CodexFlow {
expiresAt: number;
intervalMs: number;
}
interface FigmaFlow {
url: string;
port: number;
}

function Checklist({ compact }: { compact: boolean }) {
const rpc = useRpc<typeof rpcContract>();
Expand All @@ -158,6 +163,9 @@ function Checklist({ compact }: { compact: boolean }) {
const [pasted, setPasted] = useState("");
const [codex, setCodex] = useState<CodexFlow | null>(null);
const [codexError, setCodexError] = useState<string | null>(null);
const [figma, setFigma] = useState<FigmaFlow | null>(null);
const [figmaPasted, setFigmaPasted] = useState("");
const [figmaError, setFigmaError] = useState<string | null>(null);
const mounted = useRef(true);
useEffect(() => {
mounted.current = true;
Expand All @@ -183,7 +191,8 @@ function Checklist({ compact }: { compact: boolean }) {

const complete = status?.complete ?? false;
const githubPending = status?.github.pending !== null && status?.github.pending !== undefined;
useVisiblePolling(refetch, status !== null && !complete, githubPending ? PENDING_POLL_MS : IDLE_POLL_MS);
const figmaPending = status?.figma.pending ?? false;
useVisiblePolling(refetch, status !== null && !complete, githubPending || figmaPending ? PENDING_POLL_MS : IDLE_POLL_MS);

// Codex: Account Pool holds the device-flow session; this page polls it.
useEffect(() => {
Expand Down Expand Up @@ -235,7 +244,7 @@ function Checklist({ compact }: { compact: boolean }) {
return <p className="text-sm text-muted-foreground">{error ?? "Checking…"}</p>;
}

const { ai, github, devbox, linear, machines, steps } = status;
const { ai, github, devbox, linear, machines, steps, figma: figmaStatus } = status;

if (compact && !complete) return <Remaining steps={steps} />;

Expand All @@ -250,13 +259,15 @@ function Checklist({ compact }: { compact: boolean }) {
{github.login !== null ? `GitHub as ${github.login}; ` : steps.github === "done" ? "GitHub; " : ""}
{devbox.project !== null ? `devbox project ${devbox.project}; ` : steps.devbox === "done" ? "devbox; " : ""}
{linear.user !== null ? `Linear as ${linear.user}; ` : steps.linear === "done" ? "Linear; " : ""}
{steps.figma === "done" ? "Figma; " : ""}
{machines.names.length === 1 ? "1 machine" : `${machines.names.length} machines`}.{" "}
<SettingsLink pluginId="team-setup">Details</SettingsLink>
</p>
);
}

const enabledAccounts = ai.accounts.filter((a) => a.enabled);
const figmaUrl = figma?.url ?? figmaStatus.url;

return (
<div className="flex flex-col gap-4 text-sm">
Expand Down Expand Up @@ -476,6 +487,92 @@ function Checklist({ compact }: { compact: boolean }) {
)}
</Step>

<Step
state={steps.figma}
title="Figma (optional)"
action={
figmaStatus.available && !figmaStatus.authenticated && !figmaStatus.pending ? (
<Button size="sm" variant={steps.figma === "todo" ? "default" : "outline"} disabled={busy !== null} onClick={() => void run("figma", async () => {
const s = await rpc.call("figmaSignIn");
setFigmaPasted("");
setFigmaError(null);
setFigma(s);
open(s.url);
})}>
Connect Figma
</Button>
) : null
}
>
{!figmaStatus.available ? (
<p>{figmaStatus.message ?? "Figma is unavailable."}</p>
) : figmaStatus.authenticated ? (
<p>Signed in on {figmaStatus.machine}. Claude Code threads on that machine can use Figma's remote MCP server.</p>
) : figmaStatus.pending ? (
<p>Sign-in started. Approve it in the browser, then paste the address the browser lands on.</p>
) : figmaStatus.configured ? (
<p>Figma is configured on {figmaStatus.machine}, but Claude Code is not signed in to it yet. Finish the sign-in to use it.</p>
) : (
<p>Give Claude Code design context from a Figma link. Figma's remote MCP server signs in with your browser; skip this if you do not use Figma.</p>
)}
{figmaStatus.available && figmaStatus.message !== null ? <p className="text-muted-foreground">{figmaStatus.message}</p> : null}
{figmaStatus.pending || figma !== null ? (
<form
className="flex flex-col gap-2 rounded-lg border border-border p-3"
onSubmit={(e) => {
e.preventDefault();
if (figmaPasted.trim() === "") return;
void run("figma-complete", async () => {
const result = await rpc.call("figmaComplete", { url: figmaPasted.trim() });
if (!result.ok) {
setFigmaError(result.message ?? "The sign-in did not complete.");
return;
}
setFigma(null);
setFigmaPasted("");
setFigmaError(null);
refetch();
});
}}
>
<p className="text-foreground">
Open the URL, approve the sign-in, then paste the <code>http://localhost:…/callback</code> address from the page it
lands on. The page itself will not load; only the address is needed.
</p>
<div className="flex items-center gap-2">
<Button type="button" size="sm" variant="outline" disabled={figmaUrl === null} onClick={() => figmaUrl !== null && open(figmaUrl)}>
Open Figma again
</Button>
<input
className="h-8 flex-1 rounded-md border border-border bg-transparent px-2 text-sm text-foreground"
aria-label="Figma callback URL"
placeholder="Paste the http://localhost:.../callback address"
value={figmaPasted}
onChange={(e) => setFigmaPasted(e.target.value)}
/>
<Button size="sm" type="submit" disabled={busy !== null || figmaPasted.trim() === ""}>
Finish
</Button>
<Button
type="button"
size="sm"
variant="ghost"
onClick={() => void run("figma-cancel", async () => {
await rpc.call("figmaCancel");
setFigma(null);
setFigmaPasted("");
setFigmaError(null);
refetch();
})}
>
Cancel
</Button>
</div>
</form>
) : null}
{figmaError !== null ? <p className="text-destructive">{figmaError}</p> : null}
</Step>

<Step state={steps.machine} title="A machine">
{machines.names.length > 0 ? (
<p>
Expand Down
48 changes: 48 additions & 0 deletions plugins/team-setup/figma-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// The contract between team-setup's server entry and its host entry for the
// Figma step. The host entry runs on the developer's machine, where Claude
// Code and its MCP config live; the server only asks it what to show and
// relays what the developer pastes. Nothing here carries a token.
import { z } from "zod";

export const FIGMA_SERVER_NAME = "figma";
export const FIGMA_SERVER_URL = "https://mcp.figma.com/mcp";
// Claude Code's MCP OAuth callback is always http://localhost:<port>/callback,
// and the only knob it exposes is `oauth.callbackPort`. Pinning one port lets
// the step validate the URL the browser lands on and replay it against the
// loopback listener Claude Code opened. The same port is safe on every machine:
// the listener is loopback-only.
export const FIGMA_CALLBACK_PORT = 53280;

export const figmaHostContract = {
// What the step needs to draw itself: whether `claude` is here, whether the
// figma server is configured at user scope, whether it is signed in, and
// whether a sign-in is waiting for its callback.
state: {
input: z.null(),
output: z.object({
claude: z.boolean(),
configured: z.boolean(),
authenticated: z.boolean(),
pending: z.boolean(),
// The authorization URL while a sign-in waits, so a reloaded page can show it again.
url: z.string().nullable(),
message: z.string().nullable(),
}),
},
// Add the server at user scope and start `claude mcp login`, returning the
// authorization URL and the callback port Claude chose. Idempotent: a second
// call while one is pending returns the same URL.
start: {
input: z.null(),
output: z.object({ url: z.string(), port: z.number().int().positive() }),
},
// Validate the callback URL the developer pasted and replay it against the
// loopback listener. Returns the login process's own error when it fails.
complete: {
input: z.object({ url: z.string().trim().min(1) }).strict(),
output: z.object({ ok: z.boolean(), message: z.string().nullable() }),
},
cancel: { input: z.null(), output: z.object({ ok: z.boolean() }) },
} as const;

export type FigmaHostState = z.infer<(typeof figmaHostContract)["state"]["output"]>;
Loading
Loading