From eb25511beafc6c51babc30e946d7e4f20a4eab5d Mon Sep 17 00:00:00 2001 From: yujiezhang-ops Date: Thu, 19 Nov 2026 17:19:37 +0800 Subject: [PATCH 1/2] feat: offer a first task after Codex or Claude Code installs An install ended on a page that said it had finished and nothing else, so a new user had an Agent and no evidence it could do anything. The install task page now offers one small task for Codex and Claude Code: the Agent writes an introduction page in a fresh directory under the system temporary directory, and the page shows that directory, the files written and the run record. A run that fails or writes nothing says so and offers a retry and the Provider page. Nothing is sent until the button is pressed, and the text beside it says the run is billed by the Provider. Each Agent is confined by its own means. Codex runs in its workspace-write sandbox with network access forced off. Claude Code gets the Write tool only and starts in the directory, which needed a working directory on the process runner; it travels on the context like the activity paths do. Saved Provider keys, the compatibility-mode key and key-like environment values are redacted from the run record. A directory nothing was written to is removed; one with files is kept. Other Agents, and every desktop app, are not offered the task: BootAgent has no unattended way to drive them. Refs #258 Co-Authored-By: Claude Sonnet 5 --- cmd/bootagent-desktop/core_e2e.go | 15 ++ .../BootAgent/internal/app/index.ts | 3 + .../BootAgent/internal/app/models.ts | 23 ++ .../internal/binding/agentservice.ts | 16 ++ frontend/e2e/wails.spec.ts | 10 + frontend/src/backend/wails.ts | 4 + .../src/components/FirstTaskSection.test.tsx | 99 ++++++++ frontend/src/components/FirstTaskSection.tsx | 121 +++++++++ frontend/src/components/LogDisclosure.tsx | 4 +- frontend/src/i18n.tsx | 13 + frontend/src/pages/InstallTaskPage.test.tsx | 38 +++ frontend/src/pages/InstallTaskPage.tsx | 5 + frontend/src/styles/app.css | 38 +++ frontend/src/types/api.ts | 2 + internal/app/first_task.go | 232 ++++++++++++++++++ internal/app/first_task_test.go | 228 +++++++++++++++++ internal/binding/services.go | 24 ++ internal/binding/services_test.go | 2 +- internal/process/process.go | 1 + internal/process/process_test.go | 33 +++ internal/process/workdir.go | 28 +++ 21 files changed, 936 insertions(+), 3 deletions(-) create mode 100644 frontend/src/components/FirstTaskSection.test.tsx create mode 100644 frontend/src/components/FirstTaskSection.tsx create mode 100644 internal/app/first_task.go create mode 100644 internal/app/first_task_test.go create mode 100644 internal/process/workdir.go diff --git a/cmd/bootagent-desktop/core_e2e.go b/cmd/bootagent-desktop/core_e2e.go index 74e7ba18..3f0254d0 100644 --- a/cmd/bootagent-desktop/core_e2e.go +++ b/cmd/bootagent-desktop/core_e2e.go @@ -6,6 +6,7 @@ import ( "context" "io" "net/http" + "os" "path/filepath" "strings" "sync" @@ -104,6 +105,20 @@ func (r *e2eRunner) Run(_ context.Context, argv []string, _ map[string]string, _ return result, nil } +// RunPrivateInput plays an Agent given a task on stdin. The first task is the +// only caller that sets a working directory, and what it checks afterwards is +// that a page exists there. +func (r *e2eRunner) RunPrivateInput(ctx context.Context, argv []string, _ map[string]string, _ time.Duration, _ string) (process.Result, error) { + result := process.Result{Args: append([]string(nil), argv...), ExitCode: 0} + if directory := process.WorkingDirectory(ctx); directory != "" { + if err := os.WriteFile(filepath.Join(directory, "index.html"), []byte("BootAgent e2e"), 0o600); err != nil { + return result, err + } + result.Stdout = "Created index.html\n" + } + return result, nil +} + type e2eProviderDoer struct{} func (e2eProviderDoer) Do(request *http.Request) (*http.Response, error) { diff --git a/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/app/index.ts b/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/app/index.ts index f1594f45..ac238d73 100644 --- a/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/app/index.ts +++ b/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/app/index.ts @@ -16,6 +16,9 @@ export type { DesktopAgentProfileResult, DesktopAgentStatus, DetectedConfig, + FirstTaskAgent, + FirstTaskRequest, + FirstTaskResult, InstallRuntimeResult, InstalledMultimodal, MCPAgentApplyResult, diff --git a/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/app/models.ts b/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/app/models.ts index 56d071e3..219b6ceb 100644 --- a/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/app/models.ts +++ b/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/app/models.ts @@ -226,6 +226,29 @@ export interface DetectedConfig { "unreadable": string | null; } +export interface FirstTaskAgent { + "id": string; + "name": string; +} + +export interface FirstTaskRequest { + "agent_id": string; + "locale": string; +} + +/** + * FirstTaskResult describes a run that started. OK is false when the Agent + * failed or wrote nothing, and Directory is empty then: an empty directory is + * removed rather than reported. + */ +export interface FirstTaskResult { + "agent_id": string; + "ok": boolean; + "directory": string; + "files": string[] | null; + "log": string; +} + /** * InstallRuntimeResult reports what the bootstrap did. PathUpdated is separate * from Installed because an already-downloaded runtime may still need its diff --git a/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/binding/agentservice.ts b/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/binding/agentservice.ts index 06dc21ad..1a751f15 100644 --- a/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/binding/agentservice.ts +++ b/frontend/bindings/github.com/MaimoryLab/BootAgent/internal/binding/agentservice.ts @@ -26,6 +26,13 @@ export function ActivateWithConversion(request: $models.AgentConversionRequest): return $Call.ByID(3840302198, request); } +/** + * FirstTaskAgents lists the installed Agents RunFirstTask can drive unattended. + */ +export function FirstTaskAgents(): $CancellablePromise { + return $Call.ByID(1312481620); +} + export function Install(request: $models.InstallRequest): $CancellablePromise<$models.InstallResponse> { return $Call.ByID(1289781782, request); } @@ -46,6 +53,15 @@ export function PreviewUninstall(request: $models.UpdateRequest): $CancellablePr return $Call.ByID(224864709, request); } +/** + * RunFirstTask has an Agent write a small page in a temporary directory of its + * own. It is a billed request to the Agent's model, so the UI calls it only from + * a button the user pressed. + */ +export function RunFirstTask(request: app$0.FirstTaskRequest): $CancellablePromise { + return $Call.ByID(1393373323, request); +} + export function Uninstall(request: $models.UpdateRequest): $CancellablePromise { return $Call.ByID(67868259, request); } diff --git a/frontend/e2e/wails.spec.ts b/frontend/e2e/wails.spec.ts index d0169cbd..a8d477ab 100644 --- a/frontend/e2e/wails.spec.ts +++ b/frontend/e2e/wails.spec.ts @@ -122,6 +122,16 @@ test("onboarding installs one Agent end to end and writes its Profile", async ({ await page.getByRole("button", { name: "开始安装" }).click(); await expect(page.getByRole("heading", { name: "安装完成" })).toBeVisible({ timeout: 60_000 }); + + // The Agent just installed is offered one small task. The test build's runner + // plays the Agent, so what this covers is the path from the button to the + // page it names: the binding, the temporary directory and the file listing. + await expect(page.getByRole("heading", { name: "跑一个小任务试试" })).toBeVisible(); + await page.getByRole("button", { name: "开始", exact: true }).click(); + await expect(page.getByRole("status").filter({ hasText: "Codex 写好了" })).toBeVisible(); + await expect(page.getByRole("list", { name: "生成的文件" })).toHaveText("index.html"); + await expect(page.locator(".first-task-output code")).toContainText("bootagent-first-task-"); + await page.getByRole("button", { name: "进入总览" }).click(); await expect(page.getByRole("heading", { name: "环境总览" })).toBeVisible(); diff --git a/frontend/src/backend/wails.ts b/frontend/src/backend/wails.ts index 428a8539..ec2f5820 100644 --- a/frontend/src/backend/wails.ts +++ b/frontend/src/backend/wails.ts @@ -237,6 +237,10 @@ export const wailsApi = { call(() => AgentService.ActivateWithConversion({ agent_id: agentId, profile_id: profileId })) as CancellableRequest, launchAgent: (agentId: string, workingDirectory = ""): Promise => call(() => AgentService.Launch({ agent_id: agentId, working_directory: workingDirectory })) as Promise, + firstTaskAgents: (): Promise => + call(() => AgentService.FirstTaskAgents()).then((agents) => agents ?? []), + runFirstTask: (agentId: string, locale: string): CancellableRequest => + call(() => AgentService.RunFirstTask({ agent_id: agentId, locale })) as CancellableRequest, migrateConversations: (): Promise => call(() => AgentService.MigrateConversations()) as Promise, uninstallAgent: (agentId: string, allowCrossEnvironment = false, installationId = "", installationIds: string[] = [], removeUserData = false): CancellableRequest => diff --git a/frontend/src/components/FirstTaskSection.test.tsx b/frontend/src/components/FirstTaskSection.test.tsx new file mode 100644 index 00000000..876ad213 --- /dev/null +++ b/frontend/src/components/FirstTaskSection.test.tsx @@ -0,0 +1,99 @@ +import { fireEvent, render, screen, waitFor } from "@testing-library/react"; +import { MemoryRouter } from "react-router-dom"; +import { afterEach, describe, expect, it, vi } from "vitest"; + +import { api } from "../backend/api"; +import { BootAgentApiError } from "../backend/errors"; +import type { FirstTaskResult } from "../types/api"; +import { FirstTaskSection } from "./FirstTaskSection"; + +const DIRECTORY = "/tmp/bootagent-first-task-123"; + +function result(overrides: Partial = {}): FirstTaskResult { + return { agent_id: "codex", ok: true, directory: DIRECTORY, files: ["index.html"], log: "Created index.html", ...overrides }; +} + +async function renderSection(agentId = "codex") { + vi.spyOn(api, "firstTaskAgents").mockResolvedValue([{ id: "codex", name: "Codex" }]); + const page = render(); + await waitFor(() => expect(api.firstTaskAgents).toHaveBeenCalled()); + return page; +} + +describe("FirstTaskSection", () => { + afterEach(() => vi.restoreAllMocks()); + + it("is absent for an Agent that cannot run unattended", async () => { + const run = vi.spyOn(api, "runFirstTask"); + const { container } = await renderSection("opencode"); + + expect(container.innerHTML).toBe(""); + expect(run).not.toHaveBeenCalled(); + }); + + // The run is a billed request to the user's own Provider. It has to be said + // before the button, and nothing may be sent until the button is pressed. + it("says the run is billed and waits to be asked", async () => { + const run = vi.spyOn(api, "runFirstTask").mockResolvedValue(result()); + await renderSection(); + + const start = await screen.findByRole("button", { name: "开始" }); + expect(screen.getByText(/真实的模型调用,由模型服务按它的价格计费/)).toBeTruthy(); + expect(screen.getByText(/只会写入这个目录/)).toBeTruthy(); + expect(run).not.toHaveBeenCalled(); + + fireEvent.click(start); + expect(run).toHaveBeenCalledTimes(1); + expect(run).toHaveBeenCalledWith("codex", "zh-CN"); + }); + + it("shows where the page is and what was written", async () => { + vi.spyOn(api, "runFirstTask").mockResolvedValue(result({ files: ["assets/style.css", "index.html"] })); + await renderSection(); + fireEvent.click(await screen.findByRole("button", { name: "开始" })); + + expect((await screen.findByRole("status")).textContent).toContain("Codex 写好了"); + expect(screen.getByText(DIRECTORY)).toBeTruthy(); + expect(screen.getAllByRole("listitem").map((item) => item.textContent)).toEqual(["assets/style.css", "index.html"]); + // The record is there, behind a disclosure rather than poured onto the page. + expect(screen.queryByText("Created index.html")).toBeNull(); + fireEvent.click(screen.getByRole("button", { name: /查看运行记录/ })); + expect(screen.getByText("Created index.html")).toBeTruthy(); + }); + + it("offers a next step when the Agent wrote nothing", async () => { + const run = vi.spyOn(api, "runFirstTask").mockResolvedValue(result({ ok: false, directory: "", files: [], log: "401 Unauthorized" })); + await renderSection(); + fireEvent.click(await screen.findByRole("button", { name: "开始" })); + + expect((await screen.findByRole("alert")).textContent).toContain("Codex 没有写出任何文件"); + expect(screen.getByRole("button", { name: "检查模型服务" })).toBeTruthy(); + // The reason is in the record, so a failure opens it without being asked. + expect(screen.getByText("401 Unauthorized")).toBeTruthy(); + + fireEvent.click(screen.getByRole("button", { name: "重试" })); + expect(run).toHaveBeenCalledTimes(2); + }); + + // Files exist, so they are shown, but the Agent did not finish cleanly and the + // page may be half written. Calling that a success would misreport it. + it("keeps the files of a run that ended badly without calling it done", async () => { + vi.spyOn(api, "runFirstTask").mockResolvedValue(result({ ok: false })); + await renderSection(); + fireEvent.click(await screen.findByRole("button", { name: "开始" })); + + expect((await screen.findByRole("alert")).textContent).toContain("Codex 没有正常结束"); + expect(screen.getByText(DIRECTORY)).toBeTruthy(); + expect(screen.queryByRole("status")).toBeNull(); + }); + + it("reports a run that could not start", async () => { + vi.spyOn(api, "runFirstTask").mockRejectedValue(new BootAgentApiError("The selected Agent is not installed", "PREREQUISITE_MISSING", false, 400)); + await renderSection(); + fireEvent.click(await screen.findByRole("button", { name: "开始" })); + + expect(await screen.findByRole("alert")).toBeTruthy(); + expect(screen.getByRole("button", { name: "重试" })).toBeTruthy(); + expect(screen.queryByRole("status")).toBeNull(); + }); +}); diff --git a/frontend/src/components/FirstTaskSection.tsx b/frontend/src/components/FirstTaskSection.tsx new file mode 100644 index 00000000..0fd185f2 --- /dev/null +++ b/frontend/src/components/FirstTaskSection.tsx @@ -0,0 +1,121 @@ +import { Copy, ExternalLink, Play, RefreshCw } from "lucide-react"; +import { useEffect, useRef, useState } from "react"; +import { useNavigate } from "react-router-dom"; + +import { api, failureLine, isCancellationError } from "../backend/api"; +import { useI18n } from "../i18n"; +import type { FirstTaskResult } from "../types/api"; +import { copyToClipboard } from "../utils/clipboard"; +import { LogDisclosure } from "./LogDisclosure"; + +/** + * Offers one small, real task to an Agent that has just been installed: it + * writes a page in a temporary directory of its own. Rendered only for Agents + * the backend can drive unattended, so it is absent rather than disabled for + * the rest. + * + * Nothing is sent until the button is pressed: the run is a billed request. + */ +export function FirstTaskSection({ agentId }: { agentId: string }) { + const { t, locale } = useI18n(); + const navigate = useNavigate(); + // Empty until the backend confirms it can drive this Agent, and then its name. + const [agentName, setAgentName] = useState(""); + const [running, setRunning] = useState(false); + const [result, setResult] = useState(null); + const [failure, setFailure] = useState(""); + const [copied, setCopied] = useState(false); + const request = useRef | null>(null); + + useEffect(() => { + let active = true; + void api.firstTaskAgents() + .then((agents) => { if (active) setAgentName(agents.find((agent) => agent.id === agentId)?.name ?? ""); }) + .catch(() => {}); + return () => { active = false; }; + }, [agentId]); + // Leaving the page ends the run: nobody would see its result, and it would + // keep spending on the user's account. + useEffect(() => () => { void request.current?.cancel?.(); }, []); + + if (!agentName) return null; + + const run = async () => { + setRunning(true); + setResult(null); + setFailure(""); + setCopied(false); + const pending = api.runFirstTask(agentId, locale); + request.current = pending; + try { + setResult(await pending); + } catch (error) { + if (!isCancellationError(error)) setFailure(failureLine(error, t("小任务没能运行"), t)); + } finally { + request.current = null; + setRunning(false); + } + }; + + const files = result?.files ?? []; + const problem = failure + || (result && !result.ok + ? files.length + ? t("{agent} 没有正常结束,下面的文件可能不完整", { agent: agentName }) + : t("{agent} 没有写出任何文件", { agent: agentName }) + : ""); + const finished = Boolean(result || failure); + + return ( +
+

