diff --git a/frontend/e2e/wails.spec.ts b/frontend/e2e/wails.spec.ts index e43af2d..73a602e 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 0000000..174aa4f --- /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 0000000..b7aa676 --- /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 3fa916b..c9b0072 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 9e97f3f..37e8e0e 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 c804148..9a04f93 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 4e667a9..c4bbe3c 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 e0de10c..28f95de 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 f6f592c..0b11856 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);