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 2995bd52..93c32aff 100644 --- a/frontend/e2e/wails.spec.ts +++ b/frontend/e2e/wails.spec.ts @@ -163,6 +163,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/components/SelectField.test.tsx b/frontend/src/components/SelectField.test.tsx index f999b31e..55f698a0 100644 --- a/frontend/src/components/SelectField.test.tsx +++ b/frontend/src/components/SelectField.test.tsx @@ -1,4 +1,4 @@ -import { render, screen } from "@testing-library/react"; +import { fireEvent, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { useState } from "react"; import { describe, expect, it } from "vitest"; @@ -102,6 +102,35 @@ describe("SelectField", () => { expect(screen.queryByRole("listbox")).toBeNull(); }); + describe("scrolling while the list is open", () => { + /** jsdom lays nothing out, so the trigger's position is whatever this says. */ + function placeTriggerAt(top: number) { + trigger().getBoundingClientRect = () => ({ top, bottom: top + 36, left: 0, right: 200, width: 200, height: 36, x: 0, y: top, toJSON: () => ({}) }); + } + + // The list is positioned from the trigger, so a scroll that moves the + // trigger leaves it in the wrong place. + it("closes when the scroll moved the trigger", async () => { + render(); + placeTriggerAt(100); + await userEvent.click(trigger()); + placeTriggerAt(40); + fireEvent.scroll(document.body); + expect(screen.queryByRole("listbox")).toBeNull(); + }); + + // Opening the list makes the browser scroll its container to show it. That + // scroll arrives after the list has been placed, and closing on it shut the + // list the moment it opened on a page that was scrolled down. + it("stays open when the scroll left the trigger where it was", async () => { + render(); + placeTriggerAt(100); + await userEvent.click(trigger()); + fireEvent.scroll(document.body); + expect(screen.getByRole("listbox")).toBeTruthy(); + }); + }); + it("jumps to an option by typing its first letters", async () => { render(); trigger().focus(); diff --git a/frontend/src/components/SelectField.tsx b/frontend/src/components/SelectField.tsx index 270cb8f6..268c05fd 100644 --- a/frontend/src/components/SelectField.tsx +++ b/frontend/src/components/SelectField.tsx @@ -50,6 +50,7 @@ export function SelectField({ value, options, onChange, label, id, className = " const [dropUp, setDropUp] = useState(false); const triggerRef = useRef(null); const listRef = useRef(null); + const openedAt = useRef({ top: 0, left: 0 }); const typeahead = useRef({ query: "", at: 0 }); const selectedIndex = options.findIndex((option) => option.value === value); @@ -76,6 +77,7 @@ export function SelectField({ value, options, onChange, label, id, className = " const list = listRef.current; if (!trigger || !list) return; const box = trigger.getBoundingClientRect(); + openedAt.current = { top: box.top, left: box.left }; // The margin covers the 5px CSS offset plus room for the shadow, and gives // the sidebar pickers -- which sit near the bottom edge -- a reason to flip // before the list is merely technically on screen with nothing to spare. @@ -95,15 +97,22 @@ export function SelectField({ value, options, onChange, label, id, className = " const target = event.target as Node; if (!triggerRef.current?.contains(target) && !listRef.current?.contains(target)) close(false); }; - // Any scroll or resize invalidates the measured position above. - const onReflow = () => close(false); + // A resize invalidates the measured position above. A scroll only does if it + // moved the trigger: scroll events are delivered a frame late, so one from + // just before the list opened arrives after it, with the trigger already + // where it was measured. + const onResize = () => close(false); + const onScroll = () => { + const box = triggerRef.current?.getBoundingClientRect(); + if (!box || box.top !== openedAt.current.top || box.left !== openedAt.current.left) close(false); + }; document.addEventListener("pointerdown", onPointerDown); - window.addEventListener("resize", onReflow); - window.addEventListener("scroll", onReflow, true); + window.addEventListener("resize", onResize); + window.addEventListener("scroll", onScroll, true); return () => { document.removeEventListener("pointerdown", onPointerDown); - window.removeEventListener("resize", onReflow); - window.removeEventListener("scroll", onReflow, true); + window.removeEventListener("resize", onResize); + window.removeEventListener("scroll", onScroll, true); }; }, [open]); diff --git a/frontend/src/i18n.tsx b/frontend/src/i18n.tsx index 0eed7405..856619f5 100644 --- a/frontend/src/i18n.tsx +++ b/frontend/src/i18n.tsx @@ -1089,6 +1089,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", "本机环境": "This computer", "系统": "System", "已安装的 Agent": "Agents installed", 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 ? (