Skip to content

Commit 3b68c2b

Browse files
matt2eclaude
andcommitted
feat(identity): replace first-run key setup with a Builderlab welcome screen
On native desktop with no human key in the credential store, the app now opens on a welcome screen instead of the "Your Buzz identity" key import/create screen: title "Buzz", the subtitle "Your people, your agents, your projects — all in one place.", a primary "Connect with Builderlab" button, and a disabled community URL field and "Scan a QR code" button labelled "Coming soon". A successful Builderlab sign-in ends on a "Connected to Builderlab" page showing the signed-in email (a dead end for now); a failed or canceled sign-in shows the error with a Back button to the welcome screen. Loading, storage-error/retry and ready handling are unchanged. FOUNDATION edit (src/app/App.tsx), kept to the minimum needed: - line 2: import `Welcome` from `../features/identity/Welcome` instead of `IdentitySetup` - lines 49/51: the JSX element wrapping `ConnectedApp` changes from `<IdentitySetup identity=…>` to `<Welcome identity=…>` No other FOUNDATION file (services.ts, main.tsx, communities/service.ts) is touched. Builderlab OAuth reuse: the Settings card signs in through `createOAuthSession(signal => browserCredential(ctx.host, signal))` in src/bundled/builderlab. The welcome screen calls that same session and OAuth client (native `oauth_callback_begin/wait/cancel`, then `/v1/auth/login/exchange` and `/v1/auth/me` over `plugin_host_request`). Because `HostService.request` is plugin-owner-scoped and the plugin's session is not exposed to App, new `oauth/first-run.ts` binds a `Host` to the plugin's own bundled native grant (`block.builderlab`/`bundled`, granted at build time from BUZZ_BUILDERLAB_ORIGIN). That credential is not yet shared with Settings → Integrations → Builderlab. `IdentitySetup` stays for the credential-free fixture (tests/fixtures/identity.html, unchanged) and its tests; its native title bar is extracted into `SetupWindowHeader`, shared with `Welcome`. No Rust or `.env.local` changes. Tests: identity.test.tsx covers the title/subtitle, both disabled "Coming soon" controls, Connect invoking the sign-in entry point and the connected page, failure → Back and cancel → welcome, and the error-state and Linux/Windows title-bar gates now rendered by `Welcome`. first-run.test.ts checks the bundled grant request shape. The window-chrome browser spec asserts the new heading after the launch handoff. docs/identity.md and the Builderlab README describe the new first-launch screen. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 5b194ba commit 3b68c2b

9 files changed

Lines changed: 353 additions & 16 deletions

File tree

‎docs/identity.md‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# Packaged human identity and relay access
22

3-
Native macOS, Windows and Linux without the live development broker offer
4-
**Create a new identity** or **Use an existing key**. These are alternatives.
5-
Setup can also offer **Continue with your Buzz identity** when old Buzz is
6-
installed and **Restore from backup** in builds with backup recovery configured;
7-
both are described below. Import accepts an nsec,
8-
validates its checksum and secp256k1 scalar, and persists that exact key before
9-
adopting its public identity. It never generates a replacement after an import,
10-
read or write failure. Denied/unavailable/corrupt storage is not first run.
3+
Native macOS, Windows and Linux without the live development broker open on a
4+
welcome screen when no human key exists on this device: **Buzz** — "Your people,
5+
your agents, your projects — all in one place." — with **Connect with Builderlab**
6+
as the only enabled action; a community URL field and **Scan a QR code** are shown
7+
disabled as *Coming soon*. Connect runs the bundled Builderlab plugin's browser
8+
sign-in under that plugin's own native network grant. Success currently ends on a
9+
**Connected to Builderlab** page showing the signed-in email; it creates no device
10+
key, and that credential is not yet shared with Settings → Integrations →
11+
Builderlab. Failure or cancellation shows the error with **Back** to the welcome
12+
screen. Denied/unavailable/corrupt storage is not first run and keeps the
13+
**Retry secure storage access** path.
14+
15+
The key setup screen (`IdentitySetup`) is no longer shown on first launch; the
16+
fixture below still renders it. It offers **Create a new identity** or **Use an
17+
existing key**. These are alternatives. It can also offer **Continue with your
18+
Buzz identity** when old Buzz is installed and **Restore from backup** in builds
19+
with backup recovery configured; both are described below. Import accepts an
20+
nsec, validates its checksum and secp256k1 scalar, and persists that exact key
21+
before adopting its public identity. It never generates a replacement after an
22+
import, read or write failure.
1123