{t("跑一个小任务试试")}

+

{t("让 {agent} 在一个临时目录里写一个介绍页,只会写入这个目录。这是真实的模型调用,由模型服务按它的价格计费", { agent: agentName })}

+ {result?.ok ? ( +
+ {t("{agent} 写好了,文件在下面这个目录", { agent: agentName })} +
+ ) : null} + {problem ?
{problem}
: null} + {result?.directory ? ( +
+ {result.directory} + +
    + {files.map((file) =>
  • {file}
  • )} +
+
+ ) : null} +
+ {running ? ( + <> + + + + ) : !finished ? ( + + ) : problem ? ( + <> + + + + ) : null} +
+ {result?.log ? : null} +
+ ); +} diff --git a/frontend/src/components/LogDisclosure.tsx b/frontend/src/components/LogDisclosure.tsx index 26422610..7cf6fb3c 100644 --- a/frontend/src/components/LogDisclosure.tsx +++ b/frontend/src/components/LogDisclosure.tsx @@ -3,7 +3,7 @@ import { useEffect, useState } from "react"; import { useI18n } from "../i18n"; -export function LogDisclosure({ log, open: openByParent = false, showEmpty = false }: { log: string; open?: boolean; showEmpty?: boolean }) { +export function LogDisclosure({ log, open: openByParent = false, showEmpty = false, label }: { log: string; open?: boolean; showEmpty?: boolean; label?: string }) { const { t } = useI18n(); const [open, setOpen] = useState(openByParent); useEffect(() => { @@ -14,7 +14,7 @@ export function LogDisclosure({ log, open: openByParent = false, showEmpty = fal
{open ?
{log}
: null} diff --git a/frontend/src/i18n.tsx b/frontend/src/i18n.tsx index 3fa916b1..9bae3114 100644 --- a/frontend/src/i18n.tsx +++ b/frontend/src/i18n.tsx @@ -1082,6 +1082,19 @@ 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", + "跑一个小任务试试": "Try one small task", + // Says who bills and stops there, like the key explainer: no amount, no "small". + "让 {agent} 在一个临时目录里写一个介绍页,只会写入这个目录。这是真实的模型调用,由模型服务按它的价格计费": "{agent} writes an introduction page in a temporary directory and writes nowhere else. This is a real model call, billed by the provider at its prices", + "开始": "Start", + "正在运行,通常需要一两分钟": "Running, usually a minute or two", + "{agent} 写好了,文件在下面这个目录": "{agent} is done. The files are in the directory below", + "{agent} 没有正常结束,下面的文件可能不完整": "{agent} did not finish cleanly, so the files below may be incomplete", + "{agent} 没有写出任何文件": "{agent} did not write any file", + "小任务没能运行": "The task could not run", + "复制路径": "Copy path", + "生成的文件": "Files written", + "检查模型服务": "Check the provider", + "查看运行记录": "View the run record", } as const; export type Locale = "zh-CN" | "en"; diff --git a/frontend/src/pages/InstallTaskPage.test.tsx b/frontend/src/pages/InstallTaskPage.test.tsx index 966ec8bd..bea73be8 100644 --- a/frontend/src/pages/InstallTaskPage.test.tsx +++ b/frontend/src/pages/InstallTaskPage.test.tsx @@ -4,6 +4,7 @@ import { MemoryRouter, Route, Routes } from "react-router-dom"; import { describe, expect, it, vi } from "vitest"; // No I18nProvider, so translate() returns the Chinese keys unchanged. +import { api } from "../backend/api"; import { InstallTaskPage } from "./InstallTaskPage"; const mockUseTaskCenter = vi.hoisted(() => vi.fn(() => ({ tasks: [], cancelTask: vi.fn(), dismissTask: vi.fn(), progress: {}, running: {} }))); @@ -69,3 +70,40 @@ describe("InstallTaskPage update route", () => { expect(screen.getByRole("region", { name: "任务时间线" })).toBeTruthy(); }); }); + +// An install ends on this page, so it is where the first task has to be offered. +describe("InstallTaskPage first task", () => { + function renderTask(kind: "install" | "update", state: "success" | "failure") { + mockUseTaskCenter.mockReturnValue({ + tasks: [{ + id: `${kind}:codex`, kind, target: "codex", title: "安装 Codex", route: `/tasks/${kind}/codex`, + progressTarget: "", state, message: "", startedAt: 1, events: [], + }], + cancelTask: vi.fn(), dismissTask: vi.fn(), progress: {}, running: {}, + } as never); + render( + + } /> + , + ); + } + + it("is offered once an Agent has installed", async () => { + const agents = vi.spyOn(api, "firstTaskAgents").mockResolvedValue([{ id: "codex", name: "Codex" }]); + renderTask("install", "success"); + + expect(await screen.findByRole("heading", { name: "跑一个小任务试试" })).toBeTruthy(); + agents.mockRestore(); + }); + + // An update leaves an Agent the user already knows, and a failed install + // leaves nothing to run. Neither asks the backend at all. + it("is not offered after an update or a failed install", () => { + const agents = vi.spyOn(api, "firstTaskAgents").mockResolvedValue([{ id: "codex", name: "Codex" }]); + renderTask("update", "success"); + renderTask("install", "failure"); + + expect(agents).not.toHaveBeenCalled(); + agents.mockRestore(); + }); +}); diff --git a/frontend/src/pages/InstallTaskPage.tsx b/frontend/src/pages/InstallTaskPage.tsx index 65c1003b..a61e170c 100644 --- a/frontend/src/pages/InstallTaskPage.tsx +++ b/frontend/src/pages/InstallTaskPage.tsx @@ -1,6 +1,7 @@ import { useLocation, useNavigate, useParams } from "react-router-dom"; import { DownloadProgress } from "../components/DownloadProgress"; +import { FirstTaskSection } from "../components/FirstTaskSection"; import { LogDisclosure } from "../components/LogDisclosure"; import { PageScaffold } from "../components/PageScaffold"; import { useI18n } from "../i18n"; @@ -80,6 +81,10 @@ export function InstallTaskPage() {
) : null} {task.log ? : null} + {/* This is the page an install ends on, so it is where the new Agent is + first offered something to do. The section hides itself for an Agent + that cannot run unattended, which covers every desktop app. */} + {kind === "install" && task.state === "success" ? : null} {task.state !== "running" && task.action ? (