Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix: recover onboarding when selected agent is unavailable
Gusdbd42af64b45
diff --git a/src/web/src/components/community/onboarding/onboarding-machine-dialog.dom.test.ts b/src/web/src/components/community/onboarding/onboarding-machine-dialog.dom.test.tsindex 77cc1b606..305a8e00e 100644--- a/src/web/src/components/community/onboarding/onboarding-machine-dialog.dom.test.ts+++ b/src/web/src/components/community/onboarding/onboarding-machine-dialog.dom.test.ts@@ -20,6 +20,7 @@ vi.mock("@/components/community/machines/pair-machine-sheet", () => ({PairMachineSteps: vi.fn(() => null),}))vi.mock("@/components/ui/button", () => ({+ buttonVariants: () => "",Button: ({ children, ...props }: React.PropsWithChildren<Record<string, unknown>>) =>React.createElement("button", props, children),}))@@ -34,6 +35,7 @@ vi.mock("@/components/ui/dialog", () => ({}))import { OnboardingMachineDialog } from "./onboarding-machine-dialog"+import { tid } from "@/lib/community/testids"import { PairMachineSteps } from "@/components/community/machines/pair-machine-sheet"const mockedSteps = vi.mocked(PairMachineSteps)@@ -80,14 +82,86 @@ describe("OnboardingMachineDialog", () => {it.each([{ label: "wrong harness", availableRuntimes: [{ id: "claude-code", status: "healthy" as const }] },- { label: "unhealthy harness", availableRuntimes: [{ id: "codex", status: "unhealthy" as const }] },+ { label: "unhealthy harness", availableRuntimes: [{ id: "codex", status: "unhealthy" as const, lastError: "ENOENT" }] },{ label: "missing harness", availableRuntimes: [] },])("waits when the online machine has a $label", ({ availableRuntimes }) => {mocks.machines = [{ id: "machine-1", hostname: "host", status: "online", availableRuntimes }]mocks.apiFetch.mockReturnValue(new Promise(() => undefined))const input = props()- render(React.createElement(OnboardingMachineDialog, input))+ const view = render(React.createElement(OnboardingMachineDialog, input))+ expect(input.onConnected).not.toHaveBeenCalled()+ expect(view.getByTestId(tid.onboardingRuntimeUnavailable)).toHaveTextContent("host is connected")+ expect(view.getByTestId(tid.onboardingRuntimeUnavailable)).toHaveTextContent("Codex isn’t ready")+ expect(view.getByTestId(tid.onboardingRuntimeUnavailable)).toHaveTextContent("restart the Alook daemon")+ const support = view.getByTestId(tid.onboardingJoinSupport)+ expect(support).toHaveAccessibleName("Need Help")+ expect(view.getByTestId(tid.onboardingRuntimeUnavailable)).toHaveTextContent(+ availableRuntimes.find((runtime) => runtime.id === "codex")?.lastError || "The selected agent wasn’t detected as available.",+ )+ expect(mockedSteps).not.toHaveBeenCalled()+ expect(mocks.apiFetch).not.toHaveBeenCalled()+ expect(view.getByRole("button", { name: "Continue", hidden: true })).toBeDisabled()+ fireEvent.click(view.getByTestId(tid.onboardingChooseHarness))+ expect(input.onChooseAnotherHarness).toHaveBeenCalledOnce()+ })++ it("advances once when an unavailable runtime becomes healthy", () => {+ mocks.machines = [{ id: "machine-1", hostname: "host", status: "online", availableRuntimes: [{ id: "codex", status: "unhealthy" }] }]+ const input = props()+ const view = render(React.createElement(OnboardingMachineDialog, input))+ expect(view.getByTestId(tid.onboardingRuntimeUnavailable)).toBeInTheDocument()+ mocks.machines = [{ ...mocks.machines[0], availableRuntimes: [{ id: "codex", status: "healthy" }] }]+ view.rerender(React.createElement(OnboardingMachineDialog, input))+ expect(view.queryByTestId(tid.onboardingRuntimeUnavailable)).not.toBeInTheDocument()+ expect(input.onConnected).toHaveBeenCalledExactlyOnceWith("machine-1")+ view.rerender(React.createElement(OnboardingMachineDialog, input))+ expect(input.onConnected).toHaveBeenCalledOnce()+ expect(mocks.apiFetch).not.toHaveBeenCalled()+ })++ it("uses a matching machine even if the first online machine has no usable runtime", () => {+ mocks.machines = [+ { id: "other", hostname: "other", status: "online", availableRuntimes: [] },+ { id: "matching", hostname: "ready", status: "online", availableRuntimes: [{ id: "codex", status: "healthy" }] },+ ]+ const input = props()+ const view = render(React.createElement(OnboardingMachineDialog, input))+ expect(input.onConnected).toHaveBeenCalledExactlyOnceWith("matching")+ expect(view.queryByTestId(tid.onboardingRuntimeUnavailable)).not.toBeInTheDocument()+ expect(mockedSteps.mock.calls.at(-1)![0].connectedHostname).toBe("ready")+ })++ it("joins Support directly and opens the joined server without leaving setup", async () => {+ mocks.machines = [{ id: "machine-1", hostname: "host", status: "online", availableRuntimes: [] }]+ let resolveJoin!: (value: { serverId: string }) => void+ mocks.apiFetch.mockReturnValue(new Promise((resolve) => { resolveJoin = resolve }))+ const input = props()+ const view = render(React.createElement(OnboardingMachineDialog, input))+ fireEvent.click(view.getByTestId(tid.onboardingJoinSupport))+ await act(async () => { await vi.advanceTimersByTimeAsync(0) })+ expect(mocks.apiFetch).toHaveBeenCalledOnce()+ expect(mocks.apiFetch).toHaveBeenCalledWith("/api/community/invites/nC7ax53lwm/join", expect.objectContaining({ method: "POST" }))+ expect(view.getByTestId(tid.onboardingJoinSupport)).toBeDisabled()+ await act(async () => { resolveJoin({ serverId: "support" }); await vi.advanceTimersByTimeAsync(0) })+ expect(view.getByTestId(tid.onboardingOpenSupport)).toHaveAttribute("href", "/c/channels/support")+ expect(view.getByTestId(tid.onboardingOpenSupport)).toHaveAttribute("target", "_blank")+ expect(view.getByTestId(tid.onboardingRuntimeUnavailable)).toBeInTheDocument()expect(input.onConnected).not.toHaveBeenCalled()+ expect(input.onManageMachines).not.toHaveBeenCalled()+ })++ it("shows a failed Support join and lets the user retry", async () => {+ mocks.machines = [{ id: "machine-1", hostname: "host", status: "online", availableRuntimes: [] }]+ mocks.apiFetch.mockRejectedValueOnce(new Error("INVITE_EXPIRED")).mockResolvedValueOnce({ serverId: "support" })+ const view = render(React.createElement(OnboardingMachineDialog, props()))+ fireEvent.click(view.getByTestId(tid.onboardingJoinSupport))+ await act(async () => { await vi.advanceTimersByTimeAsync(0) })+ expect(view.getByRole("alert", { hidden: true })).toHaveTextContent("Couldn’t join Alook Support")+ expect(view.getByTestId(tid.onboardingJoinSupport)).toBeEnabled()+ fireEvent.click(view.getByTestId(tid.onboardingJoinSupport))+ await act(async () => { await vi.advanceTimersByTimeAsync(0) })+ expect(view.getByTestId(tid.onboardingOpenSupport)).toBeInTheDocument()+ expect(view.queryByRole("alert", { hidden: true })).not.toBeInTheDocument()})it("does not advance a closed dialog but advances when opened", () => {diff --git a/src/web/src/components/community/onboarding/onboarding-machine-dialog.tsx b/src/web/src/components/community/onboarding/onboarding-machine-dialog.tsxindex 28fed54a1..66fffc593 100644--- a/src/web/src/components/community/onboarding/onboarding-machine-dialog.tsx+++ b/src/web/src/components/community/onboarding/onboarding-machine-dialog.tsx@@ -6,7 +6,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"import { useCommunityMutationOrigin } from "@/hooks/community/community-origin"import { useCommunityViewSource } from "@/hooks/community/use-community-view-source"import { isPresenceOnline } from "@alook/shared"-import { CircleAlert } from "lucide-react"+import { Check, CircleAlert } from "lucide-react"import { toast } from "sonner"import {@@ -14,7 +14,7 @@ import {PairMachineSteps,} from "@/components/community/machines/pair-machine-sheet"import { ProviderLogo } from "@/components/provider-logo"-import { Button } from "@/components/ui/button"+import { Button, buttonVariants } from "@/components/ui/button"import {Dialog,DialogContent,@@ -23,6 +23,7 @@ import {DialogHeader,DialogTitle,} from "@/components/ui/dialog"+import { useJoinServer } from "@/hooks/community/mutations/servers"import { useMachines } from "@/hooks/community/use-machines"import { tid } from "@/lib/community/testids"@@ -47,6 +48,7 @@ export function OnboardingMachineDialog({}) {const origin = useCommunityMutationOrigin()const queryClient = useQueryClient()+ const joinSupport = useJoinServer()const source = useCommunityViewSource(`onboarding-machine:${harness}`, open)const { machines, isSuccess, refetch } = useMachines({enabled: open, subscribed: open,@@ -63,6 +65,8 @@ export function OnboardingMachineDialog({),[harness, machines],)+ const unavailableMachine = !previewConnectedMachine && !onlineMachine ? connectedMachine : null+ const runtimeError = unavailableMachine?.availableRuntimes.find((runtime) => runtime.id === harness)?.lastErrorconst autoMint = useCreateAtom<AbortSignal | null>(null)const autoAdvance = useCreateAtom<AbortSignal | null>(null)const readyMachineId = previewConnectedMachine?.id ?? onlineMachine?.id@@ -105,7 +109,7 @@ export function OnboardingMachineDialog({if (autoMint.get() === source.signal ||!isSuccess ||- onlineMachine ||+ connectedMachine ||previewConnectedMachine ||previewCommand ||tokenId ||@@ -121,7 +125,7 @@ export function OnboardingMachineDialog({generating,isSuccess,machineLimitReached,- onlineMachine,+ connectedMachine,open,previewConnectedMachine,previewCommand,@@ -130,6 +134,19 @@ export function OnboardingMachineDialog({autoMint,])+ const joinAlookSupport = async () => {+ if (joinSupport.isPending) return+ const assert = source.capture()+ assert()+ try {+ await joinSupport.mutateAsync({ inviteCode: "nC7ax53lwm" })+ assert()+ toast.success("Joined Alook Support")+ } catch {+ try { assert() } catch { return }+ }+ }+const command = tokenId ? buildPairCommand(tokenId) : ""const displayedCommand = previewConnectedMachine? "npx --yes @alook/daemon@latest daemon start --machine-key preview-machine-key"@@ -175,13 +192,66 @@ export function OnboardingMachineDialog({<span>machine</span></DialogTitle><DialogDescription className="max-w-[52ch] leading-relaxed">- Run one command. We’ll continue when it’s online.+ {unavailableMachine ? "Your computer is connected. Let’s get your agent ready." : "Run one command. We’ll continue when it’s online."}</DialogDescription></div></DialogHeader><div className="flex flex-col gap-4 px-4 pb-4 sm:px-6 sm:pb-6">- {machineLimitReached && !onlineMachine ? (+ {unavailableMachine ? (+ <section data-testid={tid.onboardingRuntimeUnavailable} className="flex flex-col gap-4" role="status">+ <p className="flex items-start gap-2 text-sm font-medium">+ <Check aria-hidden className="mt-0.5 size-4 shrink-0" />+ <span className="min-w-0 wrap-break-word">{unavailableMachine.hostname || "Your computer"} is connected</span>+ </p>+ <div className="flex flex-col gap-2">+ <h3 className="text-base font-medium">{harnessLabel} isn’t ready on this computer</h3>+ <p className="text-sm wrap-break-word text-destructive">+ Detection error: {runtimeError || "The selected agent wasn’t detected as available."}+ </p>+ <p className="text-sm leading-relaxed text-muted-foreground">+ Install or fix {harnessLabel}, then restart the Alook daemon from a terminal where {harnessLabel} works. We’ll continue when it’s ready.+ </p>+ </div>+ <div className="flex flex-col gap-2 sm:flex-row">+ {joinSupport.data ? (+ <a+ href={`/c/channels/${joinSupport.data.serverId}`}+ target="_blank"+ rel="noopener noreferrer"+ data-testid={tid.onboardingOpenSupport}+ className={buttonVariants({ className: "h-11 sm:h-9" })}+ >+ Open Alook Support+ </a>+ ) : (+ <Button+ type="button"+ className="h-11 sm:h-9"+ data-testid={tid.onboardingJoinSupport}+ disabled={joinSupport.isPending}+ onClick={() => void joinAlookSupport()}+ >+ {joinSupport.isPending ? "Joining…" : "Need Help"}+ </Button>+ )}+ <Button+ type="button"+ variant="outline"+ className="h-11 sm:h-9"+ data-testid={tid.onboardingChooseHarness}+ onClick={onChooseAnotherHarness}+ >+ Choose another agent+ </Button>+ </div>+ {joinSupport.isError ? (+ <p role="alert" className="text-sm text-destructive">Couldn’t join Alook Support. Try again.</p>+ ) : joinSupport.data ? (+ <p className="text-sm text-muted-foreground">You’ve joined Alook Support. Open it in a new tab to report the detection error.</p>+ ) : null}+ </section>+ ) : machineLimitReached && !onlineMachine ? (<sectionrole="alert"className="flex flex-col gap-3 rounded-xl border border-warning/30 bg-warning/5 p-4"@@ -224,11 +294,6 @@ export function OnboardingMachineDialog({/>)}- {!machineLimitReached && !previewConnectedMachine && !onlineMachine && connectedMachine ? (- <p role="status" className="text-sm text-muted-foreground">- {harnessLabel} isn’t available on {connectedMachine.hostname || "this machine"} yet.- </p>- ) : null}</div><DialogFooter className="m-0 rounded-b-xl border-0 bg-transparent px-4 py-4 sm:px-6">diff --git a/src/web/src/lib/community/testids.ts b/src/web/src/lib/community/testids.tsindex beb0998af..754ccff7d 100644--- a/src/web/src/lib/community/testids.ts+++ b/src/web/src/lib/community/testids.ts@@ -101,6 +101,10 @@ export const tid = {machinePairStatus: "community-machine-pair-status",onboardingHarnessDialog: "community-onboarding-harness-dialog",onboardingHarnessOption: (runtime: string) => `community-onboarding-harness-${runtime}`,+ onboardingRuntimeUnavailable: "community-onboarding-runtime-unavailable",+ onboardingOpenSupport: "community-onboarding-open-support",+ onboardingJoinSupport: "community-onboarding-join-support",+ onboardingChooseHarness: "community-onboarding-choose-harness",onboardingMachineDialog: "community-onboarding-machine-dialog",onboardingIdentityDialog: "community-onboarding-identity-dialog",onboardingIdentityOption: (identity: string) => `community-onboarding-identity-${identity}`,