Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-11667): studio first-run experience — progressive disclosure (#7009)
Celal Zamanoğlu6b3d91e6b634
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioCoachMark.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioCoachMark.test.tsxnew file mode 100644index 000000000..1bdae8688--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/StudioCoachMark.test.tsx@@ -0,0 +1,66 @@+// @vitest-environment jsdom++import {+ act,+ cleanup,+ fireEvent,+ render,+ screen,+} from "@testing-library/react";+import { MemoryRouter } from "react-router-dom";+import { afterEach, beforeEach, describe, expect, test } from "vitest";++import { useStudioFirstRunStore } from "@/store/StudioFirstRunStore";++import { StudioCoachMark } from "./StudioCoachMark";++function renderAt(path = "/workflows/wpid_1/studio") {+ return render(+ <MemoryRouter initialEntries={[path]}>+ <StudioCoachMark />+ </MemoryRouter>,+ );+}++afterEach(cleanup);+beforeEach(() => {+ localStorage.clear();+ useStudioFirstRunStore.setState({+ coachMarkSeen: false,+ narrowNudgeSeen: false,+ });+});++describe("StudioCoachMark", () => {+ test("shows on a first plain studio visit", () => {+ renderAt();+ expect(screen.getByRole("note", { name: "Studio panes tip" })).toBeTruthy();+ });++ test("dismisses for good via Got it", () => {+ renderAt();+ fireEvent.click(screen.getByRole("button", { name: "Got it" }));+ expect(screen.queryByRole("note")).toBeNull();+ expect(useStudioFirstRunStore.getState().coachMarkSeen).toBe(true);+ });++ test("never shows again once seen", () => {+ useStudioFirstRunStore.setState({ coachMarkSeen: true });+ renderAt();+ expect(screen.queryByRole("note")).toBeNull();+ });++ test("hides live when a pane interaction marks it seen", () => {+ renderAt();+ expect(screen.getByRole("note")).toBeTruthy();+ act(() => {+ useStudioFirstRunStore.getState().markCoachMarkSeen();+ });+ expect(screen.queryByRole("note")).toBeNull();+ });++ test("stays out of the way on deep-linked visits", () => {+ renderAt("/workflows/wpid_1/studio?wr=wr_1");+ expect(screen.queryByRole("note")).toBeNull();+ });+});diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioCoachMark.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioCoachMark.tsxnew file mode 100644index 000000000..6a075fa13--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/StudioCoachMark.tsx@@ -0,0 +1,54 @@+import { useState } from "react";+import { useLocation } from "react-router-dom";++import { Button } from "@/components/ui/button";+import { useStudioFirstRunStore } from "@/store/StudioFirstRunStore";++import { liveSearch } from "./liveSearch";++/**+ * One-time callout beside the spine teaching that tabs open side-by-side+ * panes. Suppressed on deep-linked visits (a shared run link is the wrong+ * moment to teach layout); the first pane toggle also dismisses it for good.+ */+export function StudioCoachMark() {+ const coachMarkSeen = useStudioFirstRunStore((s) => s.coachMarkSeen);+ const markCoachMarkSeen = useStudioFirstRunStore((s) => s.markCoachMarkSeen);+ const location = useLocation();+ const [deepLinked] = useState(() => {+ const params = new URLSearchParams(liveSearch(location.search));+ return Boolean(+ params.get("wr") || params.get("active") || params.get("bl"),+ );+ });++ if (coachMarkSeen || deepLinked) {+ return null;+ }++ return (+ <div+ role="note"+ aria-label="Studio panes tip"+ className="absolute left-3 top-8 z-50 w-64 rounded-md border bg-popover p-3 text-popover-foreground shadow-md duration-200 motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-left-2"+ >+ <span+ aria-hidden+ className="absolute -left-1 top-5 size-2 rotate-45 border-b border-l bg-popover"+ />+ <p className="text-xs font-medium">Panes open side by side</p>+ <p className="mt-1 text-xs text-muted-foreground">+ Each tab on this rail toggles a pane, so you can watch the browser while+ you edit, or keep Copilot next to a run.+ </p>+ <Button+ variant="secondary"+ size="sm"+ className="mt-2 h-7 px-2 text-xs"+ onClick={markCoachMarkSeen}+ >+ Got it+ </Button>+ </div>+ );+}diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsxnew file mode 100644index 000000000..333e946dd--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsx@@ -0,0 +1,232 @@+// @vitest-environment jsdom++import { useLayoutEffect, useMemo } from "react";+import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { MemoryRouter } from "react-router-dom";+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";++import { useStudioFirstRunStore } from "@/store/StudioFirstRunStore";++import { StudioPaneDefaultsProvider } from "./StudioPaneDefaults";+import { useStudioPaneDefaults } from "./StudioPaneDefaultsContext";+import { useStudioPanes } from "./useStudioPanes";++const { runSignalsMock, toastMock } = vi.hoisted(() => ({+ runSignalsMock: vi.fn(),+ toastMock: vi.fn(),+}));++vi.mock("./useStudioRunSignals", () => ({+ useStudioRunSignals: () => runSignalsMock(),+}));++vi.mock("@/components/ui/use-toast", () => ({+ toast: toastMock,+}));++function PanesProbe() {+ const { panes, togglePane, openPane } = useStudioPanes();+ return (+ <div>+ <output data-testid="panes">{panes.join(",")}</output>+ <button onClick={() => togglePane("run")}>toggle-run</button>+ <button onClick={() => openPane("editor")}>open-editor</button>+ <button onClick={() => openPane("browser")}>open-browser</button>+ </div>+ );+}++// Simulates the shell's stage ref with an element of a known width.+function StageProbe({ width }: { width: number }) {+ const { registerStageElement } = useStudioPaneDefaults();+ const el = useMemo(() => {+ const div = document.createElement("div");+ Object.defineProperty(div, "clientWidth", { value: width });+ return div;+ }, [width]);+ useLayoutEffect(() => {+ registerStageElement(el);+ }, [registerStageElement, el]);+ return null;+}++function renderStudio({+ path = "/workflows/wpid_1/studio",+ hasBlocks = true,+ stageWidth,+}: {+ path?: string;+ hasBlocks?: boolean;+ stageWidth?: number;+} = {}) {+ const tree = (+ <MemoryRouter initialEntries={[path]}>+ <StudioPaneDefaultsProvider hasBlocks={hasBlocks}>+ {stageWidth !== undefined ? <StageProbe width={stageWidth} /> : null}+ <PanesProbe />+ </StudioPaneDefaultsProvider>+ </MemoryRouter>+ );+ return { ...render(tree), tree };+}++function panesText(): string {+ return screen.getByTestId("panes").textContent ?? "";+}++afterEach(cleanup);+beforeEach(() => {+ localStorage.clear();+ useStudioFirstRunStore.setState({+ coachMarkSeen: false,+ narrowNudgeSeen: false,+ });+ runSignalsMock.mockReturnValue({+ hasRun: false,+ runStatus: undefined,+ knownHasRuns: undefined,+ });+ toastMock.mockReset();+});++describe("state-aware default panes", () => {+ test("an agent with cached runs starts on Copilot + Browser", () => {+ runSignalsMock.mockReturnValue({+ hasRun: true,+ runStatus: undefined,+ knownHasRuns: true,+ });+ renderStudio();+ expect(panesText()).toBe("copilot,browser");+ });++ test("a never-run agent starts on Copilot + Editor", () => {+ runSignalsMock.mockReturnValue({+ hasRun: false,+ runStatus: undefined,+ knownHasRuns: false,+ });+ renderStudio();+ expect(panesText()).toBe("copilot,editor");+ });++ test("an empty agent starts on Copilot + Editor even before runs load", () => {+ renderStudio({ hasBlocks: false });+ expect(panesText()).toBe("copilot,editor");+ });++ test("an agent with blocks keeps the legacy default while runs are unknown", () => {+ renderStudio({ hasBlocks: true });+ expect(panesText()).toBe("copilot,browser");+ });++ test("a runs signal that arrives after mount does not reshuffle the panes", () => {+ const { rerender, tree } = renderStudio({ hasBlocks: true });+ expect(panesText()).toBe("copilot,browser");+ runSignalsMock.mockReturnValue({+ hasRun: false,+ runStatus: undefined,+ knownHasRuns: false,+ });+ rerender(tree);+ expect(panesText()).toBe("copilot,browser");+ });++ test("an explicit ?panes= is never overridden by the state default", () => {+ runSignalsMock.mockReturnValue({+ hasRun: false,+ runStatus: undefined,+ knownHasRuns: false,+ });+ renderStudio({ path: "/workflows/wpid_1/studio?panes=browser" });+ expect(panesText()).toBe("browser");+ });++ test("deep links keep their mapping regardless of the state default", () => {+ runSignalsMock.mockReturnValue({+ hasRun: true,+ runStatus: undefined,+ knownHasRuns: false,+ });+ renderStudio({ path: "/workflows/wpid_1/studio?wr=wr_1" });+ expect(panesText()).toBe("run");+ });++ test("toggling from the state default writes the default plus the change", () => {+ runSignalsMock.mockReturnValue({+ hasRun: true,+ runStatus: undefined,+ knownHasRuns: false,+ });+ renderStudio();+ fireEvent.click(screen.getByText("open-browser"));+ expect(panesText()).toBe("copilot,editor,browser");+ });+});++describe("narrow-viewport clamp of shared links", () => {+ const FOUR_PANES =+ "/workflows/wpid_1/studio?panes=copilot,editor,browser,run";++ test("an over-wide shared link degrades to its fitting prefix", () => {+ renderStudio({ path: FOUR_PANES, stageWidth: 600 });+ expect(panesText()).toBe("copilot,editor");+ });++ test("a wide viewport presents the shared link untouched", () => {+ renderStudio({ path: FOUR_PANES, stageWidth: 2000 });+ expect(panesText()).toBe("copilot,editor,browser,run");+ });++ test("without a measurable stage the list is presented as-is", () => {+ renderStudio({ path: FOUR_PANES });+ expect(panesText()).toBe("copilot,editor,browser,run");+ });++ test("the first pane write clears the clamp and builds on what is shown", () => {+ renderStudio({ path: FOUR_PANES, stageWidth: 600 });+ fireEvent.click(screen.getByText("toggle-run"));+ expect(panesText()).toBe("copilot,editor,run");+ });+});++describe("narrow-viewport nudge", () => {+ test("opening a pane past the min-width budget nudges exactly once", () => {+ renderStudio({+ path: "/workflows/wpid_1/studio?panes=copilot,editor",+ stageWidth: 600,+ });+ fireEvent.click(screen.getByText("toggle-run"));+ expect(toastMock).toHaveBeenCalledTimes(1);+ expect(panesText()).toBe("copilot,editor,run");+ fireEvent.click(screen.getByText("open-browser"));+ expect(toastMock).toHaveBeenCalledTimes(1);+ expect(useStudioFirstRunStore.getState().narrowNudgeSeen).toBe(true);+ });++ test("no nudge when the opened pane still fits", () => {+ renderStudio({+ path: "/workflows/wpid_1/studio?panes=copilot",+ stageWidth: 2000,+ });+ fireEvent.click(screen.getByText("open-browser"));+ expect(toastMock).not.toHaveBeenCalled();+ });++ test("closing a pane never nudges", () => {+ renderStudio({+ path: "/workflows/wpid_1/studio?panes=copilot,run",+ stageWidth: 600,+ });+ fireEvent.click(screen.getByText("toggle-run"));+ expect(panesText()).toBe("copilot");+ expect(toastMock).not.toHaveBeenCalled();+ });++ test("a pane write marks the coach mark as learned", () => {+ renderStudio({ stageWidth: 2000 });+ expect(useStudioFirstRunStore.getState().coachMarkSeen).toBe(false);+ fireEvent.click(screen.getByText("open-editor"));+ expect(useStudioFirstRunStore.getState().coachMarkSeen).toBe(true);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.tsxnew file mode 100644index 000000000..35df63273--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.tsx@@ -0,0 +1,108 @@+import { useCallback, useMemo, useRef, useState, type ReactNode } from "react";+import { useLocation } from "react-router-dom";++import { toast } from "@/components/ui/use-toast";+import { useStudioFirstRunStore } from "@/store/StudioFirstRunStore";++import { liveSearch } from "./liveSearch";+import {+ defaultPanesForWorkflowState,+ fitPanesToWidth,+ panesFitWidth,+ resolveOpenPanes,+ type StudioPaneId,+} from "./panes";+import {+ StudioPaneDefaultsContext,+ type PaneClamp,+ type PaneWrite,+} from "./StudioPaneDefaultsContext";+import { useStudioRunSignals } from "./useStudioRunSignals";++/**+ * First-visit pane policy for one studio mount. The state-aware default and+ * the narrow-viewport clamp are both latched exactly once (the shell remounts+ * per workflow via its key), so panes never reshuffle after first paint: a+ * runs signal that arrives later changes nothing until the next visit.+ */+export function StudioPaneDefaultsProvider({+ hasBlocks,+ children,+}: {+ hasBlocks: boolean;+ children: ReactNode;+}) {+ const location = useLocation();+ const { knownHasRuns } = useStudioRunSignals();++ // Latched: cached runs data decides; on a cold cache an agent with blocks+ // keeps today's watch default while an empty agent starts on the editor.+ const [defaultPanes] = useState<readonly StudioPaneId[]>(() =>+ defaultPanesForWorkflowState({ hasRuns: knownHasRuns, hasBlocks }),+ );++ const [initialPanes] = useState<readonly StudioPaneId[]>(() =>+ resolveOpenPanes(liveSearch(location.search), defaultPanes),+ );++ const [clamp, setClamp] = useState<PaneClamp | null>(null);+ const stageElRef = useRef<HTMLElement | null>(null);+ const measuredRef = useRef(false);+ const wroteRef = useRef(false);++ // Ref callbacks run before paint, so an over-wide shared link is clamped to+ // its fitting prefix without ever flashing the full list.+ const registerStageElement = useCallback(+ (el: HTMLElement | null) => {+ stageElRef.current = el;+ if (!el || measuredRef.current || wroteRef.current) {+ return;+ }+ const width = el.clientWidth;+ if (width <= 0) {+ return;+ }+ measuredRef.current = true;+ const fitted = fitPanesToWidth(initialPanes, width);+ if (fitted.length !== initialPanes.length) {+ setClamp({ source: initialPanes, presented: fitted });+ }+ },+ [initialPanes],+ );++ const notePaneWrite = useCallback((change: PaneWrite) => {+ wroteRef.current = true;+ setClamp((current) => (current === null ? current : null));+ const firstRun = useStudioFirstRunStore.getState();+ // Toggling a pane is the lesson the coach mark teaches.+ if (!firstRun.coachMarkSeen) {+ firstRun.markCoachMarkSeen();+ }+ const stageWidth = stageElRef.current?.clientWidth ?? 0;+ if (+ stageWidth > 0 &&+ change.next.length > change.previous.length &&+ !panesFitWidth(change.next, stageWidth) &&+ !firstRun.narrowNudgeSeen+ ) {+ firstRun.markNarrowNudgeSeen();+ toast({+ title: "Tight fit",+ description:+ "Panes keep a minimum width, so this view may feel cramped. Close a pane from the left rail any time.",+ });+ }+ }, []);++ const value = useMemo(+ () => ({ defaultPanes, clamp, notePaneWrite, registerStageElement }),+ [defaultPanes, clamp, notePaneWrite, registerStageElement],+ );++ return (+ <StudioPaneDefaultsContext.Provider value={value}>+ {children}+ </StudioPaneDefaultsContext.Provider>+ );+}diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaultsContext.ts b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaultsContext.tsnew file mode 100644index 000000000..9f18937a5--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaultsContext.ts@@ -0,0 +1,37 @@+import { createContext, useContext } from "react";++import { DEFAULT_STUDIO_PANES, type StudioPaneId } from "./panes";++export type PaneClamp = {+ source: readonly StudioPaneId[];+ presented: readonly StudioPaneId[];+};++export type PaneWrite = {+ previous: readonly StudioPaneId[];+ next: readonly StudioPaneId[];+};++export type StudioPaneDefaultsValue = {+ defaultPanes: readonly StudioPaneId[];+ clamp: PaneClamp | null;+ notePaneWrite: (change: PaneWrite) => void;+ registerStageElement: (el: HTMLElement | null) => void;+};++const noop = () => undefined;++// Module default keeps useStudioPanes safe outside the studio shell (legacy+// Workspace, tests): legacy default panes, no clamping, no nudges.+export const StudioPaneDefaultsContext = createContext<StudioPaneDefaultsValue>(+ {+ defaultPanes: DEFAULT_STUDIO_PANES,+ clamp: null,+ notePaneWrite: noop,+ registerStageElement: noop,+ },+);++export function useStudioPaneDefaults(): StudioPaneDefaultsValue {+ return useContext(StudioPaneDefaultsContext);+}diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsxindex 4a239f399..a672df7f5 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx@@ -9,23 +9,21 @@ import { BrowserTab } from "./BrowserTab";import { EditorTab, type StudioWorkspaceProps } from "./EditorTab";import { RunTab } from "./RunTab";import { StudioBrowserStream } from "./StudioBrowserStream";+import { StudioCoachMark } from "./StudioCoachMark";import { studioPanelId, studioTabId } from "./constants";import { STUDIO_PANE_META } from "./paneMeta";-import { type StudioPaneId } from "./panes";+import { STUDIO_PANE_MIN_WIDTH, type StudioPaneId } from "./panes";+import { StudioPaneDefaultsProvider } from "./StudioPaneDefaults";+import { useStudioPaneDefaults } from "./StudioPaneDefaultsContext";import { StudioShellContext } from "./StudioShellContext";import { StudioSpine } from "./StudioSpine";+import { StudioStageLauncher } from "./StudioStageLauncher";import { StudioTopBar } from "./StudioTopBar";import { StudioWorkflowPanels } from "./StudioWorkflowPanels";import { useStudioPanes } from "./useStudioPanes";-// Width floors from the approved mock; the Copilot pane also holds a ceiling so-// a lone chat doesn't stretch across the whole stage.-const PANE_MIN_WIDTH: Record<StudioPaneId, number> = {- copilot: 260,- editor: 220,- browser: 260,- run: 220,-};+// The Copilot pane holds a ceiling so a lone chat doesn't stretch across the+// whole stage; the shared floors live in panes.ts next to the fit math.const COPILOT_MAX_WIDTH = 440;function StudioPane({@@ -49,7 +47,7 @@ function StudioPane({aria-label={label}style={{order,- minWidth: PANE_MIN_WIDTH[id],+ minWidth: STUDIO_PANE_MIN_WIDTH[id],maxWidth: id === "copilot" ? COPILOT_MAX_WIDTH : undefined,}}className={cn(@@ -85,7 +83,18 @@ function StudioPane({* order (?panes=). The Copilot chat is portaled into its pane from Workspace.*/export function StudioShell(props: StudioWorkspaceProps) {+ return (+ <StudioPaneDefaultsProvider+ hasBlocks={props.workflow.workflow_definition.blocks.length > 0}+ >+ <StudioStage {...props} />+ </StudioPaneDefaultsProvider>+ );+}++function StudioStage(props: StudioWorkspaceProps) {const { panes, closePane } = useStudioPanes();+ const { registerStageElement } = useStudioPaneDefaults();const pipMinimized = useStudioShellStore((s) => s.pipMinimized);const [copilotPortalEl, setCopilotPortalEl] = useState<HTMLElement | null>(null,@@ -176,7 +185,10 @@ export function StudioShell(props: StudioWorkspaceProps) {{/* Panes keep a fixed DOM order (stable mounts for the canvas, chat andstream slots); the CSS order carries the click order instead, soscreen-reader/Tab order stays the fixed order, not the visual one. */}- <div className="relative flex min-h-0 min-w-0 flex-1 gap-3 overflow-hidden p-3">+ <div+ ref={registerStageElement}+ className="relative flex min-h-0 min-w-0 flex-1 gap-3 overflow-hidden p-3"+ ><StudioPane {...paneProps("copilot")}>{/* Copilot portal target. Kept mounted while the pane is closed soan in-flight Copilot turn isn't torn down. */}@@ -193,13 +205,8 @@ export function StudioShell(props: StudioWorkspaceProps) {<StudioPane {...paneProps("run")}><RunTab /></StudioPane>- {panes.length === 0 ? (- <div className="flex flex-1 items-center justify-center">- <p className="max-w-[17rem] text-center text-sm text-muted-foreground">- No panes open. Open one from the rail on the left.- </p>- </div>- ) : null}+ {panes.length === 0 ? <StudioStageLauncher /> : null}+ <StudioCoachMark /><StudioWorkflowPanels /></div></div>diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioSpine.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioSpine.tsxindex ac3b101a5..58fdee076 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioSpine.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioSpine.tsx@@ -1,18 +1,14 @@import { useState, type KeyboardEvent } from "react";-import { useParams } from "react-router-dom";import { Status } from "@/api/types";import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";import { cn } from "@/util/utils";-import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";-import { useWorkflowRunsQuery } from "../hooks/useWorkflowRunsQuery";import { studioPanelId, studioTabId } from "./constants";import { STUDIO_PANE_META } from "./paneMeta";import { STUDIO_PANE_IDS, type StudioPaneId } from "./panes";-import { finalizedRunStatus } from "./runProjections";import { useStudioPanes } from "./useStudioPanes";-import { useStudioRunId } from "./useStudioRunId";+import { useStudioRunSignals } from "./useStudioRunSignals";// Terminal-only (finalizedRunStatus never returns a live status); mirrors the// StatusBadge variant buckets so the dot reads the same as the run chip.@@ -47,20 +43,7 @@ export function StudioSpine() {);const clearBrowserActivity = useStudioBrowserStore((s) => s.clearActivity);- const urlRunId = useStudioRunId();- const { workflowPermanentId } = useParams();- const { data: urlRun } = useWorkflowRunWithWorkflowQuery(- urlRunId ? { workflowRunId: urlRunId } : undefined,- );- const { data: runs } = useWorkflowRunsQuery({- workflowPermanentId,- page: 1,- pageSize: 1,- });- const hasRun = Boolean(urlRunId) || (runs?.length ?? 0) > 0;- const runStatus = finalizedRunStatus(- urlRunId ? urlRun?.status : runs?.[0]?.status,- );+ const { hasRun, runStatus } = useStudioRunSignals();const onToggle = (id: StudioPaneId) => {if (id === "browser" && !panes.includes("browser")) {diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.test.tsxnew file mode 100644index 000000000..786c8e3bd--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.test.tsx@@ -0,0 +1,90 @@+// @vitest-environment jsdom++import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { MemoryRouter, useLocation } from "react-router-dom";+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";++import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";++import { StudioStageLauncher } from "./StudioStageLauncher";++const { runSignalsMock } = vi.hoisted(() => ({+ runSignalsMock: vi.fn(),+}));++vi.mock("./useStudioRunSignals", () => ({+ useStudioRunSignals: () => runSignalsMock(),+}));++const initialBrowserState = useStudioBrowserStore.getState();++function LocationProbe() {+ const location = useLocation();+ return <output data-testid="search">{location.search}</output>;+}++function renderAt(path = "/workflows/wpid_1/studio?panes=") {+ return render(+ <MemoryRouter initialEntries={[path]}>+ <StudioStageLauncher />+ <LocationProbe />+ </MemoryRouter>,+ );+}++function currentPanes(): string | null {+ const search = screen.getByTestId("search").textContent ?? "";+ return new URLSearchParams(search).get("panes");+}++afterEach(cleanup);+beforeEach(() => {+ useStudioBrowserStore.setState(initialBrowserState, true);+ runSignalsMock.mockReturnValue({+ hasRun: false,+ runStatus: undefined,+ knownHasRuns: false,+ });+});++describe("StudioStageLauncher", () => {+ test("offers every pane as a labeled button", () => {+ renderAt();+ for (const label of ["Copilot", "Editor", "Browser", "Run"]) {+ expect(+ screen.getByRole("button", { name: new RegExp(`^${label}`) }),+ ).toBeTruthy();+ }+ });++ test("keeps the Run launcher gated until a run exists, with the reason readable", () => {+ renderAt();+ const run = screen.getByRole("button", { name: /no runs yet/ });+ expect((run as HTMLButtonElement).disabled).toBe(true);+ });++ test("enables the Run launcher once a run exists", () => {+ runSignalsMock.mockReturnValue({+ hasRun: true,+ runStatus: undefined,+ knownHasRuns: true,+ });+ renderAt();+ const run = screen.getByRole("button", { name: "Run" });+ expect((run as HTMLButtonElement).disabled).toBe(false);+ });++ test("opens the clicked pane", () => {+ renderAt();+ fireEvent.click(screen.getByRole("button", { name: "Editor" }));+ expect(currentPanes()).toBe("editor");+ });++ test("clears unseen browser activity when opening the Browser pane", () => {+ useStudioBrowserStore.getState().markActivity();+ renderAt();+ fireEvent.click(screen.getByRole("button", { name: "Browser" }));+ expect(useStudioBrowserStore.getState().hasUnseenActivity).toBe(false);+ expect(currentPanes()).toBe("browser");+ });+});diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.tsxnew file mode 100644index 000000000..af6ade9da--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.tsx@@ -0,0 +1,60 @@+import { Button } from "@/components/ui/button";+import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";++import { STUDIO_PANE_META } from "./paneMeta";+import { STUDIO_PANE_IDS, type StudioPaneId } from "./panes";+import { useStudioPanes } from "./useStudioPanes";+import { useStudioRunSignals } from "./useStudioRunSignals";++/**+ * Zero-panes stage: every pane stays one labeled click away instead of the+ * stage dead-ending. Mirrors the spine's Run gating.+ */+export function StudioStageLauncher() {+ const { openPane } = useStudioPanes();+ const { hasRun } = useStudioRunSignals();+ const clearBrowserActivity = useStudioBrowserStore((s) => s.clearActivity);++ const open = (id: StudioPaneId) => {+ if (id === "browser") {+ clearBrowserActivity();+ }+ openPane(id);+ };++ return (+ <div className="flex flex-1 items-center justify-center">+ <div className="flex max-w-md flex-col items-center gap-4 text-center">+ <p className="text-sm text-muted-foreground">+ All panes are closed. Open one to keep working:+ </p>+ <div className="flex flex-wrap items-center justify-center gap-2">+ {STUDIO_PANE_IDS.map((id) => {+ const { label, icon: Icon } = STUDIO_PANE_META[id];+ const disabled = id === "run" && !hasRun;+ return (+ <Button+ key={id}+ type="button"+ variant="secondary"+ size="sm"+ disabled={disabled}+ title={disabled ? "Run: no runs yet" : `Open ${label}`}+ onClick={() => open(id)}+ className="gap-2"+ >+ <Icon className="size-4" aria-hidden />+ {label}+ {/* title isn't exposed on a disabled control; keep the reason+ readable in browse mode. */}+ {disabled ? (+ <span className="sr-only">(no runs yet)</span>+ ) : null}+ </Button>+ );+ })}+ </div>+ </div>+ </div>+ );+}diff --git a/skyvern-frontend/src/routes/workflows/studio/liveSearch.ts b/skyvern-frontend/src/routes/workflows/studio/liveSearch.tsnew file mode 100644index 000000000..577a48713--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/liveSearch.ts@@ -0,0 +1,6 @@+// window.location is blank under a memory router (tests); the router's+// location is identical to the live URL in a real browser. Reading the live+// URL matters because pushState is synchronous while router state is not.+export function liveSearch(routerSearch: string): string {+ return window.location.search || routerSearch;+}diff --git a/skyvern-frontend/src/routes/workflows/studio/panes.test.ts b/skyvern-frontend/src/routes/workflows/studio/panes.test.tsindex fe9554a78..024305692 100644--- a/skyvern-frontend/src/routes/workflows/studio/panes.test.ts+++ b/skyvern-frontend/src/routes/workflows/studio/panes.test.ts@@ -2,7 +2,14 @@ import { describe, expect, test } from "vitest";import {DEFAULT_STUDIO_PANES,+ STUDIO_STAGE_GAP_PX,+ STUDIO_STAGE_PADDING_PX,+ STUDIO_PANE_MIN_WIDTH,+ defaultPanesForWorkflowState,+ fitPanesToWidth,+ panesFitWidth,panesFromDeepLink,+ panesListEqual,parsePanesParam,resolveOpenPanes,searchWithPanes,@@ -125,6 +132,124 @@ describe("resolveOpenPanes", () => {});});+describe("defaultPanesForWorkflowState", () => {+ test("an agent with runs starts on Copilot + Browser", () => {+ expect(+ defaultPanesForWorkflowState({ hasRuns: true, hasBlocks: true }),+ ).toEqual(["copilot", "browser"]);+ });++ test("a never-run agent starts on Copilot + Editor", () => {+ expect(+ defaultPanesForWorkflowState({ hasRuns: false, hasBlocks: true }),+ ).toEqual(["copilot", "editor"]);+ });++ test("a known runs signal outranks the blocks heuristic", () => {+ expect(+ defaultPanesForWorkflowState({ hasRuns: true, hasBlocks: false }),+ ).toEqual(["copilot", "browser"]);+ });++ test("unknown runs falls back to blocks: an empty agent starts on the editor", () => {+ expect(+ defaultPanesForWorkflowState({ hasRuns: undefined, hasBlocks: false }),+ ).toEqual(["copilot", "editor"]);+ });++ test("unknown runs with blocks keeps the legacy default", () => {+ expect(+ defaultPanesForWorkflowState({ hasRuns: undefined, hasBlocks: true }),+ ).toEqual([...DEFAULT_STUDIO_PANES]);+ });+});++describe("resolveOpenPanes with custom defaults", () => {+ test("no params resolves to the given defaults", () => {+ expect(resolveOpenPanes("", ["copilot", "editor"])).toEqual([+ "copilot",+ "editor",+ ]);+ });++ test("deep links are unaffected by custom defaults", () => {+ expect(resolveOpenPanes("?wr=wr_123", ["copilot", "editor"])).toEqual([+ "run",+ ]);+ expect(+ resolveOpenPanes("?wr=wr_123&bl=block_1", ["copilot", "editor"]),+ ).toEqual(["run", "browser"]);+ });++ test("an explicit ?panes= is never overridden by custom defaults", () => {+ expect(resolveOpenPanes("?panes=browser", ["copilot", "editor"])).toEqual([+ "browser",+ ]);+ expect(resolveOpenPanes("?panes=", ["copilot", "editor"])).toEqual([]);+ });+});++describe("panesListEqual", () => {+ test("compares contents and order", () => {+ expect(panesListEqual(["copilot", "browser"], ["copilot", "browser"])).toBe(+ true,+ );+ expect(panesListEqual(["copilot", "browser"], ["browser", "copilot"])).toBe(+ false,+ );+ expect(panesListEqual(["copilot"], ["copilot", "browser"])).toBe(false);+ expect(panesListEqual([], [])).toBe(true);+ });+});++describe("panesFitWidth", () => {+ const width = (panes: Parameters<typeof panesFitWidth>[0]) =>+ panes.reduce((sum, id) => sum + STUDIO_PANE_MIN_WIDTH[id], 0) ++ STUDIO_STAGE_PADDING_PX ++ STUDIO_STAGE_GAP_PX * (panes.length - 1);++ test("an empty list always fits", () => {+ expect(panesFitWidth([], 0)).toBe(true);+ });++ test("fits exactly at the min-width sum plus stage chrome", () => {+ const panes = ["copilot", "browser"] as const;+ expect(panesFitWidth(panes, width(panes))).toBe(true);+ expect(panesFitWidth(panes, width(panes) - 1)).toBe(false);+ });+});++describe("fitPanesToWidth", () => {+ test("returns the list unchanged when everything fits", () => {+ expect(+ fitPanesToWidth(["copilot", "editor", "browser", "run"], 2000),+ ).toEqual(["copilot", "editor", "browser", "run"]);+ });++ test("keeps the longest leading prefix that fits", () => {+ // copilot(260) + editor(220) + padding(24) + gap(12) = 516 fits in 600;+ // adding browser(260) + gap(12) = 788 does not.+ expect(+ fitPanesToWidth(["copilot", "editor", "browser", "run"], 600),+ ).toEqual(["copilot", "editor"]);+ });++ test("degrades deterministically by order, not by pane size", () => {+ expect(fitPanesToWidth(["run", "copilot", "browser"], 600)).toEqual([+ "run",+ "copilot",+ ]);+ });++ test("always keeps the first pane even when nothing fits", () => {+ expect(fitPanesToWidth(["browser", "run"], 100)).toEqual(["browser"]);+ });++ test("keeps an empty list empty", () => {+ expect(fitPanesToWidth([], 100)).toEqual([]);+ });+});+describe("pane list operations", () => {test("toggling a closed pane appends it (click order)", () => {expect(togglePane(["copilot", "browser"], "run")).toEqual([diff --git a/skyvern-frontend/src/routes/workflows/studio/panes.ts b/skyvern-frontend/src/routes/workflows/studio/panes.tsindex 6b5643e34..7f12b24d1 100644--- a/skyvern-frontend/src/routes/workflows/studio/panes.ts+++ b/skyvern-frontend/src/routes/workflows/studio/panes.ts@@ -14,10 +14,76 @@ export const DEFAULT_STUDIO_PANES: readonly StudioPaneId[] = ["browser",];+// Width floors from the approved mock; the stage clamps shared links and nudges+// on over-tight opens against these same numbers (fitPanesToWidth below).+export const STUDIO_PANE_MIN_WIDTH: Record<StudioPaneId, number> = {+ copilot: 260,+ editor: 220,+ browser: 260,+ run: 220,+};++// Stage chrome for the fit math; must match the p-3 + gap-3 on the stage div+// in StudioShell.tsx.+export const STUDIO_STAGE_PADDING_PX = 24;+export const STUDIO_STAGE_GAP_PX = 12;+function isStudioPaneId(value: string): value is StudioPaneId {return (STUDIO_PANE_IDS as readonly string[]).includes(value);}+// First-visit defaults: someone who never ran the agent (or has nothing built)+// starts on the familiar build surface; an agent with history starts on watch.+export function defaultPanesForWorkflowState(state: {+ hasRuns: boolean | undefined;+ hasBlocks: boolean;+}): StudioPaneId[] {+ if (state.hasRuns !== undefined) {+ return state.hasRuns ? ["copilot", "browser"] : ["copilot", "editor"];+ }+ return state.hasBlocks ? [...DEFAULT_STUDIO_PANES] : ["copilot", "editor"];+}++export function panesListEqual(+ a: readonly StudioPaneId[],+ b: readonly StudioPaneId[],+): boolean {+ return a.length === b.length && a.every((id, index) => id === b[index]);+}++export function panesFitWidth(+ panes: readonly StudioPaneId[],+ stageWidth: number,+): boolean {+ if (panes.length === 0) {+ return true;+ }+ const total =+ panes.reduce((sum, id) => sum + STUDIO_PANE_MIN_WIDTH[id], 0) ++ STUDIO_STAGE_PADDING_PX ++ STUDIO_STAGE_GAP_PX * (panes.length - 1);+ return total <= stageWidth;+}++// Degrade an over-wide open list to its longest leading prefix that fits at+// min-widths; the first pane always survives so a link never lands on nothing.+export function fitPanesToWidth(+ panes: readonly StudioPaneId[],+ stageWidth: number,+): StudioPaneId[] {+ const kept: StudioPaneId[] = [];+ for (const id of panes) {+ if (!panesFitWidth([...kept, id], stageWidth)) {+ break;+ }+ kept.push(id);+ }+ if (kept.length === 0 && panes.length > 0) {+ kept.push(panes[0]!);+ }+ return kept;+}+// Ordered open-pane list from an explicit ?panes= value; unknown entries and// duplicates are dropped. null means the param was absent (callers fall back to// the deep-link mapping); an empty value is an explicit "no panes open".@@ -37,33 +103,42 @@ export function parsePanesParam(raw: string | null): StudioPaneId[] | null {// Deep-link → panes mapping when ?panes= is absent: a block run shows its// timeline beside the live debug stream; any other run reference lands on Run.-export function panesFromDeepLink(params: {- runId: string | null;- active: string | null;- blockLabel: string | null;-}): StudioPaneId[] {+export function panesFromDeepLink(+ params: {+ runId: string | null;+ active: string | null;+ blockLabel: string | null;+ },+ defaultPanes: readonly StudioPaneId[] = DEFAULT_STUDIO_PANES,+): StudioPaneId[] {if (params.runId && params.blockLabel) {return ["run", "browser"];}if (params.runId || params.active) {return ["run"];}- return [...DEFAULT_STUDIO_PANES];+ return [...defaultPanes];}// Open panes for a studio search string. An explicit ?panes= wins over the-// legacy deep-link params (?wr= / ?active= / ?bl=).-export function resolveOpenPanes(search: string): StudioPaneId[] {+// legacy deep-link params (?wr= / ?active= / ?bl=); both win over defaultPanes.+export function resolveOpenPanes(+ search: string,+ defaultPanes: readonly StudioPaneId[] = DEFAULT_STUDIO_PANES,+): StudioPaneId[] {const params = new URLSearchParams(search);const explicit = parsePanesParam(params.get(STUDIO_PANES_PARAM));if (explicit !== null) {return explicit;}- return panesFromDeepLink({- runId: params.get("wr"),- active: params.get("active"),- blockLabel: params.get("bl"),- });+ return panesFromDeepLink(+ {+ runId: params.get("wr"),+ active: params.get("active"),+ blockLabel: params.get("bl"),+ },+ defaultPanes,+ );}// Open panes append, close panes splice: list order is the layout order.diff --git a/skyvern-frontend/src/routes/workflows/studio/useStudioPanes.ts b/skyvern-frontend/src/routes/workflows/studio/useStudioPanes.tsindex 3cf86ac7d..d736b5717 100644--- a/skyvern-frontend/src/routes/workflows/studio/useStudioPanes.ts+++ b/skyvern-frontend/src/routes/workflows/studio/useStudioPanes.ts@@ -5,7 +5,9 @@ import {type NavigateOptions,} from "react-router-dom";+import { liveSearch } from "./liveSearch";import {+ panesListEqual,resolveOpenPanes,searchWithPanes,togglePane as togglePaneIn,@@ -13,6 +15,7 @@ import {withPaneOpen,type StudioPaneId,} from "./panes";+import { useStudioPaneDefaults } from "./StudioPaneDefaultsContext";/*** Pane state lives in the URL (?panes=), so the open set and its order are@@ -23,10 +26,22 @@ import {export function useStudioPanes() {const location = useLocation();const navigate = useNavigate();+ const { defaultPanes, clamp, notePaneWrite } = useStudioPaneDefaults();++ // The mount-time viewport clamp only masks the exact pane list the URL+ // carried at mount; any other list means someone navigated, so present it+ // as-is. The first write clears the clamp for good.+ const present = useCallback(+ (resolved: StudioPaneId[]): StudioPaneId[] =>+ clamp && panesListEqual(resolved, clamp.source)+ ? [...clamp.presented]+ : resolved,+ [clamp],+ );const panes = useMemo(- () => resolveOpenPanes(location.search),- [location.search],+ () => present(resolveOpenPanes(location.search, defaultPanes)),+ [location.search, defaultPanes, present],);const applyPanes = useCallback(@@ -34,16 +49,16 @@ export function useStudioPanes() {compute: (current: StudioPaneId[]) => StudioPaneId[],options?: Pick<NavigateOptions, "state">,) => {- // window.location is blank under a memory router (tests); fall back to- // the router's location, which is identical to the live URL in a browser.- const liveSearch = window.location.search || location.search;- const next = compute(resolveOpenPanes(liveSearch));+ const search = liveSearch(location.search);+ const current = present(resolveOpenPanes(search, defaultPanes));+ const next = compute(current);+ notePaneWrite({ previous: current, next });navigate(- { search: searchWithPanes(liveSearch, next) },+ { search: searchWithPanes(search, next) },{ replace: true, ...options },);},- [navigate, location.search],+ [navigate, location.search, defaultPanes, present, notePaneWrite],);const togglePane = useCallback(diff --git a/skyvern-frontend/src/routes/workflows/studio/useStudioRunSignals.ts b/skyvern-frontend/src/routes/workflows/studio/useStudioRunSignals.tsnew file mode 100644index 000000000..6f2293e4e--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/useStudioRunSignals.ts@@ -0,0 +1,32 @@+import { useParams } from "react-router-dom";++import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";+import { useWorkflowRunsQuery } from "../hooks/useWorkflowRunsQuery";+import { finalizedRunStatus } from "./runProjections";+import { useStudioRunId } from "./useStudioRunId";++/**+ * The run facts the shell keys UI off: Run-tab gating, the spine status dot,+ * and the first-visit pane default. `knownHasRuns` stays undefined until the+ * runs page-1 probe has data, so callers can tell "no runs" from "not loaded".+ */+export function useStudioRunSignals() {+ const urlRunId = useStudioRunId();+ const { workflowPermanentId } = useParams();+ const { data: urlRun } = useWorkflowRunWithWorkflowQuery(+ urlRunId ? { workflowRunId: urlRunId } : undefined,+ );+ const { data: runs } = useWorkflowRunsQuery({+ workflowPermanentId,+ page: 1,+ pageSize: 1,+ });+ const knownHasRuns = runs === undefined ? undefined : runs.length > 0;+ return {+ hasRun: Boolean(urlRunId) || knownHasRuns === true,+ runStatus: finalizedRunStatus(+ urlRunId ? urlRun?.status : runs?.[0]?.status,+ ),+ knownHasRuns,+ };+}diff --git a/skyvern-frontend/src/store/StudioFirstRunStore.ts b/skyvern-frontend/src/store/StudioFirstRunStore.tsnew file mode 100644index 000000000..8f3b88a2a--- /dev/null+++ b/skyvern-frontend/src/store/StudioFirstRunStore.ts@@ -0,0 +1,34 @@+import { create } from "zustand";+import { persist, createJSONStorage } from "zustand/middleware";++type StudioFirstRunState = {+ coachMarkSeen: boolean;+ narrowNudgeSeen: boolean;+ markCoachMarkSeen: () => void;+ markNarrowNudgeSeen: () => void;+};++const DEFAULTS = {+ coachMarkSeen: false,+ narrowNudgeSeen: false,+};++export const STUDIO_FIRST_RUN_STORAGE_KEY = "skyvern.studioFirstRun";++export const useStudioFirstRunStore = create<StudioFirstRunState>()(+ persist(+ (set) => ({+ ...DEFAULTS,+ markCoachMarkSeen: () => set({ coachMarkSeen: true }),+ markNarrowNudgeSeen: () => set({ narrowNudgeSeen: true }),+ }),+ {+ name: STUDIO_FIRST_RUN_STORAGE_KEY,+ storage: createJSONStorage(() => localStorage),+ partialize: (state) => ({+ coachMarkSeen: state.coachMarkSeen,+ narrowNudgeSeen: state.narrowNudgeSeen,+ }),+ },+ ),+);