From 099404ea6c5a6e0cfb1d68f8bbbae9e45a27da65 Mon Sep 17 00:00:00 2001 From: yujiezhang-ops Date: Thu, 19 Nov 2026 16:31:37 +0800 Subject: [PATCH 1/2] feat: show the machine and pre-select an Agent on a first run The Agent step opened with nothing chosen and nothing said about the machine, so a new user met a list of eleven products and a disabled Continue button. A first run now arrives with WorkBuddy selected on the desktop tab, which stays the default tab. It is only a starting point: any other row can be picked, a status refresh does not put it back, and a machine that has been set up before gets no pre-selection. Above the list, a summary names the system, each runtime and how many Agents are installed. A missing runtime says whether the current choice needs it, because a desktop Agent needs none and a bare "not installed" would read as a fault. Refs #258 Co-Authored-By: Claude Sonnet 5 --- frontend/e2e/wails.spec.ts | 13 ++++- .../components/EnvironmentSummary.test.tsx | 51 ++++++++++++++++++ .../src/components/EnvironmentSummary.tsx | 52 +++++++++++++++++++ frontend/src/i18n.tsx | 7 +++ frontend/src/pages/AgentSelectionPage.tsx | 2 + frontend/src/state/desktopSetup.ts | 16 ++++++ frontend/src/state/wizardReducer.test.ts | 32 ++++++++++++ frontend/src/state/wizardReducer.ts | 12 +++++ frontend/src/styles/app.css | 15 ++++++ 9 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/EnvironmentSummary.test.tsx create mode 100644 frontend/src/components/EnvironmentSummary.tsx diff --git a/frontend/e2e/wails.spec.ts b/frontend/e2e/wails.spec.ts index d0169cbd..93a4f1ca 100644 --- a/frontend/e2e/wails.spec.ts +++ b/frontend/e2e/wails.spec.ts @@ -1,6 +1,17 @@ import { expect, test, type Locator } from "@playwright/test"; -// Every test addresses a route directly. "/" is a decision, not a page: on a +// The one test that lands on "/", and it has to run first: a first run is a home +// nothing has written to yet, which stops being true as soon as any test saves. +test("a first run opens the wizard with an Agent already chosen", async ({ page }) => { + await page.goto("/"); + await expect(page.getByRole("heading", { name: "选择 Agent", level: 1 })).toBeVisible(); + await expect(page.getByRole("group", { name: "本机环境" })).toContainText("macOS"); + // exact, because "选择 WorkBuddy AI" is the row below it. + await expect(page.getByLabel("选择 WorkBuddy", { exact: true })).toBeChecked(); + await expect(page.getByRole("button", { name: "继续" })).toBeEnabled(); +}); + +// Every other test addresses a route directly. "/" is a decision, not a page: on a // home without ~/.bootagent it opens onboarding, so landing there would make // these tests depend on whichever one ran first and wrote state. // selectOption is gone from these tests: the pickers are custom listboxes now, diff --git a/frontend/src/components/EnvironmentSummary.test.tsx b/frontend/src/components/EnvironmentSummary.test.tsx new file mode 100644 index 00000000..174aa4f5 --- /dev/null +++ b/frontend/src/components/EnvironmentSummary.test.tsx @@ -0,0 +1,51 @@ +import { render, screen } from "@testing-library/react"; +import { describe, expect, it } from "vitest"; + +import type { StatusResponse } from "../types/api"; +import { EnvironmentSummary } from "./EnvironmentSummary"; + +function runtime(id: string, name: string, installed: boolean, version = "") { + return { + id, name, command: id, installed, version, lockedVersion: "1.0.0", managed: false, supported: true, + note: "", license: "", licenseUrl: "", source: "", installPath: "", + }; +} + +function status(overrides: Partial = {}): StatusResponse { + return { + platform: { os: "macos", arch: "arm64", shell: "zsh" }, + runtimes: [runtime("node", "Node.js", true, "22.1.0"), runtime("uv", "uv", false)], + capabilities: { canInstall: {}, missingRuntime: { aider: "uv" }, supportedAgentIds: [] }, + catalog: [{ id: "codex" }, { id: "aider" }], + agents: { codex: { installed: true }, aider: { installed: false }, workbuddy: { installed: true } }, + desktopAgents: [{ id: "workbuddy", installed: true }, { id: "zcode", installed: false }], + ...overrides, + } as unknown as StatusResponse; +} + +function facts() { + return [...screen.getByRole("group", { name: "本机环境" }).children].map((item) => item.textContent); +} + +describe("EnvironmentSummary", () => { + it("names the system, each runtime and how many Agents are installed", () => { + render(); + // Two installed, not three: workbuddy is in agents as the owner of the + // desktop app's profile, and counting that map would count it twice. + expect(facts()).toEqual(["系统macOS · arm64", "Node.js版本 22.1.0", "uv未安装", "已安装的 Agent2 个"]); + }); + + // The default arrival is a desktop Agent, which needs no runtime. A bare "not + // installed" beside it would read as a fault on a machine that has none. + it("says whether the current selection needs a missing runtime", () => { + const { rerender } = render(); + expect(facts()[2]).toBe("uv未安装,当前选择用不到"); + rerender(); + expect(facts()[2]).toBe("uv未安装,当前选择需要"); + }); + + it("reports a machine with nothing installed without a zero", () => { + render(); + expect(facts().at(-1)).toBe("已安装的 Agent还没有"); + }); +}); diff --git a/frontend/src/components/EnvironmentSummary.tsx b/frontend/src/components/EnvironmentSummary.tsx new file mode 100644 index 00000000..b7aa676e --- /dev/null +++ b/frontend/src/components/EnvironmentSummary.tsx @@ -0,0 +1,52 @@ +import { useI18n } from "../i18n"; +import type { StatusResponse } from "../types/api"; + +const OS_NAMES: Record = { macos: "macOS", windows: "Windows", linux: "Linux" }; + +interface EnvironmentSummaryProps { + status: StatusResponse; + selectedAgentIds: string[]; +} + +/** + * What was found on this machine, shown before the first choice. A missing + * runtime is only a problem for an Agent that installs through it, so each one + * says whether the current selection needs it instead of reading as a fault. + */ +export function EnvironmentSummary({ status, selectedAgentIds }: EnvironmentSummaryProps) { + const { t } = useI18n(); + const runtimes = (status.runtimes ?? []).filter((runtime) => runtime.supported || runtime.installed); + const needed = new Set( + selectedAgentIds + .filter((id) => !status.agents?.[id]?.installed) + .map((id) => status.capabilities.missingRuntime?.[id]) + .filter(Boolean), + ); + // Counted from the two lists the page shows. status.agents also holds the + // profile owners of desktop Agents, which would count those twice. + const installed = (status.catalog ?? []).filter((item) => status.agents?.[item.id]?.installed).length + + (status.desktopAgents ?? []).filter((app) => app.installed).length; + + return ( +
+ + {t("系统")} + {OS_NAMES[status.platform.os] ?? status.platform.os} · {status.platform.arch} + + {runtimes.map((runtime) => ( + + {runtime.name} + {runtime.installed + ? runtime.version ? t("版本 {version}", { version: runtime.version }) : t("已安装") + : !selectedAgentIds.length ? t("未安装") + : needed.has(runtime.id) ? t("未安装,当前选择需要") + : t("未安装,当前选择用不到")} + + ))} + + {t("已安装的 Agent")} + {installed ? t("{count} 个", { count: installed }) : t("还没有")} + +
+ ); +} diff --git a/frontend/src/i18n.tsx b/frontend/src/i18n.tsx index 3fa916b1..c9b00723 100644 --- a/frontend/src/i18n.tsx +++ b/frontend/src/i18n.tsx @@ -1082,6 +1082,13 @@ const english = { "在 Agent 的配置页选择配置模版时会自动开启": "Turns on by itself when you choose a profile on an Agent's page", "开启后这些 Agent 才能使用": "These Agents work once it is on", "更换": "Change", + "本机环境": "This computer", + "系统": "System", + "已安装的 Agent": "Agents installed", + "{count} 个": "{count}", + "还没有": "None yet", + "未安装,当前选择需要": "Not installed, and this choice needs it", + "未安装,当前选择用不到": "Not installed, and this choice does not need it", } as const; export type Locale = "zh-CN" | "en"; diff --git a/frontend/src/pages/AgentSelectionPage.tsx b/frontend/src/pages/AgentSelectionPage.tsx index 9e97f3f7..37e8e0e3 100644 --- a/frontend/src/pages/AgentSelectionPage.tsx +++ b/frontend/src/pages/AgentSelectionPage.tsx @@ -4,6 +4,7 @@ import { useNavigate } from "react-router-dom"; import { AgentRow } from "../components/AgentRow"; import { EditionTag } from "../components/EditionTag"; +import { EnvironmentSummary } from "../components/EnvironmentSummary"; import { AgentIcon } from "../components/icons/agents"; import { PageScaffold } from "../components/PageScaffold"; import { RuntimePrompt } from "../components/RuntimePrompt"; @@ -64,6 +65,7 @@ export function AgentSelectionPage() { {state.statusError ?
{state.statusError}
: null} {state.status ? ( <> +
diff --git a/frontend/src/state/desktopSetup.ts b/frontend/src/state/desktopSetup.ts index c8041486..9a04f932 100644 --- a/frontend/src/state/desktopSetup.ts +++ b/frontend/src/state/desktopSetup.ts @@ -15,6 +15,22 @@ export function selectedDesktopApp(status: StatusResponse, selectedAgentIds: str return desktopApps(status).find((app) => app.id === selected); } +const FIRST_RUN_DESKTOP_AGENT = "workbuddy"; + +/** + * The desktop Agent a first run arrives on, or "" for none. + * + * Only a machine that has never been set up gets one: someone returning to the + * wizard came to add a particular Agent, and a pre-ticked row would be a choice + * made for them. A platform the app does not run on gets none either, because + * its row is disabled and could not be un-ticked by picking another. + */ +export function firstRunDesktopAgent(status: StatusResponse | null): string { + if (!status?.firstRun) return ""; + const app = desktopApps(status).find((item) => item.id === FIRST_RUN_DESKTOP_AGENT); + return app?.supported ? app.id : ""; +} + export function desktopProtocol(app: DesktopAgentStatus): string { return app.protocol?.trim() || ""; } diff --git a/frontend/src/state/wizardReducer.test.ts b/frontend/src/state/wizardReducer.test.ts index 4e667a9f..c4bbe3c1 100644 --- a/frontend/src/state/wizardReducer.test.ts +++ b/frontend/src/state/wizardReducer.test.ts @@ -37,6 +37,38 @@ describe("wizardReducer", () => { expect(initialWizardState.setupKind).toBe("desktop"); }); + describe("the Agent a first run arrives on", () => { + const workbuddy = { + id: "workbuddy", name: "WorkBuddy", installed: false, supported: true, + version: null, source: "unknown", protocol: "openai", profileAgentId: "workbuddy", profileId: null, + } satisfies NonNullable[number]; + const firstRun = { ...status, firstRun: true, desktopAgents: [workbuddy] } satisfies StatusResponse; + + it("is WorkBuddy, so a new user can continue without knowing the list", () => { + const loaded = wizardReducer(initialWizardState, { type: "STATUS_LOADED", status: firstRun }); + expect(loaded.selectedAgentIds).toEqual(["workbuddy"]); + // Returning to the desktop tab from the CLI one is the same arrival. + const cli = wizardReducer(loaded, { type: "START_SETUP" }); + expect(cli.selectedAgentIds).toEqual([]); + expect(wizardReducer(cli, { type: "START_DESKTOP_SETUP" }).selectedAgentIds).toEqual(["workbuddy"]); + }); + + it("can be changed, and a status refresh does not change it back", () => { + let state = wizardReducer(initialWizardState, { type: "STATUS_LOADED", status: firstRun }); + state = wizardReducer(state, { type: "SELECT_AGENT", agentId: "zcode" }); + state = wizardReducer(state, { type: "STATUS_LOADED", status: { ...firstRun } }); + expect(state.selectedAgentIds).toEqual(["zcode"]); + }); + + it("is nothing once the machine has been set up, or where WorkBuddy cannot run", () => { + const returning = wizardReducer(initialWizardState, { type: "STATUS_LOADED", status: { ...firstRun, firstRun: false } }); + expect(returning.selectedAgentIds).toEqual([]); + const unsupported = { ...firstRun, desktopAgents: [{ ...workbuddy, supported: false }] }; + expect(wizardReducer(initialWizardState, { type: "STATUS_LOADED", status: unsupported }).selectedAgentIds).toEqual([]); + expect(wizardReducer(initialWizardState, { type: "STATUS_LOADED", status: { ...firstRun, desktopAgents: [] } }).selectedAgentIds).toEqual([]); + }); + }); + it("loads status and reports status errors", () => { let state = wizardReducer(initialWizardState, { type: "STATUS_LOADING" }); expect(state.statusState).toBe("loading"); diff --git a/frontend/src/state/wizardReducer.ts b/frontend/src/state/wizardReducer.ts index e0de10cb..28f95de7 100644 --- a/frontend/src/state/wizardReducer.ts +++ b/frontend/src/state/wizardReducer.ts @@ -8,6 +8,7 @@ import type { InstallOutput, } from "../types/api"; import { userProviders } from "./conversion"; +import { firstRunDesktopAgent } from "./desktopSetup"; import { byProviderCreatedAt, preferProviderWithKey } from "./ranking"; export type AsyncState = "idle" | "loading" | "success" | "error"; @@ -114,6 +115,11 @@ function providerDefaultModel(status: StatusResponse | null, provider: ProviderI return status?.providers[provider]?.default_model || ""; } +function arrivalSelection(status: StatusResponse | null): string[] { + const agent = firstRunDesktopAgent(status); + return agent ? [agent] : []; +} + export type WizardAction = | { type: "STATUS_LOADING" } | { type: "STATUS_LOADED"; status: StatusResponse } @@ -197,6 +203,11 @@ export function wizardReducer(state: WizardState, action: WizardAction): WizardS ? { provider: latestProvider(action.status), ...(state.model ? {} : { model: providerDefaultModel(action.status, latestProvider(action.status)) }), + // Seeded here for the same reason: the list this picks from only + // exists once the status has arrived. + ...(state.setupKind === "desktop" && !state.selectedAgentIds.length + ? { selectedAgentIds: arrivalSelection(action.status) } + : {}), } : {}), }; @@ -211,6 +222,7 @@ export function wizardReducer(state: WizardState, action: WizardAction): WizardS statusState: state.statusState, statusError: state.statusError, setupKind: "desktop", + selectedAgentIds: arrivalSelection(state.status), provider, model: providerDefaultModel(state.status, provider), }; diff --git a/frontend/src/styles/app.css b/frontend/src/styles/app.css index f6f592c4..0b11856b 100644 --- a/frontend/src/styles/app.css +++ b/frontend/src/styles/app.css @@ -802,6 +802,21 @@ grid-template-rows: auto auto minmax(0, 1fr); } +.environment-summary { + flex: 0 0 auto; + display: flex; + flex-wrap: wrap; + gap: 6px 24px; + padding: 10px 14px; + border: 1px solid var(--border); + border-radius: var(--radius-control); + font-size: 12px; +} + +.environment-summary > span { display: inline-flex; align-items: baseline; gap: 6px; } +.environment-summary small { color: var(--text-secondary); font-size: 11px; } +.environment-summary > .is-needed { color: var(--orange); } + .disclosure-section { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); From 4f0f4e57f657e4398263f0ba0d2d32d03ee69a6c Mon Sep 17 00:00:00 2001 From: yujiezhang-ops Date: Fri, 20 Nov 2026 11:14:21 +0800 Subject: [PATCH 2/2] test: wait for the saved state, not the save in flight The Claude Desktop e2e test asserted that the "save changes" button was disabled after clicking it. That button is only disabled while the request is in flight; once the address is saved and nothing uses compatibility mode, the primary action becomes "turn on compatibility mode" and the button the test looked for no longer exists. A save that finished before the first poll failed the test, and the next test with it, since it relies on what this one sets up. Assert the state the page settles in instead. Co-Authored-By: Claude Sonnet 5 --- frontend/e2e/wails.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/e2e/wails.spec.ts b/frontend/e2e/wails.spec.ts index 93a4f1ca..73a602ed 100644 --- a/frontend/e2e/wails.spec.ts +++ b/frontend/e2e/wails.spec.ts @@ -227,7 +227,10 @@ test("Claude Desktop adapts a Chat Completions Profile after one confirmation", await page.getByRole("button", { name: "高级设置" }).click(); await page.getByLabel("监听地址").fill("127.0.0.1:34125"); await page.getByRole("button", { name: "保存更改" }).click(); - await expect(page.getByRole("button", { name: "保存更改" })).toBeDisabled(); + // Nothing uses compatibility mode yet, so once the address is saved the + // primary action goes back to turning it on. The save button is only disabled + // while the request is in flight, which a fast save finishes before this runs. + await expect(page.getByRole("button", { name: "开启兼容模式" })).toBeDisabled(); await page.goto("/#/agents/claude-desktop"); await page.getByLabel("选择 Claude Desktop E2E Chat").check();