From d8be84c11e295a8662fb01a6921178876c8492d0 Mon Sep 17 00:00:00 2001 From: Dotta Date: Wed, 29 Apr 2026 12:15:31 -0500 Subject: [PATCH] Storybook: cheap-lane and model-profile stories Add NewIssueDialog stories that exercise the Primary/Cheap/Custom segmented control (including the unsupported-adapter case where Cheap is hidden), plus an IssueRunLedger story covering applied-cheap, fallback-to-primary, and baseline runs without a profile badge. Fix the storybook companies fixture to use the wrapped { companies, unauthorized } shape introduced in d95968a9 so the global CompanyProvider stops crashing on render. Co-Authored-By: Claude Opus 4.7 --- .../stories/dialogs-modals.stories.tsx | 216 +++++++++++++++++- .../stories/issue-management.stories.tsx | 154 ++++++++++++- .../projects-goals-workspaces.stories.tsx | 2 +- .../stories/sub-issues-workflow.stories.tsx | 2 +- 4 files changed, 370 insertions(+), 4 deletions(-) diff --git a/ui/storybook/stories/dialogs-modals.stories.tsx b/ui/storybook/stories/dialogs-modals.stories.tsx index 4a2cc720b5f..1d9e968d0a9 100644 --- a/ui/storybook/stories/dialogs-modals.stories.tsx +++ b/ui/storybook/stories/dialogs-modals.stories.tsx @@ -19,6 +19,7 @@ import { PathInstructionsModal } from "@/components/PathInstructionsModal"; import { useCompany } from "@/context/CompanyContext"; import { useDialog } from "@/context/DialogContext"; import { queryKeys } from "@/lib/queryKeys"; +import type { Agent } from "@paperclipai/shared"; import { storybookAgents, storybookAuthSession, @@ -328,7 +329,7 @@ function DialogBackdropFrame({ } function hydrateDialogQueries(queryClient: ReturnType) { - queryClient.setQueryData(queryKeys.companies.all, storybookCompanies); + queryClient.setQueryData(queryKeys.companies.all, { companies: storybookCompanies, unauthorized: false }); queryClient.setQueryData(queryKeys.auth.session, storybookAuthSession); queryClient.setQueryData(queryKeys.agents.list(COMPANY_ID), storybookAgents); queryClient.setQueryData(queryKeys.projects.list(COMPANY_ID), storybookProjects); @@ -382,6 +383,7 @@ function hydrateDialogQueries(queryClient: ReturnType) { supportsSkills: true, supportsLocalAgentJwt: true, requiresMaterializedRuntimeSkills: false, + supportsModelProfiles: true, }, }, { @@ -396,6 +398,7 @@ function hydrateDialogQueries(queryClient: ReturnType) { supportsSkills: true, supportsLocalAgentJwt: true, requiresMaterializedRuntimeSkills: false, + supportsModelProfiles: true, }, }, ]); @@ -403,8 +406,41 @@ function hydrateDialogQueries(queryClient: ReturnType) { { id: "gpt-5.4", label: "GPT-5.4" }, { id: "gpt-5.4-mini", label: "GPT-5.4 Mini" }, ]); + queryClient.setQueryData(queryKeys.agents.adapterModelProfiles(COMPANY_ID, "codex_local"), [ + { + key: "cheap", + label: "Cheap", + adapterConfig: { model: "gpt-5.4-mini" }, + source: "adapter_default", + }, + ]); } +const HERMES_AGENT: Agent = { + id: "agent-hermes", + companyId: COMPANY_ID, + name: "HermesRouter", + urlKey: "hermesrouter", + role: "engineer", + title: "Lightweight Routing", + icon: "code", + status: "idle", + reportsTo: "agent-cto", + capabilities: "Hermes-backed assistant on an adapter without the cheap-profile contract.", + adapterType: "opencode_local", + adapterConfig: {}, + runtimeConfig: {}, + budgetMonthlyCents: 60_000, + spentMonthlyCents: 9_000, + pauseReason: null, + pausedAt: null, + permissions: { canCreateAgents: false }, + lastHeartbeatAt: new Date("2026-04-29T08:30:00.000Z"), + metadata: null, + createdAt: new Date("2026-04-12T08:00:00.000Z"), + updatedAt: new Date("2026-04-29T08:30:00.000Z"), +}; + function StorybookDialogFixtures({ children }: { children: ReactNode }) { const queryClient = useQueryClient(); const [ready] = useState(() => { @@ -655,6 +691,128 @@ function ImageGalleryModalStory() { ); } +type CheapLaneVariant = "primary" | "cheap" | "custom" | "unsupported"; + +function clickModelLaneButton(label: "Primary" | "Cheap" | "Custom") { + const radiogroup = document.querySelector("[aria-label='Model lane']"); + if (!radiogroup) return false; + const buttons = Array.from(radiogroup.querySelectorAll("button[role='radio']")); + const button = buttons.find((candidate) => candidate.textContent?.trim() === label); + if (!button) return false; + button.click(); + return true; +} + +function findAssigneeOptionsButton() { + const buttons = Array.from(document.querySelectorAll("button")); + return ( + buttons.find((candidate) => /(Codex|Claude|OpenCode|Agent) options$/.test(candidate.textContent?.trim() ?? "")) ?? null + ); +} + +function useCheapLaneAdapterOverrides(variant: CheapLaneVariant) { + const queryClient = useQueryClient(); + useLayoutEffect(() => { + if (variant !== "unsupported") return; + queryClient.setQueryData( + queryKeys.agents.list(COMPANY_ID), + [...storybookAgents, HERMES_AGENT], + ); + queryClient.setQueryData(queryKeys.adapters.all, [ + { + type: "codex_local", + label: "Codex local", + source: "builtin", + modelsCount: 5, + loaded: true, + disabled: false, + capabilities: { + supportsInstructionsBundle: true, + supportsSkills: true, + supportsLocalAgentJwt: true, + requiresMaterializedRuntimeSkills: false, + supportsModelProfiles: true, + }, + }, + { + type: "opencode_local", + label: "OpenCode local", + source: "builtin", + modelsCount: 2, + loaded: true, + disabled: false, + capabilities: { + supportsInstructionsBundle: true, + supportsSkills: true, + supportsLocalAgentJwt: true, + requiresMaterializedRuntimeSkills: true, + supportsModelProfiles: false, + }, + }, + ]); + queryClient.setQueryData(queryKeys.agents.adapterModels(COMPANY_ID, "opencode_local"), [ + { id: "anthropic/claude-haiku-4-5", label: "Claude Haiku 4.5" }, + { id: "openai/gpt-5.4-mini", label: "GPT-5.4 Mini" }, + ]); + }, [queryClient, variant]); +} + +function CheapLaneIssueDialogOpener({ variant }: { variant: CheapLaneVariant }) { + const { openNewIssue } = useDialog(); + useCheapLaneAdapterOverrides(variant); + + const assigneeAgentId = variant === "unsupported" ? "agent-hermes" : "agent-codex"; + const title = + variant === "unsupported" + ? "Route research summary to HermesRouter" + : "Generate weekly Storybook coverage report"; + const description = + variant === "unsupported" + ? "HermesRouter runs on an adapter that does not advertise a cheap profile, so the Cheap lane should disappear instead of being greyed." + : "Lower-cost runs should still pick up the agent's cheap profile so the model badge can show the requested lane."; + + useOpenWhenCompanyReady(() => { + openNewIssue({ + title, + description, + status: "todo", + priority: "medium", + projectId: "project-board-ui", + projectWorkspaceId: "workspace-board-ui", + assigneeAgentId, + }); + }); + + useEffect(() => { + let cancelled = false; + const timers: number[] = []; + + timers.push( + window.setTimeout(() => { + if (cancelled) return; + const optionsButton = findAssigneeOptionsButton(); + optionsButton?.click(); + }, 300), + ); + + if (variant === "cheap" || variant === "custom") { + timers.push( + window.setTimeout(() => { + if (cancelled) return; + clickModelLaneButton(variant === "cheap" ? "Cheap" : "Custom"); + }, 600), + ); + } + + return () => { + cancelled = true; + for (const timer of timers) window.clearTimeout(timer); + }; + }, [variant]); + + return ; +} + function PathInstructionsModalStory() { return ( ( + + + + ), +}; + +export const NewIssueCheapLaneCheap: Story = { + name: "New Issue - Cheap lane (Cheap)", + render: () => ( + + + + ), +}; + +export const NewIssueCheapLaneCustom: Story = { + name: "New Issue - Cheap lane (Custom)", + render: () => ( + + + + ), +}; + +export const NewIssueCheapLaneUnsupported: Story = { + name: "New Issue - Cheap lane (Unsupported adapter)", + render: () => ( + + + + ), +}; + export const NewAgentRecommendation: Story = { name: "New Agent - Recommendation", render: () => ( diff --git a/ui/storybook/stories/issue-management.stories.tsx b/ui/storybook/stories/issue-management.stories.tsx index f46fd926f5d..c6544db3d25 100644 --- a/ui/storybook/stories/issue-management.stories.tsx +++ b/ui/storybook/stories/issue-management.stories.tsx @@ -1,6 +1,7 @@ import { useEffect, useMemo, useRef, useState } from "react"; import type { Meta, StoryObj } from "@storybook/react-vite"; import type { Issue } from "@paperclipai/shared"; +import type { RunForIssue } from "@/api/activity"; import { useQueryClient } from "@tanstack/react-query"; import { ArrowDownAZ, @@ -83,7 +84,7 @@ function Section({ } function hydrateStorybookQueries(queryClient: ReturnType) { - queryClient.setQueryData(queryKeys.companies.all, storybookCompanies); + queryClient.setQueryData(queryKeys.companies.all, { companies: storybookCompanies, unauthorized: false }); queryClient.setQueryData(queryKeys.auth.session, storybookAuthSession); queryClient.setQueryData(queryKeys.agents.list(companyId), storybookAgents); queryClient.setQueryData(queryKeys.projects.list(companyId), storybookProjects); @@ -334,6 +335,116 @@ function OpenFiltersPopover() { ); } +const modelProfileLedgerRuns: RunForIssue[] = [ + { + runId: "run-cheap-applied", + status: "succeeded", + agentId: "agent-codex", + adapterType: "codex_local", + startedAt: "2026-04-29T09:30:00.000Z", + finishedAt: "2026-04-29T09:32:14.000Z", + createdAt: "2026-04-29T09:29:55.000Z", + invocationSource: "manual", + usageJson: { costCents: 17, inputTokens: 6400, outputTokens: 480 }, + resultJson: { + stopReason: "completed", + modelProfile: { + requested: "cheap", + applied: "cheap", + configSource: "agent_runtime_config", + }, + }, + livenessState: "advanced", + livenessReason: "Cheap-lane summary completed inside the planned scope.", + continuationAttempt: 0, + lastUsefulActionAt: "2026-04-29T09:32:10.000Z", + nextAction: "Hand the routine output back to the operator inbox.", + }, + { + runId: "run-cheap-fallback", + status: "succeeded", + agentId: "agent-codex", + adapterType: "codex_local", + startedAt: "2026-04-29T08:10:00.000Z", + finishedAt: "2026-04-29T08:14:42.000Z", + createdAt: "2026-04-29T08:09:50.000Z", + invocationSource: "manual", + usageJson: { costCents: 91, inputTokens: 21800, outputTokens: 3200 }, + resultJson: { + stopReason: "completed", + modelProfile: { + requested: "cheap", + applied: "primary", + configSource: "adapter_default", + fallbackReason: "Cheap profile not configured for this agent", + }, + }, + livenessState: "advanced", + livenessReason: "Routine fell back to the primary model after the cheap lookup missed.", + continuationAttempt: 0, + lastUsefulActionAt: "2026-04-29T08:14:36.000Z", + nextAction: "Configure agent-codex with a cheap profile to avoid the fallback.", + }, + { + runId: "run-baseline", + status: "succeeded", + agentId: "agent-codex", + adapterType: "codex_local", + startedAt: "2026-04-28T18:05:00.000Z", + finishedAt: "2026-04-28T18:14:11.000Z", + createdAt: "2026-04-28T18:04:50.000Z", + invocationSource: "scheduler", + usageJson: { costCents: 142, inputTokens: 38400, outputTokens: 7200 }, + resultJson: { stopReason: "completed" }, + livenessState: "advanced", + livenessReason: "Standard primary-lane run with no profile metadata recorded.", + continuationAttempt: 0, + lastUsefulActionAt: "2026-04-28T18:13:58.000Z", + nextAction: "Continue with the next planned subtask.", + }, +]; + +function ModelProfileBadgeLedger() { + return ( +
+ + + + + + Model profile metadata + + + Profile badges read resultJson.modelProfile on each run. Applied matching the request renders + emerald; an applied fallback renders amber and surfaces the inline reason. + + + +
+
Profile: cheap
+

requested + applied both equal cheap → emerald badge.

+
+
+
Profile: cheap → primary
+

cheap requested but primary applied → amber badge plus inline fallback reason.

+
+
+
No profile badge
+

Run with no modelProfile metadata renders without a badge for visual contrast.

+
+
+
+
+ ); +} + function RunLedgerWithCostColumns() { return (
@@ -549,6 +660,10 @@ function IssueManagementStories() { +
+ +
+
@@ -599,3 +714,40 @@ export default meta; type Story = StoryObj; export const FullSurfaceMatrix: Story = {}; + +function ModelProfileLedgerStandalone() { + return ( + +
+
+
+
+
+
IssueRunLedger
+

Model profile badges

+

+ Run ledger isolated to the cheap-lane visual states: an emerald applied=cheap badge, an amber + cheap-fell-back-to-primary badge with the inline fallback reason, and a baseline run without a + modelProfile so the visual diff stays obvious. +

+
+
+ cheap applied + cheap → primary + no profile +
+
+
+
+ +
+
+
+
+ ); +} + +export const RunLedgerModelProfileBadges: Story = { + name: "Run ledger - Model profile badges", + render: () => , +}; diff --git a/ui/storybook/stories/projects-goals-workspaces.stories.tsx b/ui/storybook/stories/projects-goals-workspaces.stories.tsx index 76d83d9d2a6..c10f5958366 100644 --- a/ui/storybook/stories/projects-goals-workspaces.stories.tsx +++ b/ui/storybook/stories/projects-goals-workspaces.stories.tsx @@ -66,7 +66,7 @@ function Section({ function hydrateStorybookQueries(queryClient: ReturnType) { queryClient.setQueryData(queryKeys.auth.session, storybookAuthSession); - queryClient.setQueryData(queryKeys.companies.all, storybookCompanies); + queryClient.setQueryData(queryKeys.companies.all, { companies: storybookCompanies, unauthorized: false }); queryClient.setQueryData(queryKeys.agents.list(COMPANY_ID), storybookAgents); queryClient.setQueryData(queryKeys.projects.list(COMPANY_ID), storybookProjects); queryClient.setQueryData(queryKeys.projects.detail(boardProject.id), boardProject); diff --git a/ui/storybook/stories/sub-issues-workflow.stories.tsx b/ui/storybook/stories/sub-issues-workflow.stories.tsx index 87ac834d905..4f4132d440c 100644 --- a/ui/storybook/stories/sub-issues-workflow.stories.tsx +++ b/ui/storybook/stories/sub-issues-workflow.stories.tsx @@ -172,7 +172,7 @@ const viewStateKey = "storybook:sub-issues-workflow:list"; const scopedKey = `${viewStateKey}:${companyId}`; function hydrateQueries(client: ReturnType) { - client.setQueryData(queryKeys.companies.all, storybookCompanies); + client.setQueryData(queryKeys.companies.all, { companies: storybookCompanies, unauthorized: false }); client.setQueryData(queryKeys.auth.session, storybookAuthSession); client.setQueryData(queryKeys.agents.list(companyId), storybookAgents); client.setQueryData(queryKeys.projects.list(companyId), storybookProjects);