Skip to content

Commit 2e6fe9e

Browse files
tellahoCarl
andauthored
fix(settings): refine claude and typesafe key setup dialogs (#3391)
## Overview **Category:** improvement **User Impact:** Claude and TypeSafe key setup provides focused inputs and direct key-creation links; Claude preserves unsaved drafts when its storage check fails. **Problem:** Initial Claude key entry occupies the Settings pane and repeats its label. Key setup needs concise instructions, consistent spacing, normal Back/Forward behavior and recovery that preserves unsaved drafts. **Solution:** Open initial Claude key entry from Set in Connect Claude, matching TypeSafe. Keep one sentence on the Claude page, console links in both popups and storage reassurance below the fields. Preserve inline replacement and shared credential controls. Keep Claude drafts recoverable through failed storage checks. ## Changes <details> <summary>File changes</summary> **src/bundled/claude-code/ClaudeSettings.tsx** Open Set in Connect Claude and preserve its draft through passive traversal and failed credential reads. Keep the input focused but read-only during verification, with error and Retry inside the dialog; retire setup on explicit dismissal or confirmed saved credentials. **src/bundled/claude-code/auth.tsx** Use the shared key form with storage guidance beneath it, retain its state outside the popup lifetime and forward the caller's read-only verification gate. **src/features/settings/ApiKeyForm.tsx** Add an optional read-only mode that retains keyboard focus. Existing callers keep their default input behavior. **src/bundled/claude-code/index.ts** Register the connect route with the existing Settings navigation owner; history holds only a presentation marker. **src/bundled/claude-code/tabs.tsx** Use compact spacing in existing key-entry dialogs. **src/app/DecisionsSettings.tsx** Provide TypeSafe's direct console link and focus editable inputs while leaving readonly saved-key actions closed. **src/bundled/claude-code/ClaudeSettings.test.tsx** Cover links, storage guidance, pending-save traversal, draft dismissal, focus and read-error recovery with the restored draft preserved through Retry. **src/bundled/claude-code/index.test.ts** Exercise the registered card's open, Back/Forward and dismissal wiring through the real navigation controller. **src/app/DecisionsSettings.test.tsx** Use one real-component journey for TypeSafe's editable and unreadable focus states, dismissal and successful provider selection. **src/bundled/claude-code/tabs.test.tsx** Align setup copy expectations with the separate storage guidance. **src/bundled/typesafe/README.md** Document the key-creation link. **docs/buzz-help.md** Describe both setup dialogs and Claude's history/draft behavior. </details> ## Reproduction steps 1. Open Settings → Claude without a saved key and choose Set. Connect Claude focuses its input and links to Anthropic's API-key settings. 2. Enter a draft, go Back and Forward within the Claude page, and confirm the draft returns. Explicitly close and reopen to confirm it is cleared. A dismissed visit must not reopen through Forward. 3. With Builderlab selected in Settings → Decisions API, choose TypeSafe without a key. Its dialog focuses the input and links to the TypeSafe keys page. Closing retains Builderlab; successful setup completes the switch. 4. With an unreadable saved TypeSafe key, open setup and confirm the saved-key menu stays closed until requested. Replace keeps autofocus on its editable input. 5. During a pending credential recheck, confirm Claude's key input keeps focus but cannot be edited. If secure-storage access fails, the dialog should retain its draft, show the error and offer Retry. After a successful missing-key check, editing resumes with the same draft; finding an existing key closes setup. The subtitle stays neutral while status is unknown. ## Validation - Head `9193df13ad23ecac396523bbc0c5e50f63db0634`: typecheck and all **43 affected tests pass** (18 Claude Settings, 10 TypeSafe, 15 Decisions Settings). Mandatory type/related-unit-test, design, Rust clippy and push checks pass; hosted CI provides broader integration coverage. - The existing routed test cases now hold the read with a deferred promise, verify autofocus and blocked typing, then cover confirmed saved credentials or a failed read followed by Retry with the same draft. No new test cases or browser journeys were added. - Test-runner-only mutations confirm the recovery case fails if read errors dismiss setup, and both pending-read cases fail if the input lock is removed. Production source was never edited for these probes. - Relative to integrated main `ae2a0899a39288920bae2425c7d4f25174e48bd9` (#3365), the PR adds **282 test lines and 301 non-test lines** (48.4% tests). Changed lines total **326 test / 390 non-test** across twelve files. - The current read-error recovery state has component-test evidence. A native walkthrough and new capture remain pending: the previously running debug build and frontend server exited during inspection. No credentials were changed, and no substitute capture was created. - Earlier native captures below document the normal layout, links and input focus, before this recovery change. External link navigation, native replacement/writes, narrow-width, enlarged-text and light-theme checks remain pending. ## Screenshots Actual native app captures, cropped to Settings content. Claude captures are from `05eeebc49`; TypeSafe is from `4ddfd2434`. They document the layout and copy; current traversal and unreadable-key behavior are covered by the tests below. | Claude settings | | --- | | ![Claude page with its one-sentence introduction](https://github.com/user-attachments/assets/5746489a-e797-492a-8826-936add3105af) | | Connect Claude | Connect TypeSafe | | --- | --- | | ![Claude key popup](https://github.com/user-attachments/assets/ce66230c-068d-40c6-a8c5-ca78b376af64) | ![TypeSafe key popup with console link](https://github.com/user-attachments/assets/6c8dfebc-adf0-49b7-96d3-fef8459dff43) | --------- Signed-off-by: Taylor Ho <[email protected]> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@feedback.communities.buzz.xyz>
1 parent 6223ae5 commit 2e6fe9e

12 files changed

Lines changed: 583 additions & 133 deletions

File tree

‎docs/buzz-help.md‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,10 +1233,16 @@ available rather than silently discarding it.
12331233
again; a failed check keeps the previous permissions.
12341234
Claude runs with an Anthropic API key pasted under **Anthropic API key**
12351235
there, once for every local Claude agent. With the Claude plugin enabled,
1236-
**Settings → Claude** starts with a masked, read-only saved key. The
1237-
field opens its **Replace / Remove** menu when focused or clicked;
1238-
the chevron also opens it. **Replace** opens a blank, masked field with small
1239-
**Cancel / Save** buttons inside it. **Save** stores a non-empty replacement
1236+
**Settings → Claude → Set** opens **Connect Claude** to add a key. Back hides
1237+
setup and Forward restores its draft while the Claude page remains open.
1238+
The input keeps focus but is read-only while secure storage is checked. If the
1239+
check fails, the dialog keeps its draft and offers **Retry**; saving waits for
1240+
a successful check. Closing the dialog discards its draft; saving returns to
1241+
the masked, read-only saved key. The field opens its **Replace / Remove** menu
1242+
when focused or clicked; the chevron also opens it. **Replace** opens a blank,
1243+
masked field with small **Cancel / Save** buttons inside it. When adding or replacing a key, **Save**
1244+
stays visible inside the field and is disabled until you enter a key.
1245+
**Save** stores a non-empty replacement
12401246
and returns to the masked view; **Cancel** discards the draft. Settings cannot
12411247
reveal or copy the saved key. The small inline **Save** stays visible and is
12421248
disabled until you enter a key; **Cancel** stays available during replacement.
@@ -1441,7 +1447,8 @@ tab, asks **Discard changes?** first; **Keep editing** keeps them.
14411447
sidebar currently shows are linked. Back from one returns to those details.
14421448
- When Builderlab and TypeSafe are available in **Settings → Decisions API**,
14431449
the **Decision provider** dropdown chooses Builderlab or TypeSafe. Each choice
1444-
uses that provider for requests. Choosing TypeSafe without a key opens a setup dialog.
1450+
uses that provider for requests. Choosing TypeSafe without a key opens
1451+
**Connect TypeSafe**, with a link to create a key in the TypeSafe console.
14451452
Saving the key completes the switch; closing setup keeps the current provider.
14461453
If a selected Builderlab account lacks Decisions API access, the pane explains
14471454
that you can use your own TypeSafe key or contact your account administrator.
@@ -1660,4 +1667,3 @@ occurs. It contains operation metadata, with no draft text or secrets. See
16601667
## Plugin account actions
16611668

16621669
Plugins can add actions to your avatar menu. Profile-related actions may appear just above Settings; other plugin actions appear below it.
1663-

‎src/app/DecisionsSettings.test.tsx‎

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
import "@testing-library/jest-dom/vitest";
33
import { Context } from "@deepseek-ai/cordis";
44
import type { ReactNode } from "react";
5-
import { act, cleanup, render, screen, within } from "@testing-library/react";
5+
import {
6+
act,
7+
cleanup,
8+
render,
9+
screen,
10+
waitFor,
11+
within,
12+
} from "@testing-library/react";
613
import userEvent from "@testing-library/user-event";
714
import { afterEach, expect, it, vi } from "vitest";
815
import {
@@ -12,6 +19,7 @@ import {
1219
type RegisteredProvider,
1320
} from "../features/decisions/service";
1421
import { DecisionsSettings } from "./DecisionsSettings";
22+
import { TypeSafeSettings } from "../bundled/typesafe/TypeSafeSettings";
1523

1624
afterEach(cleanup);
1725

@@ -371,42 +379,73 @@ it("hands focus to the section when the removed provider was the only one", asyn
371379
expect(screen.getByRole("region", { name: "Decisions API" })).toHaveFocus();
372380
});
373381

374-
it("offers Builderlab first and reveals key setup without switching until ready", async () => {
382+
it("opens TypeSafe with editable focus or a closed saved-key menu until ready", async () => {
375383
const user = userEvent.setup();
376384
const builderlab = "block.builderlab/builderlab";
385+
let keyState: "missing" | "unreadable" = "missing";
386+
const credential = {
387+
snapshot: () => keyState,
388+
subscribe: () => () => undefined,
389+
desktop: () => true,
390+
save: async () => {},
391+
clear: async () => {},
392+
};
377393
const decisions = fake(
378394
[
379395
{ key: builderlab, status: "ready" },
380-
{ key: TYPESAFE, status: "needs-setup" },
396+
{
397+
key: TYPESAFE,
398+
status: "needs-setup",
399+
Settings: ({ active }) => (
400+
<TypeSafeSettings
401+
typesafe={credential}
402+
active={active}
403+
grouped={false}
404+
/>
405+
),
406+
},
381407
],
382408
builderlab,
383409
);
384410
render(<DecisionsSettings decisions={decisions} active={() => true} />);
385411
const toggle = screen.getByRole("combobox", { name: "Decision provider" });
386-
expect(toggle).toHaveTextContent("Builderlab");
387-
expect(screen.queryByText("Settings for typesafe")).toBeNull();
388412
await user.click(toggle);
389413
// The Select opens on an animation frame after the pointer press.
390414
await user.click(await screen.findByRole("option", { name: "TypeSafe" }));
391415
expect(toggle).toHaveTextContent("Builderlab");
416+
const dialog = screen.getByRole("dialog", { name: "Connect TypeSafe" });
417+
expect(dialog).toHaveAccessibleDescription(
418+
"Create an API key at console.typesafe.ai and paste it below.",
419+
);
392420
expect(
393-
screen.getByRole("dialog", { name: "Connect TypeSafe" }),
394-
).toBeVisible();
395-
expect(screen.getByText("Settings for typesafe")).toBeVisible();
396-
expect(decisions.chosen()).toBe(builderlab);
397-
await user.click(screen.getByRole("button", { name: "Close" }));
421+
within(dialog).getByRole("link", { name: "console.typesafe.ai" }),
422+
).toHaveAttribute("href", "https://console.typesafe.ai/keys");
423+
await waitFor(() =>
424+
expect(within(dialog).getByLabelText("TypeSafe API key")).toHaveFocus(),
425+
);
426+
await user.click(within(dialog).getByRole("button", { name: "Close" }));
398427
expect(screen.queryByRole("dialog")).toBeNull();
399428
expect(decisions.chosen()).toBe(builderlab);
429+
430+
keyState = "unreadable";
431+
act(() => decisions.setStatus(TYPESAFE, "unconfirmed"));
400432
await user.click(toggle);
401433
await user.click(await screen.findByRole("option", { name: "TypeSafe" }));
434+
const saved = screen.getByRole("dialog", { name: "Connect TypeSafe" });
435+
expect(within(saved).getByLabelText("TypeSafe API key")).toHaveAttribute(
436+
"readonly",
437+
);
438+
await waitFor(() => expect(within(saved).getByRole("link")).toHaveFocus());
439+
expect(screen.queryByRole("menu")).toBeNull();
402440
act(() => decisions.setStatus(TYPESAFE, "ready"));
403441
expect(decisions.chosen()).toBe(TYPESAFE);
404442
expect(screen.queryByRole("dialog")).toBeNull();
405443
expect(toggle).toHaveTextContent("TypeSafe");
406444
await user.click(toggle);
407445
await user.click(await screen.findByRole("option", { name: "Builderlab" }));
408446
expect(decisions.chosen()).toBe(builderlab);
409-
expect(screen.queryByText("Settings for typesafe")).toBeNull();
447+
expect(toggle).toHaveTextContent("Builderlab");
448+
expect(screen.queryByLabelText("TypeSafe API key")).toBeNull();
410449
});
411450

412451
it("explains lost Builderlab access only while it is selected and confirmed unavailable", async () => {

‎src/app/DecisionsSettings.tsx‎

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
WarningCircleIcon,
2020
} from "../shared/design-system/icons";
2121
import { Dialog } from "../shared/design-system/ui/Dialog";
22+
import { Button } from "../shared/design-system/ui/Button";
2223
import { Field } from "../shared/design-system/ui/Field";
2324
import { Header, InlineHeader } from "../shared/design-system/ui/Header";
2425
import { Radio, RadioGroup } from "../shared/design-system/ui/RadioGroup";
@@ -105,6 +106,7 @@ export function DecisionsSettings({
105106
// focus is in this section, then hand it to the selected provider's radio,
106107
// or the section itself, if the update dropped it.
107108
const section = useRef<HTMLElement>(null);
109+
const setupForm = useRef<HTMLDivElement>(null);
108110
const hadFocus = useRef(false);
109111
useEffect(
110112
() =>
@@ -358,34 +360,64 @@ export function DecisionsSettings({
358360
: "Set up Builderlab"
359361
}
360362
description={
361-
selected.key === ownKey.key
362-
? undefined
363-
: "Complete account setup to use Builderlab for decision requests."
363+
selected.key === ownKey.key ? (
364+
<>
365+
Create an API key at{" "}
366+
<Button
367+
variant="link"
368+
size="text"
369+
nativeButton={false}
370+
role="link"
371+
render={
372+
<a
373+
href="https://console.typesafe.ai/keys"
374+
target="_blank"
375+
rel="noreferrer"
376+
/>
377+
}
378+
>
379+
console.typesafe.ai
380+
</Button>{" "}
381+
and paste it below.
382+
</>
383+
) : (
384+
"Complete account setup to use Builderlab for decision requests."
385+
)
364386
}
365387
dismissOnOutsideClick
366388
onOpenChange={(open) => !open && setPicked(undefined)}
389+
initialFocus={
390+
selected.key === ownKey.key
391+
? () =>
392+
setupForm.current?.querySelector<HTMLInputElement>(
393+
"input:not([readonly])",
394+
) ?? null
395+
: undefined
396+
}
367397
finalFocus={() =>
368398
section.current?.querySelector<HTMLElement>('[role="combobox"]') ??
369399
section.current
370400
}
371401
>
372-
<OwnedContribution
373-
entry={selected}
374-
registry={{ snapshot: decisions.providers }}
375-
fallback={<p role="alert">TypeSafe settings are unavailable.</p>}
376-
>
377-
{(entry, owned) => {
378-
const Settings = entry.Settings;
379-
return (
380-
Settings && (
381-
<Settings
382-
active={() => active() && owned()}
383-
grouped={false}
384-
/>
385-
)
386-
);
387-
}}
388-
</OwnedContribution>
402+
<div ref={setupForm}>
403+
<OwnedContribution
404+
entry={selected}
405+
registry={{ snapshot: decisions.providers }}
406+
fallback={<p role="alert">TypeSafe settings are unavailable.</p>}
407+
>
408+
{(entry, owned) => {
409+
const Settings = entry.Settings;
410+
return (
411+
Settings && (
412+
<Settings
413+
active={() => active() && owned()}
414+
grouped={false}
415+
/>
416+
)
417+
);
418+
}}
419+
</OwnedContribution>
420+
</div>
389421
</Dialog>
390422
)}
391423
</section>

0 commit comments

Comments
 (0)