1224
One native owner keeps the key in memory after successful restore. The new
1325
create-only secure-storage item is service `dev.local.buzz.foundation.identity` in release
@@ -383,7 +395,8 @@ Use the existing environment-free fixture Vite config:
383395
bin/pnpm exec vite --config tests/fixtures/agent-control.vite.mjs --port 1547
384396
```
385397

386-
Open `/tests/fixtures/identity.html`. It uses mock IPC and an in-memory public
398+
Open `/tests/fixtures/identity.html`. It renders the key import/create screen
399+
(not the first-launch welcome) with mock IPC and an in-memory public
387400
fixture key, not an OS credential store or a relay. Import accepts only the
388401
displayed fixture key. Reset and simulated restart affect fixture state only. **Never enter a real
389402
nsec.** Browser exercises prove UI behavior, not secure native persistence.

‎src/app/App.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// FOUNDATION: Startup, navigation, contributed pages, and built-in Settings.
22
import { AgentAvatarArtworkProvider } from "../features/agents/AgentAvatarArtworkProvider";
3-
import { IdentitySetup } from "../features/identity/IdentitySetup";
3+
import { Welcome } from "../features/identity/Welcome";
44
import { NewMenu } from "./shell/NewMenu";
55
import { PrimarySidebar } from "./shell/PrimarySidebar";
66
import { ChannelNavigationProvider } from "../features/channel-navigation/ChannelNavigationState";
@@ -67,9 +67,9 @@ export function App({ services }: { services: AppServices }) {
6767
>
6868
<LaunchWindowControls />
6969
{services.identity ? (
70-
<IdentitySetup identity={services.identity}>
70+
<Welcome identity={services.identity}>
7171
<ConnectedApp services={services} />
72-
</IdentitySetup>
72+
</Welcome>
7373
) : (
7474
<ConnectedApp services={services} />
7575
)}

‎src/bundled/builderlab/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ agents are not migrated into this type.
9898
plugin-lifetime session. `browserCredential()` returns a verified `Credential`;
9999
`session.credential()` provides access to it. The session handles cancellation,
100100
sign-out, and disposal.
101+
`oauth/first-run.ts` lets the app's first-launch welcome screen run the same
102+
sign-in before any plugin session exists, using this plugin's bundled native
103+
grant; that credential is separate from the Settings session.
101104
- `login/` owns the login experience: pending state, cancellation, retry, email
102105
display, and sign-out.
103106
- `agents/` lists the signed-in account's remote agents beneath login, with
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect, it, vi } from "vitest";
2+
import { invoke } from "@tauri-apps/api/core";
3+
import { bundledHost } from "./first-run";
4+
vi.mock("@tauri-apps/api/core", () => ({
5+
invoke: vi.fn(),
6+
isTauri: vi.fn(() => true),
7+
}));
8+
9+
it("requests under the bundled Builderlab grant without a plugin owner", async () => {
10+
vi.mocked(invoke).mockResolvedValueOnce({
11+
status: 200,
12+
headers: {},
13+
body: "{}",
14+
});
15+
const request = { url: "https://app.builderlab.xyz/api/goose/v1/auth/me" };
16+
await bundledHost.request(request);
17+
expect(invoke).toHaveBeenCalledWith("plugin_host_request", {
18+
id: "block.builderlab",
19+
revision: "bundled",
20+
request,
21+
});
22+
expect(await bundledHost.runCommand("any")).toBeNull();
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { invoke } from "@tauri-apps/api/core";
2+
import type { Host } from "../../../features/host/service";
3+
import manifest from "../manifest.json";
4+
import { browserCredential, type Credential } from "./browser";
5+
6+
/**
7+
* First launch runs before this plugin can share its Settings session, so the
8+
* welcome screen signs in through the same OAuth client under the bundled
9+
* plugin's own native network grant. Native code grants that origin at build
10+
* time; it does not depend on the plugin's JavaScript having started.
11+
*/
12+
export const bundledHost: Host = {
13+
runCommand: () => Promise.resolve(null),
14+
request: (request) =>
15+
invoke("plugin_host_request", {
16+
id: manifest.id,
17+
revision: "bundled",
18+
request,
19+
}),
20+
};
21+
22+
export const firstRunCredential = (signal: AbortSignal): Promise<Credential> =>
23+
browserCredential(bundledHost, signal);

‎src/features/identity/IdentitySetup.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import styles from "./IdentitySetup.module.css";
2020
import { OnboardingWordmark } from "./OnboardingWordmark";
2121
import { OnboardingScreen } from "./OnboardingScreen";
2222

23+
/** Key import/create gate; the app's first launch now uses Welcome instead. */
2324
export function IdentitySetup({
2425
identity,
2526
children,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { isTauri } from "@tauri-apps/api/core";
2+
import {
3+
hasIntegratedWindowControls,
4+
WindowControls,
5+
} from "../../app/shell/WindowControls";
6+
import { macTitleBarDragHandlers } from "../../app/shell/title-bar";
7+
8+
/** Screens shown before the app shell keep the undecorated window draggable. */
9+
export function SetupWindowHeader() {
10+
const macDesktop = isTauri() && /Mac/i.test(navigator.platform);
11+
const integratedWindowControls = hasIntegratedWindowControls();
12+
if (!macDesktop && !integratedWindowControls) return null;
13+
return (
14+
<header
15+
className="-mx-8 -mt-8 mb-8 flex h-14 items-center justify-end px-3"
16+
data-tauri-drag-region={integratedWindowControls || undefined}
17+
{...(macDesktop ? macTitleBarDragHandlers : {})}
18+
>
19+
<WindowControls />
20+
</header>
21+
);
22+
}

‎src/features/identity/Welcome.tsx‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import {
2+
useEffect,
3+
useState,
4+
useSyncExternalStore,
5+
type ReactNode,
6+
} from "react";
7+
import type { Credential } from "../../bundled/builderlab/oauth/browser";
8+
import { firstRunCredential } from "../../bundled/builderlab/oauth/first-run";
9+
import { createOAuthSession } from "../../bundled/builderlab/oauth/session";
10+
import { Button } from "../../shared/design-system/ui/Button";
11+
import { Field } from "../../shared/design-system/ui/Field";
12+
import { Input } from "../../shared/design-system/ui/Input";
13+
import type { Identity } from "./service";
14+
import { SetupWindowHeader } from "./SetupWindowHeader";
15+
16+
/** First-launch gate: renders children once a human key exists on this device. */
17+
export function Welcome({
18+
identity,
19+
children,
20+
connect = firstRunCredential,
21+
}: {
22+
identity: Identity;
23+
children: ReactNode;
24+
connect?: (signal: AbortSignal) => Promise<Credential>;
25+
}) {
26+
const state = useSyncExternalStore(identity.subscribe, identity.snapshot);
27+
const [login] = useState(() => createOAuthSession(connect));
28+
const auth = useSyncExternalStore(login.subscribe, login.snapshot);
29+
useEffect(
30+
() => () => {
31+
if (login.snapshot().status === "pending") login.cancel();
32+
},
33+
[login],
34+
);
35+
if (state.status === "ready") return children;
36+
return (
37+
<main className="p-8" aria-labelledby="welcome-title">
38+
<SetupWindowHeader />
39+
<div className="mx-auto flex max-w-sm flex-col gap-6">
40+
{state.status === "loading" ? (
41+
<>
42+
<h1 id="welcome-title" className="text-title text-primary">
43+
Buzz
44+
</h1>
45+
<p role="status">Opening your saved identity…</p>
46+
</>
47+
) : state.status === "error" ? (
48+
<>
49+
<h1 id="welcome-title" className="text-title text-primary">
50+
Buzz
51+
</h1>
52+
<p role="alert">{state.error}</p>
53+
<Button onClick={() => void identity.retry()}>
54+
Retry secure storage access
55+
</Button>
56+
</>
57+
) : auth.status === "signed-in" ? (
58+
<>
59+
<h1 id="welcome-title" className="text-title text-primary">
60+
Connected to Builderlab
61+
</h1>
62+
<p role="status" className="text-body text-secondary">
63+
{auth.account?.email
64+
? `Signed in as ${auth.account.email}.`
65+
: "Your Builderlab account is connected."}
66+
</p>
67+
</>
68+
) : auth.error ? (
69+
<>
70+
<h1 id="welcome-title" className="text-title text-primary">
71+
Couldn’t connect to Builderlab
72+
</h1>
73+
<p role="alert" className="text-body text-danger">
74+
{auth.error}
75+
</p>
76+
<div>
77+
<Button onClick={login.cancel}>Back</Button>
78+
</div>
79+
</>
80+
) : (
81+
<>
82+
<div>
83+
<h1 id="welcome-title" className="text-title text-primary">
84+
Buzz
85+
</h1>
86+
<p className="mt-2 text-body-lg text-secondary">
87+
Your people, your agents, your projects — all in one place.
88+
</p>
89+
</div>
90+
<div className="flex flex-col gap-3">
91+
<Button
92+
variant={auth.status === "pending" ? "outline" : "primary"}
93+
size="lg"
94+
onClick={() => {
95+
if (auth.status === "pending") login.cancel();
96+
else void login.signIn();
97+
}}
98+
>
99+
{auth.status === "pending"
100+
? "Cancel sign-in"
101+
: "Connect with Builderlab"}
102+
</Button>
103+
{auth.status === "pending" && (
104+
<p role="status" className="text-body-sm text-secondary">
105+
Finish sign-in in your browser, then return to Buzz.
106+
</p>
107+
)}
108+
<Field label="Community URL" disabled>
109+
<Input type="url" placeholder="Coming soon" disabled />
110+
</Field>
111+
<Button size="lg" disabled>
112+
Scan a QR code — Coming soon
113+
</Button>
114+
</div>
115+
</>
116+
)}
117+
</div>
118+
</main>
119+
);
120+
}

0 commit comments

Comments
 (0)