Skip to content

Automate browser based workflows with AI

feat(SKY-11970): add phased progress model to the copilot build (#7290)

Celal Zamanoğlud6936866b59c
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx
new file mode 100644
index 000000000..5acfd4ea6
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.checklist.test.tsx
@@ -0,0 +1,315 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { NarrativeView } from "./NarrativeView";
+import {
+ ActivityEntry,
+ BlockState,
+ EMPTY_NARRATIVE,
+ TurnNarrativeState,
+ hydrateNarrativeFromPayload,
+} from "./narrativeState";
+
+afterEach(() => {
+ cleanup();
+});
+
+const activityEntry = (
+ overrides: Partial<ActivityEntry> & Pick<ActivityEntry, "id" | "kind">,
+): ActivityEntry => ({
+ text: "…",
+ iteration: 0,
+ ...overrides,
+});
+
+const runningBlock = (overrides: Partial<BlockState> = {}): BlockState => ({
+ workflowRunBlockId: "wrb_1",
+ label: "block_1",
+ blockType: "task",
+ state: "running",
+ lastSeenIteration: 0,
+ activity: [],
+ startedAt: "2026-06-10T00:00:05Z",
+ endedAt: null,
+ ...overrides,
+});
+
+const liveExploreTurn = (): TurnNarrativeState => ({
+ ...EMPTY_NARRATIVE,
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ terminal: null,
+ designActivity: [
+ activityEntry({
+ id: "tc-1",
+ kind: "tool_call",
+ toolName: "navigate_browser",
+ displayLabel: "Opening page",
+ }),
+ ],
+});
+
+const testActiveTurn = (): TurnNarrativeState => ({
+ ...EMPTY_NARRATIVE,
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ designEnded: true,
+ terminal: null,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [runningBlock()],
+ designActivity: [
+ activityEntry({
+ id: "tc-1",
+ kind: "tool_call",
+ toolName: "navigate_browser",
+ displayLabel: "Opening page",
+ }),
+ activityEntry({
+ id: "tc-2",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ displayLabel: "Testing workflow",
+ }),
+ ],
+});
+
+describe("NarrativeView — phase checklist (SKY-11970)", () => {
+ it("PIN: a live design turn renders an active Explore site row nesting its tool-activity stream", () => {
+ render(<NarrativeView turn={liveExploreTurn()} uxV1 />);
+ // Active rows render inert (no aria-expanded button) — status reaches
+ // screen readers via the sr-only word instead.
+ const exploreLabel = screen.getByText("Explore site");
+ expect(exploreLabel.closest("button")).toBeNull();
+ const exploreRow = exploreLabel.closest("div")!;
+ expect(exploreRow.querySelector(".animate-spin")).toBeTruthy();
+ expect(exploreRow.textContent).toContain("Active");
+ expect(screen.getByText("Opening page")).toBeTruthy();
+ });
+
+ it("auto-collapses a phase once it's no longer active, and re-opens on click", () => {
+ const { rerender } = render(
+ <NarrativeView turn={liveExploreTurn()} uxV1 />,
+ );
+ expect(screen.getByText("Opening page")).toBeTruthy();
+
+ rerender(<NarrativeView turn={testActiveTurn()} uxV1 />);
+ const exploreRow = screen.getByRole("button", { name: /Explore site/ });
+ expect(exploreRow.getAttribute("aria-expanded")).toBe("false");
+ expect(screen.queryByText("Opening page")).toBeNull();
+ expect(screen.getByText("1 step")).toBeTruthy();
+
+ fireEvent.click(exploreRow);
+ expect(exploreRow.getAttribute("aria-expanded")).toBe("true");
+ expect(screen.getByText("Opening page")).toBeTruthy();
+ });
+
+ it("excludes the active row from toggling — renders inert, not a clickable button", () => {
+ render(<NarrativeView turn={testActiveTurn()} uxV1 />);
+ const testLabel = screen.getByText("Test-run");
+ // The whole point: an active row must not be a focusable no-op button
+ // (keyboard/screen-reader trap) — it's a plain div.
+ expect(testLabel.closest("button")).toBeNull();
+ const testRow = testLabel.closest("div")!;
+ const before = testRow.parentElement!.innerHTML;
+ fireEvent.click(testRow);
+ expect(testRow.parentElement!.innerHTML).toBe(before);
+ });
+
+ it("hosts FBlockRun exactly once, inside the Test-run nest — no double-render with the legacy flat list", () => {
+ render(<NarrativeView turn={testActiveTurn()} uxV1 />);
+ expect(screen.getAllByText("block_1")).toHaveLength(1);
+ });
+
+ it("a11y: nest-less rows render a plain div, not a button", () => {
+ render(<NarrativeView turn={liveExploreTurn()} uxV1 />);
+ const doneLabel = screen.getByText("Done");
+ expect(doneLabel.closest("button")).toBeNull();
+ });
+
+ it("names the redraft iteration in the shimmered Draft placeholder after a failed verify", () => {
+ const redraftTurn: TurnNarrativeState = {
+ ...EMPTY_NARRATIVE,
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ designEnded: true,
+ terminal: null,
+ authoringCount: 1,
+ activitySeq: 3,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [
+ runningBlock({
+ state: "completed",
+ endedAt: "2026-06-10T00:00:10Z",
+ }),
+ ],
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "outcome not confirmed",
+ activitySeqAtVerdict: 2,
+ },
+ designActivity: [
+ activityEntry({
+ id: "tc-1",
+ kind: "tool_call",
+ toolName: "navigate_browser",
+ }),
+ activityEntry({
+ id: "tc-2",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ }),
+ activityEntry({ id: "n-1", kind: "narration" }),
+ ],
+ };
+ render(<NarrativeView turn={redraftTurn} uxV1 />);
+ expect(
+ screen.getByText(
+ /Draft v2 — revising after failed verify: outcome not confirmed/,
+ ),
+ ).toBeTruthy();
+ });
+
+ it("REGRESSION PIN: never shows redraft copy on an ordinary first build with no prior verdict (Codex catch)", () => {
+ const firstBuildDraftActive: TurnNarrativeState = {
+ ...EMPTY_NARRATIVE,
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ terminal: null,
+ authoringCount: 1,
+ activitySeq: 1,
+ lastRunOutcome: null,
+ designActivity: [
+ activityEntry({
+ id: "tc-1",
+ kind: "tool_call",
+ toolName: "update_workflow",
+ }),
+ ],
+ };
+ render(<NarrativeView turn={firstBuildDraftActive} uxV1 />);
+ expect(screen.getByText("Writing the workflow code…")).toBeTruthy();
+ expect(screen.queryByText(/revising after failed verify/)).toBeNull();
+ });
+
+ it("REGRESSION PIN: Test-run stays expandable when blocks exist even with an empty test-activity bucket (Codex catch)", () => {
+ const historyRowNoTestActivity: TurnNarrativeState = {
+ ...EMPTY_NARRATIVE,
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ designEnded: true,
+ terminal: "response",
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [
+ runningBlock({ state: "completed", endedAt: "2026-06-10T00:00:10Z" }),
+ ],
+ designActivity: [],
+ };
+ render(<NarrativeView turn={historyRowNoTestActivity} uxV1 />);
+ // Terminal turns roll up by default, but the checklist already renders
+ // inline inside the RollupCard — no need to expand into DetailView.
+ const testRow = screen.getByRole("button", { name: /Test-run/ });
+ expect(testRow.getAttribute("aria-expanded")).toBe("false");
+ fireEvent.click(testRow);
+ expect(testRow.getAttribute("aria-expanded")).toBe("true");
+ expect(screen.getByTitle("Highlight block_1 on canvas")).toBeTruthy();
+ });
+
+ it("hydration no-replay pin: a reloaded terminal build turn renders all stubs — zero spinners, zero open nests, no pending timers", () => {
+ vi.useFakeTimers();
+ const payload = {
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ designEnded: true,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [
+ {
+ workflowRunBlockId: "wrb_1",
+ label: "block_1",
+ blockType: "task",
+ state: "completed",
+ lastSeenIteration: 0,
+ activity: [],
+ startedAt: "2026-06-10T00:00:00Z",
+ endedAt: "2026-06-10T00:00:10Z",
+ },
+ ],
+ terminal: "response",
+ terminalMessage: "Done.",
+ narrativeSummary: "Built and tested the workflow.",
+ priorBlockCount: null,
+ designActivity: [
+ {
+ kind: "tool_call",
+ text: "Opening page…",
+ iteration: 0,
+ toolName: "navigate_browser",
+ displayLabel: "Opening page",
+ id: "tc-1",
+ },
+ {
+ kind: "tool_call",
+ text: "Testing workflow…",
+ iteration: 1,
+ toolName: "update_and_run_blocks",
+ displayLabel: "Testing workflow",
+ id: "tc-2",
+ },
+ ],
+ startedAt: "2026-06-10T00:00:00Z",
+ endedAt: "2026-06-10T00:00:10Z",
+ };
+ const hydrated = hydrateNarrativeFromPayload(payload)!;
+
+ render(<NarrativeView turn={hydrated} uxV1 />);
+
+ expect(screen.getByText("Explore site")).toBeTruthy();
+ expect(screen.getByText("Draft code")).toBeTruthy();
+ expect(screen.getByText("Test-run")).toBeTruthy();
+ expect(screen.getByText("Done")).toBeTruthy();
+ expect(document.querySelectorAll(".animate-spin").length).toBe(0);
+ expect(document.querySelectorAll('[aria-expanded="true"]').length).toBe(0);
+ expect(vi.getTimerCount()).toBe(0);
+ vi.useRealTimers();
+ });
+
+ it("shows no checklist rows for a clarify terminal turn that never drafted anything", () => {
+ const clarifyTurn: TurnNarrativeState = {
+ ...EMPTY_NARRATIVE,
+ turnId: "turn-2",
+ turnIndex: 0,
+ mode: "clarify",
+ designStarted: true,
+ terminal: "response",
+ responseType: "ASK_QUESTION",
+ narrativeSummary: "Which login should I use?",
+ draft: null,
+ blocks: [],
+ };
+ render(<NarrativeView turn={clarifyTurn} uxV1 />);
+ expect(screen.queryByText("Explore site")).toBeNull();
+ expect(screen.queryByText("Draft code")).toBeNull();
+ expect(screen.queryByText("Test-run")).toBeNull();
+ });
+
+ it("flag-off parity: uxV1 absent renders today's FDesignRow, zero checklist rows", () => {
+ render(<NarrativeView turn={liveExploreTurn()} />);
+ expect(screen.getByText("Designing the workflow")).toBeTruthy();
+ expect(screen.queryByText("Explore site")).toBeNull();
+ expect(screen.queryByText("Draft code")).toBeNull();
+ expect(screen.queryByText("Test-run")).toBeNull();
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx
index 745137fcd..35c19f3ab 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/NarrativeView.tsx
@@ -1,6 +1,12 @@
import { type ReactNode, useEffect, useMemo, useState } from "react";
import { buildRevealOffsets, revealedCountAt } from "./actionReveal";
+import {
+ CopilotPhaseId,
+ PhaseStatus,
+ derivePhases,
+ showPhaseChecklist,
+} from "./copilotPhases";
import {
ActivityEntry,
BlockState,
@@ -550,6 +556,251 @@ function FDesignRow({ done, blockLabels, activity }: FDesignRowProps) {
);
}
+function FWorkingHeader() {
+ return (
+ <div className="flex items-center gap-2 px-1 py-1">
+ <Spinner />
+ <span className="text-[12.5px] font-semibold text-slate-100">
+ Working…
+ </span>
+ <span className="text-[11px] text-slate-400">
+ · building your workflow
+ </span>
+ </div>
+ );
+}
+
+function phaseGlyph(status: PhaseStatus): ReactNode {
+ switch (status) {
+ case "done":
+ return "✓";
+ case "fail":
+ return "✕";
+ case "active":
+ return <Spinner />;
+ default:
+ return "○";
+ }
+}
+
+function phasePuckClasses(status: PhaseStatus): string {
+ switch (status) {
+ case "done":
+ return "border-emerald-400/60 bg-emerald-500/15 text-emerald-300";
+ case "fail":
+ return "border-rose-400/60 bg-rose-500/15 text-rose-300";
+ case "active":
+ return "border-blue-400/60 bg-blue-500/15 text-blue-300";
+ default:
+ return "border-slate-500/60 bg-slate-elevation3 text-slate-600";
+ }
+}
+
+function phaseLabelClasses(status: PhaseStatus): string {
+ switch (status) {
+ case "active":
+ return "font-semibold text-slate-100";
+ case "fail":
+ return "text-rose-300";
+ case "pending":
+ case "notrun":
+ return "text-slate-500";
+ default:
+ return "text-slate-400";
+ }
+}
+
+// Status is otherwise conveyed only via an aria-hidden glyph/color — this
+// gives screen-reader users the same information as sighted users.
+function phaseStatusWord(status: PhaseStatus): string {
+ switch (status) {
+ case "active":
+ return "Active";
+ case "done":
+ return "Done";
+ case "fail":
+ return "Failed";
+ case "stopped":
+ return "Stopped";
+ case "notrun":
+ return "Not run";
+ default:
+ return "Pending";
+ }
+}
+
+// While Draft is active its stream is necessarily empty (the LLM is writing
+// code, no frames arrive) — one shimmered placeholder row fills that gap,
+// naming the redraft iteration once a prior verify failed.
+function DraftPlaceholderNote({ turn }: { turn: TurnNarrativeState }) {
+ const shimmerRef = useShimmerText<HTMLSpanElement>(true);
+ const priorFailedVerdict =
+ turn.lastRunOutcome?.verdict === "not_demonstrated" ||
+ turn.lastRunOutcome?.verdict === "not_evaluated";
+ const text = priorFailedVerdict
+ ? `Draft v${turn.authoringCount + 1} — revising after failed verify: ${
+ turn.lastRunOutcome?.displayReason ?? "outcome not confirmed"
+ }`
+ : "Writing the workflow code…";
+ return (
+ <FSubRow glyph="▸" glyphClass="text-slate-400">
+ <span
+ ref={shimmerRef}
+ title={text}
+ className="block truncate text-slate-400"
+ >
+ {text}
+ </span>
+ </FSubRow>
+ );
+}
+
+interface FPhaseChecklistProps {
+ turn: TurnNarrativeState;
+ turnEnded: boolean;
+ onBlockSelect?: (label: string) => void;
+}
+
+function FPhaseChecklist({
+ turn,
+ turnEnded,
+ onBlockSelect,
+}: FPhaseChecklistProps) {
+ const rows = useMemo(() => derivePhases(turn), [turn]);
+ const [openPhases, setOpenPhases] = useState<Set<CopilotPhaseId>>(
+ () => new Set(),
+ );
+
+ return (
+ <div className="flex flex-col">
+ {rows.map((row) => {
+ const isActive = row.status === "active";
+ const hasNest =
+ row.id === "draft"
+ ? row.entries.length > 0 ||
+ (turn.draft?.blockLabels.length ?? 0) > 0 ||
+ isActive
+ : row.id === "test"
+ ? row.entries.length > 0 || turn.blocks.length > 0
+ : row.entries.length > 0;
+ const open = isActive || openPhases.has(row.id);
+ const toggleable = hasNest && !isActive;
+ const rowContent = (
+ <>
+ <span
+ className={`flex h-6 w-6 shrink-0 items-center justify-center rounded-full border text-[11px] font-bold ${phasePuckClasses(
+ row.status,
+ )}`}
+ aria-hidden="true"
+ >
+ {phaseGlyph(row.status)}
+ </span>
+ <span
+ className={`flex-1 text-[12.5px] ${phaseLabelClasses(row.status)}`}
+ >
+ {row.label}
+ <span className="sr-only"> · {phaseStatusWord(row.status)}</span>
+ </span>
+ {row.stub ? (
+ <span
+ className={`text-[11px] tabular-nums ${
+ row.status === "fail" ? "text-rose-400" : "text-slate-500"
+ }`}
+ >
+ {row.stub}
+ </span>
+ ) : null}
+ {hasNest ? (
+ <span
+ className={`shrink-0 text-[12px] text-slate-500 transition-transform ${
+ open ? "rotate-90" : ""
+ }`}
+ aria-hidden="true"
+ >
+ ›
+ </span>
+ ) : null}
+ </>
+ );
+ const toggle = () =>
+ setOpenPhases((prev) => {
+ const next = new Set(prev);
+ if (next.has(row.id)) {
+ next.delete(row.id);
+ } else {
+ next.add(row.id);
+ }
+ return next;
+ });
+
+ return (
+ <div key={row.id} className="flex flex-col">
+ {toggleable ? (
+ <button
+ type="button"
+ aria-expanded={open}
+ onClick={toggle}
+ className="flex w-full cursor-pointer items-center gap-3 px-1 py-1 text-left"
+ >
+ {rowContent}
+ </button>
+ ) : (
+ // Active rows render inert (a button whose click is a no-op
+ // would be a keyboard/screen-reader trap) — status is
+ // conveyed via the sr-only word in rowContent instead.
+ <div className="flex w-full items-center gap-3 px-1 py-1 text-left">
+ {rowContent}
+ </div>
+ )}
+ {open ? (
+ <div className="ml-[25px] flex flex-col gap-1.5 rounded-lg border border-slate-700/60 bg-slate-elevation1 px-3 py-2">
+ {row.id === "draft" ? (
+ <>
+ {row.entries.map((entry) => (
+ <ActivityRow key={entry.id} entry={entry} />
+ ))}
+ {(turn.draft?.blockLabels ?? []).map((label) => (
+ <FSubRow
+ key={label}
+ glyph="✦"
+ glyphClass="text-emerald-300"
+ >
+ <span className="text-slate-400">Drafted </span>
+ <span className="font-mono text-slate-100">
+ {label}
+ </span>
+ </FSubRow>
+ ))}
+ {isActive ? <DraftPlaceholderNote turn={turn} /> : null}
+ </>
+ ) : row.id === "test" ? (
+ <>
+ {row.entries.map((entry) => (
+ <ActivityRow key={entry.id} entry={entry} />
+ ))}
+ {turn.blocks.map((b) => (
+ <FBlockRun
+ key={b.workflowRunBlockId || b.label}
+ block={b}
+ turnEnded={turnEnded}
+ onSelect={onBlockSelect}
+ />
+ ))}
+ </>
+ ) : (
+ row.entries.map((entry) => (
+ <ActivityRow key={entry.id} entry={entry} />
+ ))
+ )}
+ </div>
+ ) : null}
+ </div>
+ );
+ })}
+ </div>
+ );
+}
+
function accentBg(accent: TurnSummary["accent"]): string {
if (accent === "fail") {
return "border-rose-400/60 bg-rose-500/15 text-rose-300";
@@ -612,15 +863,24 @@ interface RollupCardProps {
turn: TurnNarrativeState;
summary: TurnSummary;
onExpand: () => void;
+ onBlockSelect?: (label: string) => void;
+ uxV1?: boolean;
}
-function RollupCard({ turn, summary, onExpand }: RollupCardProps) {
+function RollupCard({
+ turn,
+ summary,
+ onExpand,
+ onBlockSelect,
+ uxV1,
+}: RollupCardProps) {
const closing =
turn.narrativeSummary?.trim() || turn.terminalMessage?.trim() || "";
const rollupBlocks = latestBlocksByLabel(turn.blocks);
const completed = rollupBlocks.filter((b) => isBlockOk(b));
const failed = rollupBlocks.filter((b) => b.state === "failed");
const showCommit = !summary.isQA && completed.length > 0;
+ const showChecklist = Boolean(uxV1) && showPhaseChecklist(turn);
return (
<div className="overflow-hidden rounded-xl border border-slate-700/60 bg-slate-elevation2">
@@ -643,6 +903,16 @@ function RollupCard({ turn, summary, onExpand }: RollupCardProps) {
}
/>
+ {showChecklist ? (
+ <div className="border-t border-white/5 px-3.5 py-2">
+ <FPhaseChecklist
+ turn={turn}
+ turnEnded
+ onBlockSelect={onBlockSelect}
+ />
+ </div>
+ ) : null}
+
{showCommit ? (
<div className="border-t border-white/5 pb-3 pl-[52px] pr-3.5 pt-2.5">
<div className="mb-1.5 text-[10px] font-bold uppercase tracking-[.06em] text-slate-500">
@@ -709,9 +979,15 @@ interface DetailViewProps {
turn: TurnNarrativeState;
onCollapse: (() => void) | null;
onBlockSelect?: (label: string) => void;
+ uxV1?: boolean;
}
-function DetailView({ turn, onCollapse, onBlockSelect }: DetailViewProps) {
+function DetailView({
+ turn,
+ onCollapse,
+ onBlockSelect,
+ uxV1,
+}: DetailViewProps) {
const hasBlocks = turn.blocks.length > 0;
const designStarted = turn.designStarted;
const designOpen = designStarted && !turn.designEnded;
@@ -721,6 +997,7 @@ function DetailView({ turn, onCollapse, onBlockSelect }: DetailViewProps) {
// long design phase isn't silently invisible.
const hasDraft = (turn.draft?.blockCount ?? 0) > 0;
const showDesign = designStarted && (hasDraft || hasBlocks || !turn.terminal);
+ const showChecklist = Boolean(uxV1) && showPhaseChecklist(turn);
const preBlockNarration = turn.designActivity.filter(
(e) => e.kind === "narration",
);
@@ -741,7 +1018,16 @@ function DetailView({ turn, onCollapse, onBlockSelect }: DetailViewProps) {
</button>
) : null}
- {showDesign ? (
+ {showChecklist ? (
+ <>
+ {turn.terminal === null ? <FWorkingHeader /> : null}
+ <FPhaseChecklist
+ turn={turn}
+ turnEnded={turn.terminal !== null}
+ onBlockSelect={onBlockSelect}
+ />
+ </>
+ ) : showDesign ? (
<FDesignRow
done={!designOpen}
blockLabels={turn.draft?.blockLabels ?? []}
@@ -753,7 +1039,7 @@ function DetailView({ turn, onCollapse, onBlockSelect }: DetailViewProps) {
))
) : null}
- {hasBlocks ? (
+ {!showChecklist && hasBlocks ? (
<div className="flex flex-col gap-1">
{turn.blocks.map((b) => (
<FBlockRun
@@ -810,6 +1096,8 @@ export function NarrativeView({
turn={turn}
summary={summary}
onExpand={() => setUserRolled(false)}
+ onBlockSelect={onBlockSelect}
+ uxV1={uxV1}
/>
);
}
@@ -819,6 +1107,7 @@ export function NarrativeView({
turn={turn}
onCollapse={isComplete ? () => setUserRolled(true) : null}
onBlockSelect={onBlockSelect}
+ uxV1={uxV1}
/>
);
}
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.composerControls.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.composerControls.test.tsx
new file mode 100644
index 000000000..488ddcfbe
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.composerControls.test.tsx
@@ -0,0 +1,313 @@
+import {
+ act,
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+import {
+ FeatureFlagContext,
+ FeatureFlagValueContext,
+} from "@/hooks/useFeatureFlag";
+
+type StreamBody = {
+ message: string;
+ mode: string | null;
+ code_block: boolean | null;
+};
+type StreamCall = {
+ body: StreamBody;
+ onMessage: (payload: unknown) => boolean;
+ resolve: () => void;
+ reject: (error: unknown) => void;
+};
+
+const { mockCopilotUxV1Enabled } = vi.hoisted(() => ({
+ mockCopilotUxV1Enabled: vi.fn(() => true),
+}));
+
+vi.mock("posthog-js/react", () => ({
+ useFeatureFlagEnabled: () => mockCopilotUxV1Enabled(),
+}));
+
+const { streamCalls, postStreaming, cancelPost, historyResponse } = vi.hoisted(
+ () => {
+ const calls: StreamCall[] = [];
+ const post = vi.fn().mockResolvedValue({});
+ const streaming = vi.fn(
+ (
+ _path: string,
+ body: StreamBody,
+ onMessage: (payload: unknown) => boolean,
+ ) =>
+ new Promise<void>((resolve, reject) => {
+ calls.push({ body, onMessage, resolve, reject });
+ }),
+ );
+ const history = {
+ data: {
+ workflow_copilot_chat_id: null as string | null,
+ chat_history: [] as unknown[],
+ proposed_workflow: null as Record<string, unknown> | null,
+ auto_accept: false,
+ },
+ };
+ return {
+ streamCalls: calls,
+ postStreaming: streaming,
+ cancelPost: post,
+ historyResponse: history,
+ };
+ },
+);
+
+vi.mock("@/api/sse", () => ({
+ getSseClient: vi.fn().mockResolvedValue({ postStreaming }),
+}));
+
+vi.mock("@/api/AxiosClient", () => ({
+ getClient: vi.fn().mockResolvedValue({
+ get: vi.fn().mockImplementation(() => Promise.resolve(historyResponse)),
+ post: cancelPost,
+ }),
+}));
+
+vi.mock("@/hooks/useCredentialGetter", () => ({
+ useCredentialGetter: () => null,
+}));
+
+vi.mock("@/components/ui/use-toast", () => ({ toast: vi.fn() }));
+
+vi.mock("react-router-dom", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("react-router-dom")>();
+ return {
+ ...actual,
+ useParams: () => ({
+ workflowPermanentId: "wpid_1",
+ workflowRunId: undefined,
+ }),
+ useSearchParams: () => [new URLSearchParams(), vi.fn()],
+ };
+});
+
+const saveData = {
+ title: "Test WF",
+ workflow: {
+ workflow_id: "wf_1",
+ workflow_permanent_id: "wpid_1",
+ description: "",
+ totp_verification_url: null,
+ is_saved_task: false,
+ status: "published",
+ },
+ settings: {
+ proxyLocation: null,
+ webhookCallbackUrl: null,
+ persistBrowserSession: false,
+ pinSavedSessionIp: false,
+ browserProfileId: null,
+ browserProfileKey: null,
+ model: null,
+ maxScreenshotScrolls: null,
+ extraHttpHeaders: null,
+ runWith: "agent",
+ scriptCacheKey: "",
+ aiFallback: true,
+ codeVersion: 2,
+ runSequentially: false,
+ sequentialKey: null,
+ },
+ parameters: [],
+ blocks: [],
+ workflowDefinitionVersion: 1,
+};
+
+vi.mock("@/store/WorkflowHasChangesStore", () => ({
+ useWorkflowHasChangesStore: () => ({ getSaveData: () => saveData }),
+}));
+
+vi.mock("@/routes/workflows/hooks/useWorkflowRunQuery", () => ({
+ useWorkflowRunQuery: () => ({ data: undefined }),
+}));
+
+import { WorkflowCopilotChat } from "./WorkflowCopilotChat";
+
+type FlagConfig = {
+ copilotV2?: boolean;
+ codeBlockMode?: boolean;
+ requiresLiveBrowser?: boolean;
+ isLiveBrowserReady?: boolean;
+};
+
+async function renderChat(flags: FlagConfig) {
+ const booleanFlags: Record<string, boolean> = {
+ ENABLE_WORKFLOW_COPILOT_V2: flags.copilotV2 ?? false,
+ WORKFLOW_COPILOT_CODE_BLOCK_MODE: flags.codeBlockMode ?? false,
+ CODE_BLOCK_ACCESS: flags.codeBlockMode ?? false,
+ };
+ const view = render(
+ <FeatureFlagContext.Provider value={(name) => booleanFlags[name]}>
+ <FeatureFlagValueContext.Provider value={() => undefined}>
+ <WorkflowCopilotChat
+ requiresLiveBrowser={flags.requiresLiveBrowser}
+ isLiveBrowserReady={flags.isLiveBrowserReady}
+ />
+ </FeatureFlagValueContext.Provider>
+ </FeatureFlagContext.Provider>,
+ );
+ await waitFor(() => expect(screen.getByRole("textbox")).toBeTruthy());
+ return view;
+}
+
+function textarea(): HTMLTextAreaElement {
+ return screen.getByRole("textbox") as HTMLTextAreaElement;
+}
+
+async function submit(value: string) {
+ fireEvent.change(textarea(), { target: { value } });
+ await act(async () => {
+ fireEvent.keyDown(textarea(), { key: "Enter" });
+ });
+}
+
+beforeEach(() => {
+ HTMLElement.prototype.scrollIntoView = vi.fn();
+ HTMLElement.prototype.scrollTo = vi.fn();
+ mockCopilotUxV1Enabled.mockReset();
+ mockCopilotUxV1Enabled.mockReturnValue(true);
+ streamCalls.length = 0;
+ postStreaming.mockClear();
+ cancelPost.mockClear();
+ historyResponse.data = {
+ workflow_copilot_chat_id: null,
+ chat_history: [],
+ proposed_workflow: null,
+ auto_accept: false,
+ };
+});
+
+afterEach(() => {
+ cleanup();
+});
+
+describe("WorkflowCopilotChat — S4 composer, copilot_ux_v1 on", () => {
+ it("defaults straight to Build with code when code-first is accessible", async () => {
+ await renderChat({ copilotV2: true, codeBlockMode: true });
+ await submit("build me a workflow");
+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));
+
+ expect(streamCalls[0]?.body.mode).toBe("build");
+ expect(streamCalls[0]?.body.code_block).toBe(true);
+ expect(
+ screen.getByRole("button", { name: "Switch mode" }).textContent,
+ ).toContain("Build with code");
+ });
+
+ it("falls back to plain Build when the code-block flag is off", async () => {
+ await renderChat({ copilotV2: true, codeBlockMode: false });
+ await submit("build me a workflow");
+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));
+
+ expect(streamCalls[0]?.body.mode).toBe("build");
+ expect(streamCalls[0]?.body.code_block).toBe(null);
+ const pillText = screen.getByRole("button", {
+ name: "Switch mode",
+ }).textContent;
+ expect(pillText).toContain("Build");
+ expect(pillText).not.toContain("Build with code");
+ });
+
+ it("opens the mode pill as a real Radix menu, not a hand-rolled div", async () => {
+ await renderChat({ copilotV2: true, codeBlockMode: true });
+ const trigger = screen.getByRole("button", { name: "Switch mode" });
+ expect(trigger.getAttribute("aria-haspopup")).toBe("menu");
+
+ await act(async () => {
+ fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false });
+ });
+ expect(await screen.findByRole("menu")).toBeTruthy();
+
+ const askItem = await screen.findByRole("menuitem", { name: "Ask" });
+ await act(async () => {
+ fireEvent.click(askItem);
+ });
+ await submit("what does this workflow do?");
+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));
+ expect(streamCalls[0]?.body.mode).toBe("ask");
+ });
+
+ it("morphs to stop while running with an empty box, and cancels the run on click", async () => {
+ await renderChat({ copilotV2: true, codeBlockMode: true });
+ await submit("build me a workflow");
+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));
+
+ const button = screen.getByRole("button", { name: "Stop" });
+ await act(async () => {
+ fireEvent.click(button);
+ });
+ await waitFor(() => expect(cancelPost).toHaveBeenCalledTimes(1));
+ expect(cancelPost).toHaveBeenCalledWith(
+ "/workflow/copilot/cancel",
+ expect.anything(),
+ );
+ });
+
+ it("flips back to a queueing send when typing mid-run, and queues on click", async () => {
+ await renderChat({ copilotV2: true, codeBlockMode: true });
+ await submit("build me a workflow");
+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));
+
+ fireEvent.change(textarea(), {
+ target: { value: "also grab the story scores" },
+ });
+ const button = screen.getByRole("button", {
+ name: "Queue for next turn",
+ });
+
+ await act(async () => {
+ fireEvent.click(button);
+ });
+
+ // Queued, not sent as a second concurrent turn.
+ expect(postStreaming).toHaveBeenCalledTimes(1);
+ expect(screen.getByText("Queued")).toBeTruthy();
+ // Exactly one status line — the Queued chip, not also the legacy
+ // aria-live text line (browserStatusText is suppressed under S4 so the
+ // two don't announce the same status twice).
+ expect(
+ screen.getAllByText("Queued — sends when this turn finishes."),
+ ).toHaveLength(1);
+ });
+
+ it("disables the morph button (not a dead-looking Send) while a prompt waits on the live browser", async () => {
+ await renderChat({
+ copilotV2: true,
+ codeBlockMode: true,
+ requiresLiveBrowser: true,
+ isLiveBrowserReady: false,
+ });
+ await submit("build me a workflow");
+
+ // No turn started yet — queued purely on the live-browser gate.
+ expect(postStreaming).not.toHaveBeenCalled();
+ expect(
+ screen.getByText("Prompt queued. Waiting for live browser..."),
+ ).toBeTruthy();
+
+ const button = screen.getByRole("button", {
+ name: "Send disabled — waiting for live browser",
+ });
+ expect((button as HTMLButtonElement).disabled).toBe(true);
+
+ const cancel = screen.getByRole("button", {
+ name: "Cancel queued message",
+ });
+ await act(async () => {
+ fireEvent.click(cancel);
+ });
+ expect(screen.queryByText("Queued")).toBeNull();
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.composerMode.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.composerMode.test.tsx
index 660e83daa..10189289f 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.composerMode.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.composerMode.test.tsx
@@ -85,8 +85,11 @@ vi.mock("react-router-dom", async (importOriginal) => {
};
});
+// This suite exercises the legacy (copilot_ux_v1 off) default-mode logic; no
+// test here touches copilot_ux_v1-gated behavior, so pin it off rather than
+// the stray `true` this file previously carried over from SKY-11973's mock.
vi.mock("posthog-js/react", () => ({
- useFeatureFlagEnabled: () => true,
+ useFeatureFlagEnabled: () => false,
}));
const saveData = {
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx
index f38e38f9e..60a82f5c1 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx
+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx
@@ -16,6 +16,8 @@ import {
Cross2Icon,
ChevronDownIcon,
CheckIcon,
+ ArrowUpIcon,
+ StopIcon,
} from "@radix-ui/react-icons";
import { createPortal } from "react-dom";
import { stringify as convertToYAML } from "yaml";
@@ -62,6 +64,7 @@ import {
resolveSendAction,
} from "./sendQueue";
import { shouldAutoApplyWorkflowResponse } from "./proposalDisposition";
+import { shouldArmDraftingGapTimer } from "./copilotPhases";
import { NarrativeView } from "./NarrativeView";
import { useRunLifecycleAnnouncements } from "./useRunLifecycleAnnouncements";
import { DiffCard, shouldShowDiffCard } from "./cards/DiffCard";
@@ -90,6 +93,8 @@ import {
} from "@/components/ui/dropdown-menu";
import { cn, formatElapsedSeconds } from "@/util/utils";
import { COPILOT_UX_V1_FLAG } from "@/util/featureFlags";
+import { ControlTooltip } from "@/routes/workflows/studio/ControlTooltip";
+import { TooltipProvider } from "@/components/ui/tooltip";
// Cap on retained per-turn snap-back snapshots. A typical session has a
// handful of turns; this ceiling guards a runaway long-running chat.
@@ -558,11 +563,23 @@ export function WorkflowCopilotChat({
const defaultModeVariant = useFeatureFlagValue(
"WORKFLOW_COPILOT_DEFAULT_MODE",
);
+ // S4: under the campaign flag, default straight to code-first (skipping the
+ // WORKFLOW_COPILOT_DEFAULT_MODE A/B variant) whenever code-first is accessible.
+ const codeFirstAccessible = copilotV2Enabled && codeBlockModeEnabled;
+ const s4DefaultVariant: ComposerDefaultVariant = codeFirstAccessible
+ ? "build_code"
+ : "build";
// The variant configures the initial default only when both gating flags are on.
- const effectiveDefaultVariant: ComposerDefaultVariant =
- copilotV2Enabled && codeBlockModeEnabled
+ const effectiveDefaultVariant: ComposerDefaultVariant = copilotUxV1Enabled
+ ? s4DefaultVariant
+ : copilotV2Enabled && codeBlockModeEnabled
? normalizeComposerDefaultVariant(defaultModeVariant)
: "build";
+ // codeBlockRequestOverride keys off the same source effectiveDefaultVariant
+ // used, not the raw flag value, so the S4 default stays internally consistent.
+ const codeOverrideVariantSource = copilotUxV1Enabled
+ ? s4DefaultVariant
+ : defaultModeVariant;
const [composerMode, setComposerMode] = useState<"ask" | "build">(() =>
effectiveDefaultVariant === "ask" || effectiveDefaultVariant === "ask_code"
? "ask"
@@ -573,7 +590,7 @@ export function WorkflowCopilotChat({
);
const [codeBlockRequestOverride, setCodeBlockRequestOverride] = useState<
boolean | null
- >(() => defaultCodeBlockRequestOverride(defaultModeVariant));
+ >(() => defaultCodeBlockRequestOverride(codeOverrideVariantSource));
// Flags arrive asynchronously from /customer; seed the default once they resolve, never again.
const composerSeededRef = useRef(false);
const flagsResolved =
@@ -593,9 +610,15 @@ export function WorkflowCopilotChat({
);
setCodeWorkflow(defaultVariantUsesCode(effectiveDefaultVariant));
setCodeBlockRequestOverride(
- defaultCodeBlockRequestOverride(defaultModeVariant),
+ defaultCodeBlockRequestOverride(codeOverrideVariantSource),
);
- }, [flagsResolved, effectiveDefaultVariant, defaultModeVariant]);
+ }, [
+ flagsResolved,
+ effectiveDefaultVariant,
+ defaultModeVariant,
+ copilotUxV1Enabled,
+ codeOverrideVariantSource,
+ ]);
// Build can never be active unless the V2 flag is on.
const isBuild = copilotV2Enabled && composerMode === "build";
const codeToggleAllowed = effectiveDefaultVariant !== "build_no_code";
@@ -805,6 +828,28 @@ export function WorkflowCopilotChat({
workflowPermanentId,
],
);
+ // Explore/Draft boundary is unobservable (the LLM writes code with no
+ // frames emitted); after DRAFTING_GAP_MS of silence with no pending block
+ // run, assume Draft has started. Re-arms per narrative update; the reducer
+ // guard makes a stale or double-fired timer a no-op.
+ const DRAFTING_GAP_MS = 8000;
+ useEffect(() => {
+ if (!copilotUxV1Enabled) return;
+ if (!shouldArmDraftingGapTimer(narrative)) return;
+ const wait = Math.max(
+ 0,
+ DRAFTING_GAP_MS - (Date.now() - narrative.lastActivityAtMs!),
+ );
+ const t = setTimeout(
+ () =>
+ applyStoredNarrativeEvent({
+ type: "client_phase_hint",
+ hintedAtMs: Date.now(),
+ }),
+ wait,
+ );
+ return () => clearTimeout(t);
+ }, [narrative, applyStoredNarrativeEvent, copilotUxV1Enabled]);
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
const { getSaveData } = useWorkflowHasChangesStore();
const hasInitializedPosition = useRef(false);
@@ -813,7 +858,6 @@ export function WorkflowCopilotChat({
requiresLiveBrowser,
isLiveBrowserReady,
});
- const isQueuedPromptWaiting = Boolean(queuedPrompt);
// Reset on initialMessage change so a re-arrival of the prop (without a
// remount) can fire auto-send again.
useEffect(() => {
@@ -2377,8 +2421,12 @@ export function WorkflowCopilotChat({
queuedPrompt?.reason === "working"
? "Queued — sends when this turn finishes."
: "Prompt queued. Waiting for live browser...";
+ // S4's Queued chip already surfaces queuedPromptWaitingStatus; don't
+ // duplicate it as a second status line above the composer.
const browserStatusText = queuedPrompt
- ? queuedPromptWaitingStatus
+ ? copilotUxV1Enabled && copilotV2Enabled
+ ? null
+ : queuedPromptWaitingStatus
: isLoading
? "Copilot is working. Your next send will wait for the next turn."
: isWaitingForLiveBrowser
@@ -2399,6 +2447,98 @@ export function WorkflowCopilotChat({
// Mid-turn Accept would be clobbered by the in-flight turn's terminal
// restore, so gate actions wait for idle.
const gateActionable = Boolean(proposedWorkflow) && !isLoading;
+ const hasComposerText = inputValue.trim().length > 0;
+ // A live_browser-reason queued prompt parks with no active turn to stop and
+ // a disabled, emptied textarea — the morph button would otherwise render as
+ // a live "Send" that's a guaranteed no-op; only the Queued chip's ✕ acts.
+ const waitingOnQueueOnly = queuedPrompt?.reason === "live_browser";
+ const morphButtonLabel = waitingOnQueueOnly
+ ? "Send disabled — waiting for live browser"
+ : !isLoading
+ ? "Send"
+ : hasComposerText
+ ? "Queue for next turn"
+ : "Stop";
+ // Shared between the legacy fused split-button and the S4 mode pill so the
+ // three options never drift between the two composer treatments.
+ const modeMenuItems = (
+ <>
+ <DropdownMenuItem
+ aria-label="Ask"
+ onSelect={() => {
+ setComposerMode("ask");
+ setCodeWorkflow(false);
+ setCodeBlockRequestOverride(null);
+ }}
+ className={cn("flex items-start gap-2.5", !isBuild && "bg-accent")}
+ >
+ <ModeGlyph mode="ask" />
+ <span className="flex flex-1 flex-col">
+ <span className="text-sm font-medium">Ask</span>
+ <span className="text-xs leading-snug text-muted-foreground">
+ Answer questions and make quick workflow edits.
+ </span>
+ </span>
+ {!isBuild ? <CheckIcon className="h-4 w-4 text-sky-400" /> : null}
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ aria-label="Build"
+ onSelect={() => {
+ setComposerMode("build");
+ setCodeWorkflow(false);
+ setCodeBlockRequestOverride(false);
+ }}
+ className={cn(
+ "flex items-start gap-2.5",
+ isBuild && !codeWorkflow && "bg-accent",
+ )}
+ >
+ <ModeGlyph mode="build" />
+ <span className="flex flex-1 flex-col">
+ <span className="text-sm font-medium">Build</span>
+ <span className="text-xs leading-snug text-muted-foreground">
+ Navigates the site to design your workflow, then tests that it
+ works.
+ </span>
+ </span>
+ {isBuild && !codeWorkflow ? (
+ <CheckIcon className="h-4 w-4 text-sky-400" />
+ ) : null}
+ </DropdownMenuItem>
+ {codeOptionAvailable ? (
+ <DropdownMenuItem
+ aria-label={
+ copilotUxV1Enabled ? "Build with code" : "Build workflow as code"
+ }
+ onSelect={() => {
+ setComposerMode("build");
+ setCodeWorkflow(true);
+ setCodeBlockRequestOverride(true);
+ }}
+ className={cn(
+ "flex items-start gap-2.5",
+ isBuild && codeWorkflow && "bg-accent",
+ )}
+ >
+ <ModeGlyph mode="build" glow />
+ <span className="flex flex-1 flex-col">
+ <span className="text-sm font-medium">
+ {copilotUxV1Enabled
+ ? "Build with code"
+ : "Build workflow as code"}
+ </span>
+ <span className="text-xs leading-snug text-muted-foreground">
+ Build the workflow as code. Faster and more flexible, but may need
+ extra detail to handle every edge case.
+ </span>
+ </span>
+ {isBuild && codeWorkflow ? (
+ <CheckIcon className="h-4 w-4 text-sky-400" />
+ ) : null}
+ </DropdownMenuItem>
+ ) : null}
+ </>
+ );
const content = (
<div
@@ -2505,8 +2645,6 @@ export function WorkflowCopilotChat({
/>
{messages.map((message, index) => {
const isLastMessage = index === lastTurnIndex;
- const showQueuedFooter =
- isQueuedPromptWaiting && message.id === queuedPrompt?.id;
if (message.kind === "run_lifecycle") {
return (
<RunLifecycleLine
@@ -2649,12 +2787,7 @@ export function WorkflowCopilotChat({
key={message.id}
message={message}
footer={
- showQueuedFooter ? (
- <div className="flex items-center gap-2 text-xs text-muted-foreground">
- <ReloadIcon className="h-3 w-3 animate-spin" />
- <span>{queuedPromptWaitingStatus}</span>
- </div>
- ) : copilotUxV1Enabled && isGateOwnerOrLast ? (
+ copilotUxV1Enabled && isGateOwnerOrLast ? (
<ReviewGateCard
pending
verdict={getReviewGateVerdict(
@@ -2749,6 +2882,42 @@ export function WorkflowCopilotChat({
{/* Input */}
<div className="border-t border-border p-3">
+ {copilotUxV1Enabled && copilotV2Enabled ? (
+ <div className="mb-2">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <button
+ type="button"
+ title="Switch mode"
+ aria-label="Switch mode"
+ className="flex items-center gap-1.5 rounded-full border border-border bg-slate-elevation2 px-2.5 py-1 text-[11px] font-medium text-muted-foreground hover:bg-slate-elevation3 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
+ >
+ <span>Mode:</span>
+ <ModeGlyph
+ mode={isBuild ? "build" : "ask"}
+ glow={codeStateActive}
+ />
+ <span className="text-foreground">
+ {codeStateActive
+ ? "Build with code"
+ : isBuild
+ ? "Build"
+ : "Ask"}
+ </span>
+ <ChevronDownIcon className="h-3 w-3" />
+ </button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent
+ side="top"
+ align="start"
+ className="w-[272px] p-1.5"
+ onCloseAutoFocus={(event) => event.preventDefault()}
+ >
+ {modeMenuItems}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ ) : null}
{copilotUxV1Enabled &&
proposedWorkflow &&
pendingProposalTurnId &&
@@ -2775,6 +2944,22 @@ export function WorkflowCopilotChat({
pending · Review
</button>
) : null}
+ {copilotUxV1Enabled && copilotV2Enabled && queuedPrompt ? (
+ <div className="mb-2 flex items-center gap-2 rounded-lg border border-border bg-slate-elevation2 px-2.5 py-1.5 text-xs text-muted-foreground">
+ <ReloadIcon className="h-3 w-3 shrink-0 animate-spin" />
+ <span className="shrink-0 font-medium text-foreground">Queued</span>
+ <span className="flex-1 truncate">{queuedPromptWaitingStatus}</span>
+ <button
+ type="button"
+ onClick={cancelQueuedPrompt}
+ title="Cancel queued message"
+ aria-label="Cancel queued message"
+ className="shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground"
+ >
+ <Cross2Icon className="h-3 w-3" />
+ </button>
+ </div>
+ ) : null}
{inputStatusText ? (
<div
className="mb-2 text-xs text-muted-foreground"
@@ -2790,7 +2975,14 @@ export function WorkflowCopilotChat({
isHearingSpeech={isSpeechHearing}
disabled={inputDisabled}
onToggle={toggleSpeech}
- className="h-10 w-10 rounded-lg"
+ className={
+ copilotUxV1Enabled && copilotV2Enabled
+ ? "h-8 w-8 rounded-full border-0 bg-transparent"
+ : "h-10 w-10 rounded-lg"
+ }
+ iconClassName={
+ copilotUxV1Enabled && copilotV2Enabled ? "h-3.5 w-3.5" : undefined
+ }
/>
<textarea
ref={setTextareaRef}
@@ -2816,7 +3008,35 @@ export function WorkflowCopilotChat({
overflowY: "hidden",
}}
/>
- {isLoading && queuedPrompt ? (
+ {copilotUxV1Enabled && copilotV2Enabled ? (
+ <TooltipProvider>
+ <ControlTooltip
+ content={morphButtonLabel}
+ blocked={waitingOnQueueOnly}
+ >
+ <button
+ type="button"
+ disabled={waitingOnQueueOnly}
+ onClick={() =>
+ isLoading && !hasComposerText ? cancelSend() : handleSend()
+ }
+ aria-label={morphButtonLabel}
+ className={cn(
+ "flex h-9 w-9 shrink-0 items-center justify-center rounded-lg transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
+ isLoading && !hasComposerText
+ ? "bg-slate-elevation4 text-foreground hover:bg-slate-elevation3"
+ : "bg-cta text-cta-foreground hover:bg-cta-hover",
+ )}
+ >
+ {isLoading && !hasComposerText ? (
+ <StopIcon className="h-3 w-3" />
+ ) : (
+ <ArrowUpIcon className="h-4 w-4" />
+ )}
+ </button>
+ </ControlTooltip>
+ </TooltipProvider>
+ ) : isLoading && queuedPrompt ? (
<>
<button
onClick={cancelQueuedPrompt}
@@ -2910,81 +3130,7 @@ export function WorkflowCopilotChat({
className="w-[272px] p-1.5"
onCloseAutoFocus={(event) => event.preventDefault()}
>
- <DropdownMenuItem
- aria-label="Ask"
- onSelect={() => {
- setComposerMode("ask");
- setCodeWorkflow(false);
- setCodeBlockRequestOverride(null);
- }}
- className={cn(
- "flex items-start gap-2.5",
- !isBuild && "bg-accent",
- )}
- >
- <ModeGlyph mode="ask" />
- <span className="flex flex-1 flex-col">
- <span className="text-sm font-medium">Ask</span>
- <span className="text-xs leading-snug text-muted-foreground">
- Answer questions and make quick workflow edits.
- </span>
- </span>
- {!isBuild ? (
- <CheckIcon className="h-4 w-4 text-sky-400" />
- ) : null}
- </DropdownMenuItem>
- <DropdownMenuItem
- aria-label="Build"
- onSelect={() => {
- setComposerMode("build");
- setCodeWorkflow(false);
- setCodeBlockRequestOverride(false);
- }}
- className={cn(
- "flex items-start gap-2.5",
- isBuild && !codeWorkflow && "bg-accent",
- )}
- >
- <ModeGlyph mode="build" />
- <span className="flex flex-1 flex-col">
- <span className="text-sm font-medium">Build</span>
- <span className="text-xs leading-snug text-muted-foreground">
- Navigates the site to design your workflow, then tests
- that it works.
- </span>
- </span>
- {isBuild && !codeWorkflow ? (
- <CheckIcon className="h-4 w-4 text-sky-400" />
- ) : null}
- </DropdownMenuItem>
- {codeOptionAvailable ? (
- <DropdownMenuItem
- aria-label="Build workflow as code"
- onSelect={() => {
- setComposerMode("build");
- setCodeWorkflow(true);
- setCodeBlockRequestOverride(true);
- }}
- className={cn(
- "flex items-start gap-2.5",
- isBuild && codeWorkflow && "bg-accent",
- )}
- >
- <ModeGlyph mode="build" glow />
- <span className="flex flex-1 flex-col">
- <span className="text-sm font-medium">
- Build workflow as code
- </span>
- <span className="text-xs leading-snug text-muted-foreground">
- Build the workflow as code. Faster and more flexible,
- but may need extra detail to handle every edge case.
- </span>
- </span>
- {isBuild && codeWorkflow ? (
- <CheckIcon className="h-4 w-4 text-sky-400" />
- ) : null}
- </DropdownMenuItem>
- ) : null}
+ {modeMenuItems}
</DropdownMenuContent>
</DropdownMenu>
</div>
diff --git a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts
new file mode 100644
index 000000000..00e87c8b1
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.test.ts
@@ -0,0 +1,521 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ AUTHORING_TOOLS,
+ RUN_TOOLS,
+ derivePhases,
+ shouldArmDraftingGapTimer,
+ showPhaseChecklist,
+} from "./copilotPhases";
+import {
+ ActivityEntry,
+ BlockState,
+ EMPTY_NARRATIVE,
+ TurnNarrativeState,
+} from "./narrativeState";
+
+const entry = (
+ overrides: Partial<ActivityEntry> & Pick<ActivityEntry, "id" | "kind">,
+): ActivityEntry => ({
+ text: "did something",
+ iteration: 0,
+ ...overrides,
+});
+
+const block = (overrides: Partial<BlockState> = {}): BlockState => ({
+ workflowRunBlockId: "wrb_1",
+ label: "block_1",
+ blockType: "task",
+ state: "completed",
+ lastSeenIteration: 0,
+ activity: [],
+ startedAt: "2026-06-10T00:00:00Z",
+ endedAt: "2026-06-10T00:00:10Z",
+ ...overrides,
+});
+
+const turn = (
+ overrides: Partial<TurnNarrativeState> = {},
+): TurnNarrativeState => ({
+ ...EMPTY_NARRATIVE,
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ ...overrides,
+});
+
+function phase(rows: ReturnType<typeof derivePhases>, id: string) {
+ return rows.find((r) => r.id === id)!;
+}
+
+describe("AUTHORING_TOOLS / RUN_TOOLS", () => {
+ it("update_workflow is authoring-only, not a run tool (Codex catch)", () => {
+ expect(AUTHORING_TOOLS.has("update_workflow")).toBe(true);
+ expect(RUN_TOOLS.has("update_workflow")).toBe(false);
+ });
+
+ it("update_and_run_blocks is both authoring and a run tool", () => {
+ expect(AUTHORING_TOOLS.has("update_and_run_blocks")).toBe(true);
+ expect(RUN_TOOLS.has("update_and_run_blocks")).toBe(true);
+ });
+
+ it("run_blocks_and_collect_debug is a run tool only, not authoring", () => {
+ expect(RUN_TOOLS.has("run_blocks_and_collect_debug")).toBe(true);
+ expect(AUTHORING_TOOLS.has("run_blocks_and_collect_debug")).toBe(false);
+ });
+});
+
+describe("derivePhases — bucket split keeps update_workflow in Draft (Codex catch)", () => {
+ it("an update_workflow tool_call on a draft-only turn lands in the Draft bucket, not Test", () => {
+ const t = turn({
+ designEnded: true,
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({ id: "2", kind: "tool_call", toolName: "update_workflow" }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "draft").entries.map((e) => e.id)).toEqual(["2"]);
+ expect(phase(rows, "test").entries).toEqual([]);
+ });
+});
+
+describe("derivePhases — bucket split", () => {
+ it("routes pre-authoring activity to explore, RUN_TOOLS to test, post-authoring narration to draft", () => {
+ const t = turn({
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({ id: "2", kind: "narration" }),
+ entry({
+ id: "3",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ }),
+ entry({ id: "4", kind: "narration" }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "explore").entries.map((e) => e.id)).toEqual(["1", "2"]);
+ expect(phase(rows, "test").entries.map((e) => e.id)).toEqual(["3"]);
+ expect(phase(rows, "draft").entries.map((e) => e.id)).toEqual(["4"]);
+ });
+});
+
+describe("derivePhases — live progression", () => {
+ it("explore is active before any authoring activity", () => {
+ const t = turn({
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ ],
+ });
+ expect(phase(derivePhases(t), "explore").status).toBe("active");
+ expect(phase(derivePhases(t), "draft").status).toBe("pending");
+ });
+
+ it("draft goes active once the drafting-gap client hint fires, before any block runs", () => {
+ const t = turn({ draftingSignaledAt: 1000 });
+ const rows = derivePhases(t);
+ expect(phase(rows, "explore").status).toBe("done");
+ expect(phase(rows, "draft").status).toBe("active");
+ expect(phase(rows, "test").status).toBe("pending");
+ });
+
+ it("test goes active once a block starts running", () => {
+ const t = turn({
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "running", endedAt: null })],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "draft").status).toBe("done");
+ expect(phase(rows, "test").status).toBe("active");
+ });
+});
+
+describe("derivePhases — terminal", () => {
+ it("terminal success: all done, Done gets a green check", () => {
+ const t = turn({
+ terminal: "response",
+ designEnded: true,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block()],
+ });
+ const rows = derivePhases(t);
+ expect(rows.map((r) => r.status)).toEqual(["done", "done", "done", "done"]);
+ });
+
+ it("a failed block marks Test fail with a failed-count stub", () => {
+ const t = turn({
+ terminal: "response",
+ designEnded: true,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "failed" })],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "test").status).toBe("fail");
+ expect(phase(rows, "test").stub).toBe("1 block · failed");
+ });
+
+ it("draft-only turn (update_workflow, no run): Test renders notrun, Done still succeeds", () => {
+ const t = turn({
+ terminal: "response",
+ designEnded: true,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "update_workflow" }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "test").status).toBe("notrun");
+ expect(phase(rows, "test").stub).toBe("not run");
+ expect(phase(rows, "done").status).toBe("done");
+ });
+
+ it("cancel-mid-explore: explore stops, Done renders dim", () => {
+ const t = turn({
+ terminal: "response",
+ cancelled: true,
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "explore").status).toBe("stopped");
+ expect(phase(rows, "done").status).toBe("stopped");
+ });
+
+ it("error terminal marks the active-at-end phase failed", () => {
+ const t = turn({
+ terminal: "error",
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "explore").status).toBe("fail");
+ expect(phase(rows, "done").status).toBe("fail");
+ });
+});
+
+describe("showPhaseChecklist", () => {
+ it("false for a clarify terminal turn with no draft and no blocks", () => {
+ expect(
+ showPhaseChecklist(
+ turn({ terminal: "response", draft: null, blocks: [] }),
+ ),
+ ).toBe(false);
+ });
+
+ it("true for a hydrated build payload", () => {
+ expect(
+ showPhaseChecklist(
+ turn({
+ terminal: "response",
+ draft: { blockCount: 1, blockLabels: ["a"], summary: null },
+ }),
+ ),
+ ).toBe(true);
+ });
+
+ it("true for any live (non-terminal) turn once design has started", () => {
+ expect(showPhaseChecklist(turn({ terminal: null }))).toBe(true);
+ });
+});
+
+describe("shouldArmDraftingGapTimer", () => {
+ it("arms once a tool_call round-trip has completed and gone quiet", () => {
+ const t = turn({
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({ id: "2", kind: "tool_result", toolName: "navigate_browser" }),
+ ],
+ lastActivityAtMs: 1000,
+ });
+ expect(shouldArmDraftingGapTimer(t)).toBe(true);
+ });
+
+ it("REGRESSION PIN: does not arm while a tool_call is still pending its result (Codex catch)", () => {
+ // A slow navigate_browser taking >8s must not be mistaken for silent
+ // LLM code generation — the FE can tell "tool executing" from "LLM
+ // generating" by whether the last frame is an unresolved tool_call.
+ const t = turn({
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ ],
+ lastActivityAtMs: 1000,
+ });
+ expect(shouldArmDraftingGapTimer(t)).toBe(false);
+ });
+
+ it("REGRESSION PIN: does not arm when a mid-flight progress narration is the last frame but the tool call is still pending (Codex catch)", () => {
+ // schedule_narration can emit a TOOL_STARTED progress narration right
+ // after the tool_call, before the matching tool_result — a check on
+ // only the last entry's kind misses this; id-matching does not.
+ const t = turn({
+ designActivity: [
+ entry({
+ id: "tc-1",
+ kind: "tool_call",
+ toolName: "navigate_browser",
+ }),
+ entry({ id: "n-1", kind: "narration", text: "Opening the page…" }),
+ ],
+ lastActivityAtMs: 1000,
+ });
+ expect(shouldArmDraftingGapTimer(t)).toBe(false);
+ });
+
+ it("arms once the pending tool_call's matching tool_result arrives", () => {
+ const t = turn({
+ designActivity: [
+ entry({
+ id: "tc-1",
+ kind: "tool_call",
+ toolName: "navigate_browser",
+ }),
+ entry({ id: "n-1", kind: "narration", text: "Opening the page…" }),
+ entry({
+ id: "tr-1",
+ kind: "tool_result",
+ toolName: "navigate_browser",
+ }),
+ ],
+ lastActivityAtMs: 1000,
+ });
+ expect(shouldArmDraftingGapTimer(t)).toBe(true);
+ });
+
+ it("does not arm once draftingSignaledAt is already set", () => {
+ const t = turn({
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({ id: "2", kind: "tool_result", toolName: "navigate_browser" }),
+ ],
+ lastActivityAtMs: 1000,
+ draftingSignaledAt: 500,
+ });
+ expect(shouldArmDraftingGapTimer(t)).toBe(false);
+ });
+
+ it("does not arm once a draft or block exists", () => {
+ const t = turn({
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({ id: "2", kind: "tool_result", toolName: "navigate_browser" }),
+ ],
+ lastActivityAtMs: 1000,
+ draft: { blockCount: 1, blockLabels: ["a"], summary: null },
+ });
+ expect(shouldArmDraftingGapTimer(t)).toBe(false);
+ });
+});
+
+describe("derivePhases — redraft re-activation (SKY-11970 pin)", () => {
+ it("THE PIN: a not_demonstrated verdict followed by new activity re-activates Draft, not Test", () => {
+ const t = turn({
+ terminal: null,
+ designEnded: true,
+ authoringCount: 1,
+ activitySeq: 3,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "completed" })],
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "outcome not confirmed",
+ activitySeqAtVerdict: 2,
+ },
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({
+ id: "2",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ }),
+ entry({
+ id: "3",
+ kind: "tool_call",
+ toolName: "inspect_current_workflow",
+ }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "draft").status).toBe("active");
+ expect(phase(rows, "test").status).toBe("done");
+ });
+
+ it("REGRESSION PIN: the failed run's own guaranteed trailing tool_result does NOT falsely trigger redrafting (Codex catch)", () => {
+ // update_and_run_blocks emits run_outcome (the verdict) from inside the
+ // tool, then its own tool_result fires right after as the call closes —
+ // that tool_result is not new agent work and must not look like one.
+ const t = turn({
+ terminal: null,
+ designEnded: true,
+ authoringCount: 1,
+ activitySeq: 2, // unchanged: the trailing tool_result never bumped it
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "completed" })],
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "outcome not confirmed",
+ activitySeqAtVerdict: 2,
+ },
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({
+ id: "2",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ }),
+ entry({
+ id: "3",
+ kind: "tool_result",
+ toolName: "update_and_run_blocks",
+ success: false,
+ }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "test").status).toBe("active");
+ expect(phase(rows, "draft").status).not.toBe("active");
+ });
+
+ it("REGRESSION PIN: a background narration reporting the failed run does NOT falsely trigger redrafting (Codex catch)", () => {
+ // schedule_narration in streaming_adapter.py can fire right after the
+ // failed run's own tool_result, independent of any real revision.
+ const t = turn({
+ terminal: null,
+ designEnded: true,
+ authoringCount: 1,
+ activitySeq: 2, // unchanged: narration never bumps it
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "completed" })],
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "outcome not confirmed",
+ activitySeqAtVerdict: 2,
+ },
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({
+ id: "2",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ }),
+ entry({
+ id: "3",
+ kind: "narration",
+ text: "The run didn't confirm the goal was met.",
+ }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "test").status).toBe("active");
+ expect(phase(rows, "draft").status).not.toBe("active");
+ });
+
+ it("REGRESSION PIN: redraft detection survives the MAX_DESIGN_ACTIVITY_ENTRIES eviction cap (Codex catch)", () => {
+ // designActivity is capped at 50 entries (appendCapped), so its length
+ // plateaus at 50 forever once full — a length-based comparison would
+ // never detect further activity. activitySeq is uncapped and keeps
+ // counting, so redrafting still fires.
+ const cappedActivity = Array.from({ length: 50 }, (_, i) =>
+ entry({ id: `e${i}`, kind: "narration" }),
+ );
+ const t = turn({
+ terminal: null,
+ designEnded: true,
+ authoringCount: 1,
+ activitySeq: 53,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "completed" })],
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "outcome not confirmed",
+ activitySeqAtVerdict: 50,
+ },
+ designActivity: cappedActivity,
+ });
+ expect(phase(derivePhases(t), "draft").status).toBe("active");
+ });
+
+ it("a running block after the redraft flips active back to Test (cyclic accordion)", () => {
+ const t = turn({
+ terminal: null,
+ designEnded: true,
+ authoringCount: 2,
+ activitySeq: 3,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "running", endedAt: null })],
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "outcome not confirmed",
+ activitySeqAtVerdict: 2,
+ },
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({
+ id: "2",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ }),
+ entry({ id: "3", kind: "narration" }),
+ ],
+ });
+ expect(phase(derivePhases(t), "test").status).toBe("active");
+ });
+
+ it("an evaluating verdict keeps Test active, never Draft", () => {
+ const t = turn({
+ terminal: null,
+ designEnded: true,
+ authoringCount: 1,
+ activitySeq: 2,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "completed" })],
+ lastRunOutcome: {
+ verdict: "evaluating",
+ displayReason: null,
+ activitySeqAtVerdict: 2,
+ },
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({
+ id: "2",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ }),
+ ],
+ });
+ expect(phase(derivePhases(t), "test").status).toBe("active");
+ });
+
+ it("a failed verdict with no new activity since (still composing the terminal reply) stays active on Test, not Draft", () => {
+ // activitySeq === activitySeqAtVerdict: no frame has arrived since the
+ // verdict, so this can't yet be distinguished from the agent composing
+ // its give-up terminal response — redrafting requires proof.
+ const t = turn({
+ terminal: null,
+ designEnded: true,
+ authoringCount: 1,
+ activitySeq: 2,
+ draft: { blockCount: 1, blockLabels: ["block_1"], summary: null },
+ blocks: [block({ state: "completed" })],
+ lastRunOutcome: {
+ verdict: "not_demonstrated",
+ displayReason: "outcome not confirmed",
+ activitySeqAtVerdict: 2,
+ },
+ designActivity: [
+ entry({ id: "1", kind: "tool_call", toolName: "navigate_browser" }),
+ entry({
+ id: "2",
+ kind: "tool_call",
+ toolName: "update_and_run_blocks",
+ }),
+ ],
+ });
+ const rows = derivePhases(t);
+ expect(phase(rows, "test").status).toBe("active");
+ expect(phase(rows, "draft").status).not.toBe("active");
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.ts b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.ts
new file mode 100644
index 000000000..c06634fa0
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/copilotPhases.ts
@@ -0,0 +1,323 @@
+// Pure derivation of the 4-phase build checklist (Explore / Draft / Test-run
+// / Done) from TurnNarrativeState. Kept dependency-light and side-effect-free
+// (mirrors actionReveal.ts) so the same rule produces identical rows live,
+// at the terminal payload swap, and on a hydrated history reload — the
+// reducer's `response` case REPLACES client state with the BE payload, so any
+// live-only derivation would make rows visibly jump at that instant.
+import {
+ ActivityEntry,
+ AUTHORING_TOOLS,
+ BlockState,
+ RUN_TOOLS,
+ TurnNarrativeState,
+ formatElapsed,
+ latestBlocksByLabel,
+ parseUtcIsoMs,
+} from "./narrativeState";
+
+export { AUTHORING_TOOLS, RUN_TOOLS };
+
+export type CopilotPhaseId = "explore" | "draft" | "test" | "done";
+export type PhaseStatus =
+ | "pending"
+ | "active"
+ | "done"
+ | "fail"
+ | "stopped"
+ | "notrun";
+
+export interface PhaseRowModel {
+ id: CopilotPhaseId;
+ label: string;
+ status: PhaseStatus;
+ stub: string | null;
+ // Hosted stream for explore/draft; test-tool rows (not block cards) for test.
+ entries: ActivityEntry[];
+}
+
+const PHASE_LABELS: Record<CopilotPhaseId, string> = {
+ explore: "Explore site",
+ draft: "Draft code",
+ test: "Test-run",
+ done: "Done",
+};
+
+// Byte-for-byte the existing showDesign gate (NarrativeView.tsx) so Q&A /
+// clarify turns keep today's behavior: checklist appears live, disappears at
+// a no-build terminal.
+export function showPhaseChecklist(turn: TurnNarrativeState): boolean {
+ return (
+ turn.designStarted &&
+ ((turn.draft?.blockCount ?? 0) > 0 ||
+ turn.blocks.length > 0 ||
+ turn.terminal === null)
+ );
+}
+
+// A tool_call still has no matching tool_result — the narrator can emit a
+// TOOL_STARTED progress narration mid-flight (streaming_adapter.py), so
+// checking only the LAST entry's kind isn't enough; match ids instead.
+function hasPendingToolCall(designActivity: ActivityEntry[]): boolean {
+ const pending = new Set<string>();
+ for (const entry of designActivity) {
+ if (entry.kind === "tool_call") {
+ pending.add(entry.id.slice(3)); // "tc-<tool_call_id>"
+ } else if (entry.kind === "tool_result") {
+ pending.delete(entry.id.slice(3)); // "tr-<tool_call_id>"
+ }
+ }
+ return pending.size > 0;
+}
+
+// Whether the 8s drafting-gap timer should arm for this narrative snapshot.
+// A tool call with no matching result yet is still executing (e.g. a slow
+// navigate_browser) — that's "tool executing", not "LLM silently drafting",
+// so a pending round-trip must not arm the timer.
+export function shouldArmDraftingGapTimer(turn: TurnNarrativeState): boolean {
+ if (
+ turn.turnId === null ||
+ turn.terminal !== null ||
+ turn.draftingSignaledAt !== null
+ ) {
+ return false;
+ }
+ if (
+ turn.draft !== null ||
+ turn.designEnded ||
+ turn.blocks.some((b) => b.state !== "drafted")
+ ) {
+ return false;
+ }
+ if (!turn.designActivity.some((e) => e.kind === "tool_call")) return false;
+ if (hasPendingToolCall(turn.designActivity)) return false;
+ return turn.lastActivityAtMs !== null;
+}
+
+function bucketActivity(designActivity: ActivityEntry[]): {
+ explore: ActivityEntry[];
+ draft: ActivityEntry[];
+ test: ActivityEntry[];
+} {
+ const explore: ActivityEntry[] = [];
+ const draft: ActivityEntry[] = [];
+ const test: ActivityEntry[] = [];
+ let authoringSeen = false;
+ for (const entry of designActivity) {
+ // Set authoringSeen from AUTHORING_TOOLS independent of the RUN_TOOLS
+ // bucket check below — update_workflow is authoring but not a run tool,
+ // so it must still flip the explore→draft boundary even though its own
+ // entry falls through to the draft push, not the test push.
+ if (entry.toolName && AUTHORING_TOOLS.has(entry.toolName)) {
+ authoringSeen = true;
+ }
+ if (entry.toolName && RUN_TOOLS.has(entry.toolName)) {
+ test.push(entry);
+ continue;
+ }
+ (authoringSeen ? draft : explore).push(entry);
+ }
+ return { explore, draft, test };
+}
+
+function lastAuthoringToolName(
+ designActivity: ActivityEntry[],
+): string | undefined {
+ for (let i = designActivity.length - 1; i >= 0; i--) {
+ const entry = designActivity[i]!;
+ if (
+ entry.kind === "tool_call" &&
+ entry.toolName &&
+ AUTHORING_TOOLS.has(entry.toolName)
+ ) {
+ return entry.toolName;
+ }
+ }
+ return undefined;
+}
+
+function countAuthoringToolCalls(designActivity: ActivityEntry[]): number {
+ let count = 0;
+ for (const entry of designActivity) {
+ if (
+ entry.kind === "tool_call" &&
+ entry.toolName &&
+ AUTHORING_TOOLS.has(entry.toolName)
+ ) {
+ count += 1;
+ }
+ }
+ return count;
+}
+
+function pluralize(n: number, noun: string): string {
+ return `${n} ${noun}${n === 1 ? "" : "s"}`;
+}
+
+// Earliest startedAt / latest endedAt across a block set, as ISO strings so
+// the existing formatElapsed can render them — mixing client/server clocks
+// per-block would lie, so this only ever combines same-source timestamps.
+function spanIso(blocks: BlockState[]): {
+ start: string | null;
+ end: string | null;
+} {
+ let startMs: number | null = null;
+ let start: string | null = null;
+ let endMs: number | null = null;
+ let end: string | null = null;
+ for (const b of blocks) {
+ const sMs = parseUtcIsoMs(b.startedAt);
+ if (sMs !== null && (startMs === null || sMs < startMs)) {
+ startMs = sMs;
+ start = b.startedAt;
+ }
+ const eMs = parseUtcIsoMs(b.endedAt);
+ if (eMs !== null && (endMs === null || eMs > endMs)) {
+ endMs = eMs;
+ end = b.endedAt;
+ }
+ }
+ return { start, end };
+}
+
+export function derivePhases(turn: TurnNarrativeState): PhaseRowModel[] {
+ const {
+ explore,
+ draft: draftEntries,
+ test,
+ } = bucketActivity(turn.designActivity);
+ const lastAuthoring = lastAuthoringToolName(turn.designActivity);
+ const latestBlocks = latestBlocksByLabel(turn.blocks).filter(
+ (b) => b.state !== "drafted",
+ );
+ const testReached =
+ latestBlocks.length > 0 ||
+ (turn.designEnded && lastAuthoring === "update_and_run_blocks");
+ const draftReached =
+ turn.authoringCount > 0 ||
+ turn.draft !== null ||
+ turn.designEnded ||
+ turn.draftingSignaledAt !== null ||
+ testReached;
+
+ const running = turn.blocks.some(
+ (b) => b.state === "running" || b.state === "queued",
+ );
+ const lastRunOutcome = turn.lastRunOutcome;
+ // The loop demonstrably continued past the failed verdict (a new activity
+ // frame arrived), distinguishing "revising" from "composing the give-up
+ // terminal response". Compares the monotonic activitySeq, not
+ // designActivity.length — the latter plateaus once MAX_DESIGN_ACTIVITY_ENTRIES
+ // is reached, which would otherwise make this comparison never fire again.
+ const redrafting =
+ turn.terminal === null &&
+ !running &&
+ lastRunOutcome !== null &&
+ (lastRunOutcome.verdict === "not_demonstrated" ||
+ lastRunOutcome.verdict === "not_evaluated") &&
+ turn.activitySeq > lastRunOutcome.activitySeqAtVerdict;
+
+ const chainActive: CopilotPhaseId = testReached
+ ? "test"
+ : draftReached
+ ? "draft"
+ : "explore";
+ const liveActive: CopilotPhaseId | null =
+ turn.terminal !== null
+ ? null
+ : running || lastRunOutcome?.verdict === "evaluating"
+ ? "test"
+ : redrafting
+ ? "draft"
+ : chainActive;
+
+ const isTerminal = turn.terminal !== null;
+ const isError = turn.terminal === "error";
+ const isCancelled = turn.cancelled === true;
+ const anyFailed = latestBlocks.some((b) => b.state === "failed");
+ const anyNotDemonstrated = latestBlocks.some(
+ (b) => b.outcome === "not_demonstrated",
+ );
+
+ function reached(id: CopilotPhaseId): boolean {
+ if (id === "explore") return true;
+ if (id === "draft") return draftReached;
+ return testReached;
+ }
+
+ function statusFor(id: CopilotPhaseId): PhaseStatus {
+ if (id === "done") {
+ if (!isTerminal) return "pending";
+ if (turn.terminal === "response" && !isCancelled) return "done";
+ return isError ? "fail" : "stopped";
+ }
+ // A hard block failure wins regardless of live/terminal — unless this
+ // phase is still the live-active row (a block is still running/queued).
+ if (id === "test" && testReached && anyFailed && id !== liveActive) {
+ return "fail";
+ }
+ if (!isTerminal) {
+ return id === liveActive ? "active" : reached(id) ? "done" : "pending";
+ }
+ if (!reached(id)) return id === "test" ? "notrun" : "pending";
+ if (chainActive === id) {
+ if (isError) return "fail";
+ if (isCancelled) return "stopped";
+ }
+ return "done";
+ }
+
+ function stubFor(id: CopilotPhaseId, status: PhaseStatus): string | null {
+ if (id === "done") return null;
+ if (id === "explore") {
+ if (status !== "done" && status !== "fail" && status !== "stopped") {
+ return null;
+ }
+ const n = explore.filter((e) => e.kind === "tool_call").length;
+ return n > 0 ? pluralize(n, "step") : null;
+ }
+ if (id === "draft") {
+ if (status !== "done" && status !== "fail" && status !== "stopped") {
+ return null;
+ }
+ if (!turn.draft) return null;
+ const base = pluralize(turn.draft.blockCount, "block");
+ if (!isTerminal) return base;
+ const drafts = countAuthoringToolCalls(turn.designActivity);
+ return drafts >= 2 ? `${base} · ${drafts} drafts` : base;
+ }
+ // test
+ if (status === "notrun") return "not run";
+ if (status === "pending" || status === "active") return null;
+ if (status === "fail")
+ return `${pluralize(latestBlocks.length, "block")} · failed`;
+ if (status === "stopped") {
+ return latestBlocks.length > 0
+ ? `${pluralize(latestBlocks.length, "block")} · stopped`
+ : "stopped";
+ }
+ if (anyNotDemonstrated) return "· not confirmed";
+ const { start, end } = spanIso(latestBlocks);
+ const elapsed = formatElapsed(start, end);
+ return elapsed
+ ? `${pluralize(latestBlocks.length, "block")} · ${elapsed}`
+ : pluralize(latestBlocks.length, "block");
+ }
+
+ const entriesFor: Record<CopilotPhaseId, ActivityEntry[]> = {
+ explore,
+ draft: draftEntries,
+ test,
+ done: [],
+ };
+
+ return (["explore", "draft", "test", "done"] as const).map((id) => {
+ const status = statusFor(id);
+ return {
+ id,
+ label: PHASE_LABELS[id],
+ status,
+ stub: stubFor(id, status),
+ entries: entriesFor[id],
+ };
+ });
+}
diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts
new file mode 100644
index 000000000..7e23c791c
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.phaseHint.test.ts
@@ -0,0 +1,366 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ CopilotPhaseHintEvent,
+ EMPTY_NARRATIVE,
+ TurnNarrativeState,
+ applyNarrativeEvent,
+} from "./narrativeState";
+import {
+ WorkflowCopilotBlockProgressUpdate,
+ WorkflowCopilotRunOutcomeUpdate,
+ WorkflowCopilotStreamResponseUpdate,
+ WorkflowCopilotToolCallUpdate,
+ WorkflowCopilotTurnStartUpdate,
+} from "./workflowCopilotTypes";
+
+const turnStart = (): WorkflowCopilotTurnStartUpdate => ({
+ type: "turn_start",
+ turn_id: "turn-1",
+ turn_index: 0,
+ mode: "build",
+ timestamp: "2026-06-10T00:00:00Z",
+});
+
+const toolCall = (
+ overrides: Partial<WorkflowCopilotToolCallUpdate> = {},
+): WorkflowCopilotToolCallUpdate => ({
+ type: "tool_call",
+ tool_name: "navigate_browser",
+ tool_input: {},
+ iteration: 0,
+ tool_call_id: "call-1",
+ ...overrides,
+});
+
+const blockProgress = (
+ overrides: Partial<WorkflowCopilotBlockProgressUpdate> &
+ Pick<WorkflowCopilotBlockProgressUpdate, "block_label" | "status">,
+): WorkflowCopilotBlockProgressUpdate => ({
+ type: "block_progress",
+ workflow_run_block_id: `wrb_${overrides.block_label}`,
+ block_type: "task",
+ iteration: 0,
+ timestamp: "2026-06-10T00:00:04Z",
+ ...overrides,
+});
+
+const runOutcome = (
+ overrides: Partial<WorkflowCopilotRunOutcomeUpdate> &
+ Pick<WorkflowCopilotRunOutcomeUpdate, "verdict">,
+): WorkflowCopilotRunOutcomeUpdate => ({
+ type: "run_outcome",
+ workflow_run_id: "wr_1",
+ workflow_run_block_ids: ["wrb_block_1"],
+ block_labels: ["block_1"],
+ reason_code: null,
+ display_reason: null,
+ iteration: 0,
+ timestamp: "2026-06-10T00:01:00Z",
+ ...overrides,
+});
+
+const response = (
+ overrides: Partial<WorkflowCopilotStreamResponseUpdate> = {},
+): WorkflowCopilotStreamResponseUpdate => ({
+ type: "response",
+ workflow_copilot_chat_id: "chat-1",
+ message: "Done.",
+ response_time: "2026-06-10T00:02:00Z",
+ proposal_disposition: "auto_applicable",
+ ...overrides,
+});
+
+const phaseHint = (hintedAtMs: number): CopilotPhaseHintEvent => ({
+ type: "client_phase_hint",
+ hintedAtMs,
+});
+
+describe("applyNarrativeEvent — client_phase_hint", () => {
+ it("sets draftingSignaledAt once", () => {
+ const s = applyNarrativeEvent(EMPTY_NARRATIVE, phaseHint(5000));
+ expect(s.draftingSignaledAt).toBe(5000);
+ });
+
+ it("is idempotent — a second hint never overwrites the first timestamp", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ phaseHint(5000),
+ );
+ s = applyNarrativeEvent(s, phaseHint(9000));
+ expect(s.draftingSignaledAt).toBe(5000);
+ });
+
+ it("no-ops once a block has started running (design already progressed)", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ turnStart(),
+ );
+ s = applyNarrativeEvent(
+ s,
+ blockProgress({ block_label: "block_1", status: "running" }),
+ );
+ s = applyNarrativeEvent(s, phaseHint(5000));
+ expect(s.draftingSignaledAt).toBeNull();
+ });
+
+ it("no-ops once designEnded", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(EMPTY_NARRATIVE, {
+ type: "design_end",
+ timestamp: "2026-06-10T00:00:02Z",
+ });
+ s = applyNarrativeEvent(s, phaseHint(5000));
+ expect(s.draftingSignaledAt).toBeNull();
+ });
+
+ it("no-ops once a draft already exists", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(EMPTY_NARRATIVE, {
+ type: "workflow_draft",
+ block_count: 1,
+ block_labels: ["block_1"],
+ summary: null,
+ timestamp: "2026-06-10T00:00:03Z",
+ });
+ s = applyNarrativeEvent(s, phaseHint(5000));
+ expect(s.draftingSignaledAt).toBeNull();
+ });
+});
+
+describe("applyNarrativeEvent — lastActivityAtMs", () => {
+ it("stamps with the injected nowMs on tool_call/tool_result/narration", () => {
+ const s = applyNarrativeEvent(EMPTY_NARRATIVE, toolCall(), 12345);
+ expect(s.lastActivityAtMs).toBe(12345);
+ });
+
+ it("stamps even when the tool is denylisted from the visible activity log", () => {
+ const s = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ toolCall({ tool_name: "list_credentials" }),
+ 777,
+ );
+ expect(s.lastActivityAtMs).toBe(777);
+ expect(s.designActivity).toHaveLength(0);
+ });
+
+ it("defaults to Date.now() when nowMs is omitted", () => {
+ const before = Date.now();
+ const s = applyNarrativeEvent(EMPTY_NARRATIVE, toolCall());
+ expect(s.lastActivityAtMs).toBeGreaterThanOrEqual(before);
+ });
+});
+
+describe("applyNarrativeEvent — authoringCount", () => {
+ it("increments only on AUTHORING_TOOLS tool_calls", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ toolCall({ tool_name: "navigate_browser" }),
+ );
+ expect(s.authoringCount).toBe(0);
+ s = applyNarrativeEvent(s, toolCall({ tool_name: "update_workflow" }));
+ expect(s.authoringCount).toBe(1);
+ s = applyNarrativeEvent(
+ s,
+ toolCall({ tool_name: "update_and_run_blocks", tool_call_id: "call-2" }),
+ );
+ expect(s.authoringCount).toBe(2);
+ });
+
+ it("survives the MAX_DESIGN_ACTIVITY_ENTRIES eviction cap (does not reset when old entries scroll off)", () => {
+ let s: TurnNarrativeState = EMPTY_NARRATIVE;
+ s = applyNarrativeEvent(s, toolCall({ tool_name: "update_workflow" }));
+ for (let i = 0; i < 60; i++) {
+ s = applyNarrativeEvent(
+ s,
+ toolCall({ tool_name: "navigate_browser", tool_call_id: `c${i}` }),
+ );
+ }
+ expect(s.authoringCount).toBe(1);
+ expect(s.designActivity.length).toBeLessThan(61);
+ });
+});
+
+describe("applyNarrativeEvent — lastRunOutcome", () => {
+ it("run_outcome sets lastRunOutcome with the pre-event activitySeq", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ toolCall(),
+ );
+ s = applyNarrativeEvent(
+ s,
+ runOutcome({
+ verdict: "not_demonstrated",
+ display_reason: "outcome not confirmed",
+ }),
+ );
+ expect(s.lastRunOutcome).toEqual({
+ verdict: "not_demonstrated",
+ displayReason: "outcome not confirmed",
+ activitySeqAtVerdict: 1,
+ });
+ });
+
+ it("last-write-wins: an evaluating hold overwrites a stale failed verdict", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ runOutcome({ verdict: "not_demonstrated" }),
+ );
+ s = applyNarrativeEvent(s, runOutcome({ verdict: "evaluating" }));
+ expect(s.lastRunOutcome?.verdict).toBe("evaluating");
+ });
+});
+
+describe("applyNarrativeEvent — activitySeq (monotonic, cap-immune)", () => {
+ it("increments on tool_call (agent-initiated steps)", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ toolCall(),
+ );
+ expect(s.activitySeq).toBe(1);
+ s = applyNarrativeEvent(s, toolCall({ tool_call_id: "call-2" }));
+ expect(s.activitySeq).toBe(2);
+ });
+
+ it("REGRESSION PIN: does NOT increment on tool_result — a failed run's own trailing tool_result must not look like new agent work (Codex catch)", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ toolCall(),
+ );
+ expect(s.activitySeq).toBe(1);
+ s = applyNarrativeEvent(s, {
+ type: "tool_result",
+ tool_name: "navigate_browser",
+ success: true,
+ summary: "done",
+ iteration: 0,
+ tool_call_id: "call-1",
+ });
+ expect(s.activitySeq).toBe(1);
+ });
+
+ it("REGRESSION PIN: does NOT increment on narration — the narrator can report on a failed run's outcome independent of new revision work (Codex catch)", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ toolCall(),
+ );
+ expect(s.activitySeq).toBe(1);
+ s = applyNarrativeEvent(s, {
+ type: "narration",
+ narration: "The run didn't confirm the goal was met.",
+ iteration: 0,
+ timestamp: "2026-06-10T00:00:00Z",
+ });
+ expect(s.activitySeq).toBe(1);
+ });
+
+ it("REGRESSION PIN: keeps incrementing past the MAX_DESIGN_ACTIVITY_ENTRIES cap, unlike designActivity.length", () => {
+ let s: TurnNarrativeState = EMPTY_NARRATIVE;
+ for (let i = 0; i < 55; i++) {
+ s = applyNarrativeEvent(s, toolCall({ tool_call_id: `c${i}` }));
+ }
+ expect(s.designActivity.length).toBe(50);
+ expect(s.activitySeq).toBe(55);
+ });
+});
+
+describe("applyNarrativeEvent — response hydration resets phase-hint fields", () => {
+ it("regression pin: a response frame for the SAME turnId preserves draftingSignaledAt (the terminal-wipe trap)", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ turnStart(),
+ );
+ s = applyNarrativeEvent(s, phaseHint(5000));
+ expect(s.draftingSignaledAt).toBe(5000);
+
+ s = applyNarrativeEvent(
+ s,
+ response({
+ turn_id: "turn-1",
+ narrative_payload: {
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ designEnded: true,
+ draft: null,
+ blocks: [],
+ terminal: "response",
+ terminalMessage: "Done.",
+ narrativeSummary: "Done.",
+ priorBlockCount: null,
+ designActivity: [],
+ startedAt: "2026-06-10T00:00:00Z",
+ endedAt: "2026-06-10T00:02:00Z",
+ },
+ }),
+ );
+ expect(s.draftingSignaledAt).toBe(5000);
+ });
+
+ it("no graft for a DIFFERENT turnId — fresh terminal payload starts at null", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ turnStart(),
+ );
+ s = applyNarrativeEvent(s, phaseHint(5000));
+
+ s = applyNarrativeEvent(
+ s,
+ response({
+ narrative_payload: {
+ turnId: "turn-2",
+ turnIndex: 1,
+ mode: "build",
+ designStarted: true,
+ designEnded: true,
+ draft: null,
+ blocks: [],
+ terminal: "response",
+ terminalMessage: "Done.",
+ narrativeSummary: "Done.",
+ priorBlockCount: null,
+ designActivity: [],
+ startedAt: "2026-06-10T00:00:00Z",
+ endedAt: "2026-06-10T00:02:00Z",
+ },
+ }),
+ );
+ expect(s.draftingSignaledAt).toBeNull();
+ });
+
+ it("authoringCount and lastRunOutcome are NOT grafted — terminal checklist is stubs-only", () => {
+ let s: TurnNarrativeState = applyNarrativeEvent(
+ EMPTY_NARRATIVE,
+ turnStart(),
+ );
+ s = applyNarrativeEvent(s, toolCall({ tool_name: "update_workflow" }));
+ s = applyNarrativeEvent(s, runOutcome({ verdict: "not_demonstrated" }));
+ expect(s.authoringCount).toBe(1);
+ expect(s.lastRunOutcome).not.toBeNull();
+
+ s = applyNarrativeEvent(
+ s,
+ response({
+ turn_id: "turn-1",
+ narrative_payload: {
+ turnId: "turn-1",
+ turnIndex: 0,
+ mode: "build",
+ designStarted: true,
+ designEnded: true,
+ draft: null,
+ blocks: [],
+ terminal: "response",
+ terminalMessage: "Done.",
+ narrativeSummary: "Done.",
+ priorBlockCount: null,
+ designActivity: [],
+ startedAt: "2026-06-10T00:00:00Z",
+ endedAt: "2026-06-10T00:02:00Z",
+ },
+ }),
+ );
+ expect(s.authoringCount).toBe(0);
+ expect(s.lastRunOutcome).toBeNull();
+ expect(s.activitySeq).toBe(0);
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
index 10738d7e5..857b05647 100644
--- a/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
+++ b/skyvern-frontend/src/routes/workflows/copilot/narrativeState.ts
@@ -42,6 +42,15 @@ export interface CopilotBlockActionsEvent {
receivedAtMs: number;
}
+// Client-synthesized event marking that the drafting silence (no frames
+// while the LLM writes code) has lasted long enough to assume Draft has
+// started. Idempotent in the reducer so a re-armed timer or StrictMode
+// double-fire is a no-op.
+export interface CopilotPhaseHintEvent {
+ type: "client_phase_hint";
+ hintedAtMs: number;
+}
+
// Discriminated union of every event the reducer below consumes. The bubble
// derives all of its rendering from these payloads.
export type NarrativeEvent =
@@ -56,7 +65,8 @@ export type NarrativeEvent =
| WorkflowCopilotNarrationUpdate
| WorkflowCopilotToolCallUpdate
| WorkflowCopilotToolResultUpdate
- | CopilotBlockActionsEvent;
+ | CopilotBlockActionsEvent
+ | CopilotPhaseHintEvent;
// Block lifecycle states as observed via block_progress. The bubble groups
// failed-style states (failed, terminated, timed_out, canceled) under one
@@ -163,6 +173,33 @@ export interface TurnNarrativeState {
// Activity events fired BEFORE any block started running this turn
// (design phase + pre-execution tool calls), rendered inside the Design card.
designActivity: ActivityEntry[];
+ // Client-only phase-progress state (never persisted): epoch ms of the most
+ // recent tool_call/tool_result/narration, and when the 8s drafting-gap
+ // heuristic fired. Grafted across the terminal payload swap by turnId so a
+ // cancel-mid-silence doesn't visually un-check the Draft phase.
+ lastActivityAtMs: number | null;
+ draftingSignaledAt: number | null;
+ // Count of AUTHORING_TOOLS tool_calls this turn, kept outside designActivity
+ // so it survives the MAX_DESIGN_ACTIVITY_ENTRIES eviction cap. Drives the
+ // redraft-iteration label ("Draft v2 — revising…") and Draft re-activation.
+ authoringCount: number;
+ // Monotonic count of tool_call events this turn — the only frame kind
+ // that's unambiguous evidence of new agent-initiated work (tool_result is
+ // always a trailing echo; narration can be scheduled as post-hoc
+ // reporting independent of new work — see the reducer cases). Never
+ // capped (unlike designActivity.length, which plateaus once
+ // MAX_DESIGN_ACTIVITY_ENTRIES is full).
+ activitySeq: number;
+ // Snapshot of the most recent run_outcome verdict plus the activity
+ // sequence number at the moment it arrived, so a later activity frame
+ // proves the loop kept going (a redraft), not just a slow give-up
+ // response. Not grafted across terminal — cancel-mid-redraft marks Test
+ // stopped rather than Draft (accepted).
+ lastRunOutcome: {
+ verdict: BlockOutcome;
+ displayReason: string | null;
+ activitySeqAtVerdict: number;
+ } | null;
}
export const EMPTY_NARRATIVE: TurnNarrativeState = Object.freeze({
@@ -185,6 +222,11 @@ export const EMPTY_NARRATIVE: TurnNarrativeState = Object.freeze({
startedAt: null,
endedAt: null,
designActivity: [],
+ lastActivityAtMs: null,
+ draftingSignaledAt: null,
+ authoringCount: 0,
+ activitySeq: 0,
+ lastRunOutcome: null,
}) as TurnNarrativeState;
// Caps to keep long-running narrations from unbounded growth (and to keep
@@ -214,6 +256,19 @@ export function parseResponseKind(value: unknown): TurnResponseKind | null {
: null;
}
+// Tool calls that write the workflow definition. update_workflow only
+// validates/saves the draft; update_and_run_blocks also runs it, so it's
+// the one AUTHORING_TOOLS member that's also a RUN_TOOLS member (its
+// activity lands in the Test phase bucket, not Draft — see copilotPhases.ts).
+export const AUTHORING_TOOLS = new Set([
+ "update_workflow",
+ "update_and_run_blocks",
+]);
+export const RUN_TOOLS = new Set([
+ "update_and_run_blocks",
+ "run_blocks_and_collect_debug",
+]);
+
// Tool names we never surface in the user-facing activity log. Internal
// observation/maintenance tools are not interesting context for the user.
const ACTIVITY_TOOL_DENYLIST = new Set([
@@ -357,6 +412,7 @@ export function isBlockOk(
export function applyNarrativeEvent(
prev: TurnNarrativeState,
event: NarrativeEvent,
+ nowMs: number = Date.now(),
): TurnNarrativeState {
switch (event.type) {
case "turn_start":
@@ -481,7 +537,17 @@ export function applyNarrativeEvent(
}
: b,
);
- return { ...prev, blocks };
+ return {
+ ...prev,
+ blocks,
+ // Last-write-wins: an "evaluating" hold overwrites a stale failed
+ // verdict from a prior run cycle within the same turn.
+ lastRunOutcome: {
+ verdict: event.verdict,
+ displayReason: event.display_reason ?? null,
+ activitySeqAtVerdict: prev.activitySeq,
+ },
+ };
}
case "client_block_actions": {
@@ -510,34 +576,87 @@ export function applyNarrativeEvent(
case "tool_call": {
const entry = buildActivityFromToolCall(event);
- if (!entry) return prev;
+ const authoringCount =
+ prev.authoringCount + (AUTHORING_TOOLS.has(event.tool_name) ? 1 : 0);
+ const activitySeq = prev.activitySeq + 1;
+ if (!entry) {
+ return {
+ ...prev,
+ lastActivityAtMs: nowMs,
+ authoringCount,
+ activitySeq,
+ };
+ }
const { blocks, designActivity } = appendActivity(
prev.blocks,
prev.designActivity,
entry,
);
- return { ...prev, blocks, designActivity };
+ return {
+ ...prev,
+ blocks,
+ designActivity,
+ lastActivityAtMs: nowMs,
+ authoringCount,
+ activitySeq,
+ };
}
case "tool_result": {
+ // Deliberately does NOT bump activitySeq: a failed run's own
+ // update_and_run_blocks call always emits its trailing tool_result
+ // right after the run_outcome verdict it produced — counting that
+ // guaranteed echo would make redrafting fire on every failed verdict
+ // before the agent has done any new work. Only tool_call/narration
+ // (agent-initiated steps) count as evidence the loop continued.
const entry = buildActivityFromToolResult(event);
- if (!entry) return prev;
+ if (!entry) return { ...prev, lastActivityAtMs: nowMs };
const { blocks, designActivity } = appendActivity(
prev.blocks,
prev.designActivity,
entry,
);
- return { ...prev, blocks, designActivity };
+ return {
+ ...prev,
+ blocks,
+ designActivity,
+ lastActivityAtMs: nowMs,
+ };
}
case "narration": {
+ // Also does NOT bump activitySeq: the narrator can schedule a
+ // "reporting on what just happened" narration right after a failed
+ // run's own tool_result (streaming_adapter.py schedule_narration),
+ // independent of whether the agent is actually going to revise —
+ // only a genuinely new tool_call is unambiguous evidence of that.
const entry = buildActivityFromNarration(event);
const { blocks, designActivity } = appendActivity(
prev.blocks,
prev.designActivity,
entry,
);
- return { ...prev, blocks, designActivity };
+ return {
+ ...prev,
+ blocks,
+ designActivity,
+ lastActivityAtMs: nowMs,
+ };
+ }
+
+ case "client_phase_hint": {
+ // No-op once drafting is already signaled or the turn has moved past
+ // pure exploration — idempotent by construction so a re-armed timer or
+ // a StrictMode double-fire never overwrites an earlier timestamp.
+ if (
+ prev.draftingSignaledAt !== null ||
+ prev.draft !== null ||
+ prev.designEnded ||
+ prev.blocks.some((b) => b.state !== "drafted")
+ ) {
+ return prev;
+ }
+ return { ...prev, draftingSignaledAt: event.hintedAtMs };
}
case "response": {
@@ -565,6 +684,13 @@ export function applyNarrativeEvent(
return {
...hydrated,
blocks,
+ // Graft across the terminal replacement so a cancel mid-silence
+ // doesn't visually un-check the Draft phase (hydrated payloads
+ // never carry this client-only field). authoringCount/lastRunOutcome
+ // are intentionally NOT grafted — a stubs-only terminal checklist is
+ // correct there.
+ draftingSignaledAt:
+ hydrated.turnId === prev.turnId ? prev.draftingSignaledAt : null,
responseType: event.response_type ?? hydrated.responseType,
cancelled: event.cancelled ?? hydrated.cancelled,
proposalDisposition: