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
13 changes: 12 additions & 1 deletion frontend/e2e/wails.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
51 changes: 51 additions & 0 deletions frontend/src/components/EnvironmentSummary.test.tsx
Original file line number Diff line number Diff line change
@@ -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> = {}): 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(<EnvironmentSummary status={status()} selectedAgentIds={[]} />);
// 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(<EnvironmentSummary status={status()} selectedAgentIds={["workbuddy"]} />);
expect(facts()[2]).toBe("uv未安装,当前选择用不到");
rerender(<EnvironmentSummary status={status()} selectedAgentIds={["aider"]} />);
expect(facts()[2]).toBe("uv未安装,当前选择需要");
});

it("reports a machine with nothing installed without a zero", () => {
render(<EnvironmentSummary status={status({ agents: {}, desktopAgents: [] })} selectedAgentIds={[]} />);
expect(facts().at(-1)).toBe("已安装的 Agent还没有");
});
});
52 changes: 52 additions & 0 deletions frontend/src/components/EnvironmentSummary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useI18n } from "../i18n";
import type { StatusResponse } from "../types/api";

const OS_NAMES: Record<string, string> = { 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 (
<div className="environment-summary" role="group" aria-label={t("本机环境")}>
<span>
<small>{t("系统")}</small>
{OS_NAMES[status.platform.os] ?? status.platform.os} · {status.platform.arch}
</span>
{runtimes.map((runtime) => (
<span key={runtime.id} className={!runtime.installed && needed.has(runtime.id) ? "is-needed" : undefined}>
<small>{runtime.name}</small>
{runtime.installed
? runtime.version ? t("版本 {version}", { version: runtime.version }) : t("已安装")
: !selectedAgentIds.length ? t("未安装")
: needed.has(runtime.id) ? t("未安装,当前选择需要")
: t("未安装,当前选择用不到")}
</span>
))}
<span>
<small>{t("已安装的 Agent")}</small>
{installed ? t("{count} 个", { count: installed }) : t("还没有")}
</span>
</div>
);
}
7 changes: 7 additions & 0 deletions frontend/src/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/AgentSelectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -64,6 +65,7 @@ export function AgentSelectionPage() {
{state.statusError ? <div className="notice notice-error">{state.statusError}</div> : null}
{state.status ? (
<>
<EnvironmentSummary status={state.status} selectedAgentIds={state.selectedAgentIds} />
<section className="content-section">
<div className="section-heading">
<div>
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/state/desktopSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() || "";
}
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/state/wizardReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatusResponse["desktopAgents"]>[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");
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/state/wizardReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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) }
: {}),
}
: {}),
};
Expand All @@ -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),
};
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading