Files
PaperClipAI/ui/src/components/design-sandbox/DesignSandboxTaskThread.tsx
T
7b9334cd10 Draft: Build agent-ready design proposal system (#16875)
## Thinking Path

> - Paperclip helps people manage AI agents and their work.
> - People need consistent UI patterns to review and control that work.
> - The current board uses related layouts and controls with different
spacing, type, and behavior.
> - That drift makes it hard for a designer or an agent to build a new
page from a reliable reference.
> - Storybook can show the shared patterns and the states they need to
support.
> - This pull request adds design proposals, a local sandbox, and
reusable UI controls so people can compare the patterns in context.
> - The benefit is a clearer design system that agents can use to build
consistent UI.

## Linked Issues or Issue Description

**Subsystem affected**

`ui/` — React board UI and Storybook.

**Problem or motivation**

Board pages repeat visual and interaction decisions. Storybook did not
provide a complete reference for task views, conversation states,
typography, toolbars, tabs, and light/dark colors. People could not
compare a proposed pattern with the running board in one place.

**Proposed solution**

Add a staged Design Proposals catalog with foundations, components,
layouts, and page specimens. Add an opt-in sandbox. Reuse production
components where possible. Include synthetic conversation states and
shared controls so reviewers can compare and refine them.

**Alternatives considered**

Separate static mockups would not show keyboard behavior, responsive
layout, or real component states. Rebuilding each page only in Storybook
would allow the reference to drift from the board.

**Roadmap alignment**

This improves existing board UI and Skills Manager surfaces. It does not
add a new control-plane capability.

## What Changed

- Added dark and light color references, typography and conversation
specimens, and component stories for buttons, tabs, toolbars, sidebar,
popovers, activity, and task lists.
- Added a local design sandbox with synthetic task conversation playback
and representative states.
- Shared collection toolbars and navigation patterns across task, agent,
project, routine, skill, connector, and artifact pages.
- Added the streamlined Skills tabs and a My Skills collection that uses
the shared skill cards.
- Restored saved-thread access during synthetic playback, kept connector
searchbox semantics, and updated reproduction checks after moving trial
stories.
- Documented the proposed patterns and added focused UI, catalog, and
browser checks.

## Verification

- `pnpm check:token-gates`, `node scripts/check-maps.mjs`, and `node
scripts/storybook-catalog.mjs --check` passed.
- Full workspace `pnpm -r typecheck` and `pnpm build` passed after
merging master. After the review fixes, focused UI typecheck, `pnpm
build-storybook`, 23 Skills Sources tests, and all 15 Storybook
typography browser tests passed.
- Focused task-thread and system-notice suites passed: 251 tests.
Connector Browse passed 84 tests; the connector, attachment, recovery,
and Storybook flyout browser journeys passed locally.
- A local full Vitest run hit one intermittent chat-channels integration
failure; that test passed in isolation. GitHub CI
[39347996059](https://github.com/paperclipai/paperclip/actions/runs/39347996059)
passed on the exact latest commit: 55 successful checks and two skipped
draft-only Storybook jobs.
- Greptile reviewed the exact latest commit at 5/5 with no new comments
or open review threads. GitHub reports the branch as cleanly mergeable.

## Risks

- This PR changes 206 files and exceeds the repository's 100-file review
target. Review by commit and consider a scoped split before merge.
- Design Proposals are staged references. Fixture interactions do not
prove API behavior, permissions, or provider execution.
- UI changes to shared controls may affect pages outside the proposal
sandbox. Focused browser checks and the full CI matrix passed.

## Model Used

- OpenAI Codex, GPT-6 family. The exact runtime model ID and context
window are not exposed in this session. The model used reasoning, code
execution, browser inspection, and local tests. Earlier branch commits
were also AI-assisted in this Codex conversation.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details available in this session)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above where applicable
- [x] I have either linked existing issues or described the issue in-PR
following the relevant issue template
- [x] I have not referenced internal or instance-local Paperclip issues
or links
- [x] My branch name describes the change and contains no internal
ticket id
- [x] I have run focused tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Scott Tong <scott@scotts-mbp-m5-max.local>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-19 17:45:26 -07:00

173 lines
14 KiB
TypeScript

import { TaskChatShimmerScope } from "../task-chat/TaskChatShimmer";
import { revealWords, wordCount } from "./word-reveal";
import { MarkdownWordStreaming } from "../MarkdownWordStreaming";
import { ConversationPlayback } from "./ConversationPlayback";
import { settledPreviewReply as settledReply } from "./settled-preview-reply";
import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
import { useSearchParams } from "react-router-dom";
import type { Agent, FeedbackVoteValue, IssueWorkMode } from "@paperclipai/shared";
import { useStreamlinedUiEnabled } from "../../hooks/useStreamlinedUiEnabled";
import { Button } from "../ui/button";
import { NativeSelect } from "../ui/select";
import { useScrollbarWhileScrolling } from "../side-panel/use-scrollbar-while-scrolling";
import { TaskChatThreadView } from "../task-chat/TaskChatThreadView";
import { TaskChatRunnerTurn } from "../task-chat/TaskChatRunnerTurn";
import { TaskChatLiveRunPill, toolCountSummaryFromEntries } from "../task-chat/TaskChatLiveRunPill";
import { TaskChatLiveTail } from "../task-chat/TaskChatLiveTail";
import { TaskChatComposer } from "../task-chat/TaskChatComposer";
import { TaskChatComposerDock } from "../task-chat/TaskChatComposerDock";
import { TaskChatProtocolCard } from "../task-chat/TaskChatProtocolCard";
import { TaskChatBubbleActions } from "../task-chat/TaskChatBubbleActions";
import { TaskChatPresentationProvider } from "../task-chat/presentation-mode";
import { parseCssTimeMs } from "../task-chat/motion-tokens";
import { isTerminalRunStatus, paperclipRunnerFinalResponse, transcriptToTaskChatItems } from "../task-chat/transcript-adapter";
import type { TaskChatItem, TaskChatMessageItem, TaskChatRuntimeRequestDecision, TaskChatRuntimeRequestItem } from "../task-chat/task-chat-model";
import { previewHistory, THREAD_PREVIEW_ALIASES, THREAD_PREVIEW_CASES, type ThreadPreviewCase } from "./task-thread-fixtures";
/** Local design sandbox only. Uses the same transport adapter and rendered
* surfaces as TaskChatThread; no lab scenarios or imitation thread markup. */
export default function DesignSandboxTaskThread({
children, header, agentName, agent, defaultConversation, previewMode = "catalog",
}: {
children: ReactNode;
header: ReactNode;
agentName: string;
agent?: Agent;
defaultConversation: boolean;
previewMode?: "catalog" | "playback";
}) {
const [params, setParams] = useSearchParams();
const requested = params.get("threadPreview") ?? (defaultConversation ? "staging-conversation" : "saved");
const aliased = THREAD_PREVIEW_ALIASES[requested] ?? requested;
const selected = aliased === "all" || THREAD_PREVIEW_CASES.some(item => item.id === aliased) ? aliased : "saved";
const [generation, setGeneration] = useState(0);
const { enabled: streamlined } = useStreamlinedUiEnabled();
const viewport = useRef<HTMLDivElement>(null);
const onScroll = useScrollbarWhileScrolling();
const choose = (value: string) => setParams(current => {
const next = new URLSearchParams(current);
next.set("threadPreview", value);
return next;
}, { replace: true });
const cases = selected === "all" ? THREAD_PREVIEW_CASES : THREAD_PREVIEW_CASES.filter(item => item.id === selected);
useEffect(() => { if (viewport.current) viewport.current.scrollTop = 0; }, [selected]);
if (previewMode === "playback" && selected !== "saved") return <TaskChatPresentationProvider mode={streamlined ? "streamlined" : "production"}><ConversationPlayback header={header} agentName={agentName} agent={agent} onShowSavedThread={() => choose("saved")} /></TaskChatPresentationProvider>;
return <div className="flex min-h-0 flex-1 flex-col" data-testid="sandbox-task-thread" data-preview-state={selected}>
<div className="flex shrink-0 flex-wrap items-center gap-2 border-b border-border bg-background py-2 text-xs">
<label htmlFor="sandbox-thread-state" className="font-normal text-foreground">Thread preview</label>
<NativeSelect id="sandbox-thread-state" value={selected} onChange={event => choose(event.target.value)} className="w-auto min-w-0 max-w-full text-xs" aria-label="Thread preview state">
<option value="saved">Saved thread</option>
<option value="all">All states ({THREAD_PREVIEW_CASES.length})</option>
{[...new Set(THREAD_PREVIEW_CASES.map(item => item.group))].map(group => <optgroup key={group} label={group}>
{THREAD_PREVIEW_CASES.filter(item => item.group === group).map(item => <option key={item.id} value={item.id}>{item.label}</option>)}
</optgroup>)}
</NativeSelect>
{selected !== "saved" ? <>
<Button size="sm" variant="outline" onClick={() => setGeneration(value => value + 1)}>Reset / replay</Button>
<Button size="sm" variant="ghost" onClick={() => choose("saved")}>Show saved thread</Button>
<span className="text-muted-foreground">Production renderers · synthetic data · preview actions stay local</span>
</> : null}
</div>
{selected === "saved" ? children : <TaskChatPresentationProvider mode={streamlined ? "streamlined" : "production"}>
<div ref={viewport} onScroll={onScroll} className={`scrollbar-while-scrolling flex min-h-0 flex-1 flex-col ${selected === "all" ? "overflow-y-auto" : ""}`} data-testid="sandbox-thread-viewport">
{selected === "all" ? <div className="mx-auto w-full max-w-(--tc-shell-max-w) pt-3">{header}</div> : null}
{cases.map(example => <PreviewCase key={`${selected}:${example.id}:${generation}`} example={example} header={header} agentName={agentName} agent={agent} replay={selected !== "all"} streamlined={streamlined} />)}
</div>
</TaskChatPresentationProvider>}
</div>;
}
function PreviewCase({ example, header, agentName, agent, replay, streamlined }: {
example: ThreadPreviewCase; header: ReactNode; agentName: string; agent?: Agent; replay: boolean; streamlined: boolean;
}) {
const scenario = useMemo(() => example.build(), [example]);
const startedAt = useRef(Date.now() - 40_000);
const [characters, setCharacters] = useState(replay ? 1 : Infinity);
const [decisions, setDecisions] = useState<Record<string, TaskChatRuntimeRequestDecision>>({});
const [votes, setVotes] = useState<Record<string, FeedbackVoteValue>>({});
const [stopped, setStopped] = useState(false);
const [resumed, setResumed] = useState(false);
const [takeoverDismissed, setTakeoverDismissed] = useState(false);
const [workMode, setWorkMode] = useState<IssueWorkMode>("standard");
const [messages, setMessages] = useState<TaskChatItem[]>([]);
const status = stopped ? "cancelled" : scenario.status;
const terminal = isTerminalRunStatus(status);
const parsed = useMemo(() => transcriptToTaskChatItems(scenario.entries, { runId: `synthetic-${example.id}`, agentName, running: !terminal }), [scenario, example.id, agentName, terminal]);
const streamingLength = parsed.reduce((length, item) => item.kind === "message" && item.streaming ? Math.max(length, wordCount(item.text)) : item.kind === "thinking" && item.streaming ? Math.max(length, wordCount(item.lines.join("\n"))) : length, 0);
useEffect(() => {
if (!replay || !streamingLength) return;
const interval = parseCssTimeMs(getComputedStyle(document.documentElement).getPropertyValue("--motion-sandbox-word-tick"));
if (!interval || window.matchMedia("(prefers-reduced-motion: reduce)").matches) { setCharacters(Infinity); return; }
const timer = window.setInterval(() => setCharacters(count => {
if (count >= streamingLength) { window.clearInterval(timer); return Infinity; }
return count + 1;
}), interval);
return () => window.clearInterval(timer);
}, [replay, streamingLength]);
const items = parsed.map(item => {
if (item.kind === "message" && item.streaming) return { ...item, text: revealWords(item.text, characters) };
if (item.kind === "thinking" && item.streaming) return { ...item, lines: [revealWords(item.lines.join("\n"), characters)] };
if (item.kind === "protocol" && item.surface === "runtime_request" && decisions[item.id]) {
const decision = decisions[item.id];
return { ...item, status: "resolved" as const, resolvedAction: decision.action, ...("response" in decision ? { response: decision.response } : {}) };
}
return item;
});
const pending = items.find((item): item is TaskChatRuntimeRequestItem => item.kind === "protocol" && item.surface === "runtime_request" && item.status === "pending");
const runtimeDecision = (item: TaskChatRuntimeRequestItem, decision: TaskChatRuntimeRequestDecision) => setDecisions(current => ({ ...current, [item.id]: decision }));
const history = useMemo(() => {
const prior = previewHistory(agentName);
return [prior.human, ...settledReply({ ...prior.response, agent }, prior.entries, `synthetic-${example.id}-history`)];
}, [agentName, agent, example.id]);
const actions = (item: TaskChatMessageItem) => item.author === "agent" && !item.streaming ? <TaskChatBubbleActions copyText={item.text} feedback={{
activeVote: votes[item.id] ?? null, sharingPreference: "allowed", termsUrl: null,
onVote: async vote => { setVotes(current => ({ ...current, [item.id]: vote })); },
}} /> : null;
const followup: TaskChatMessageItem = { id: "synthetic-followup", kind: "message", author: "human", isCurrentUser: true, text: "Tell me your method for finding this out.", timestamp: "10:12 AM", optimistic: scenario.messageState };
const final = terminal && !scenario.renderer ? paperclipRunnerFinalResponse(parsed, { allowFallback: true }) : undefined;
const failed = ["failed", "timed_out", "cancelled"].includes(status);
const notice: TaskChatItem[] = scenario.notice ? [{ id: "synthetic-notice", kind: "message", author: "system", text: "Synthetic workspace notice. Expand this row to inspect the details.", timestamp: "10:13 AM", presentation: { kind: "system_notice", tone: scenario.notice, title: `Workspace preview · ${scenario.notice}`, detailsDefaultOpen: false, density: "compact" } }] : [];
const historyItems = [...history, followup, ...(final ? settledReply({ ...final, interstitial: false, streaming: false, authorName: agentName, agent, timestamp: "10:13 AM" }, scenario.entries, `synthetic-${example.id}`, failed) : []), ...notice, ...messages];
const showTail = !final && !scenario.paused && !scenario.notice && !scenario.messageState;
const showComposer = replay || Boolean(pending || scenario.paused || scenario.messageState);
const agentMap = useMemo(() => new Map([[agent?.id ?? "synthetic-agent", agent ?? { id: "synthetic-agent", name: agentName }]]), [agent, agentName]);
return <section className={`flex min-w-0 flex-1 flex-col ${replay ? "min-h-0" : "pt-4"}`} data-preview-case={example.id} data-preview-renderer={scenario.renderer ?? "transcript"} aria-label={example.label}>
{!replay ? <h3 className="mx-auto mb-3 w-full max-w-(--tc-shell-max-w) border-t border-border pt-4 text-xs font-normal text-muted-foreground">{example.label}</h3> : null}
<TaskChatThreadView items={historyItems} scroll={replay} header={replay ? header : undefined} className={replay ? "pt-3" : undefined} renderMessageActions={actions} onRuntimeRequestDecision={runtimeDecision} tail={showTail ? <>
{scenario.renderer === "native" ? <TaskChatRunnerTurn
runId={`synthetic-${example.id}`} agentName={agentName} agent={agent} items={items} status={status}
startedAtMs={status === "queued" ? null : startedAt.current} finishedAtMs={terminal ? startedAt.current + 40_000 : null}
activityUnavailable={scenario.activityUnavailable} continuedAfterSteering={scenario.continuedAfterSteering}
onRuntimeRequestDecision={runtimeDecision}
/> : <TaskChatShimmerScope items={items}>
<TaskChatLiveRunPill status={status} startedAtMs={status === "queued" ? null : startedAt.current} finishedAtMs={terminal ? startedAt.current + 40_000 : null} toolSummary={toolCountSummaryFromEntries(scenario.entries)} />
<MarkdownWordStreaming.Provider value={replay}><TaskChatLiveTail items={items} emptyMessage={scenario.emptyMessage ?? "Waiting for transcript…"} onRuntimeRequestDecision={runtimeDecision} /></MarkdownWordStreaming.Provider>
{failed ? <TaskChatThreadView items={[{ id: "synthetic-run-stop", kind: "marker", variant: "interrupted", tone: status === "cancelled" ? "neutral" : "error", collapsible: true, label: status === "cancelled" ? "Run cancelled" : status === "timed_out" ? "Run timed out" : "Run failed", detail: status === "cancelled" ? "The synthetic run was stopped; no saved task was changed." : "Synthetic provider failure: the test process stopped before a final reply was available." }]} scroll={false} /> : null}
</TaskChatShimmerScope>}
</> : null} />
{showComposer ? <TaskChatComposerDock mobile={false} streamlined={streamlined}>
<TaskChatComposer
agentMap={agentMap} modelAgents={agent ? new Map([[agent.id, agent]]) : undefined} currentAssigneeValue={`agent:${agent?.id ?? "synthetic-agent"}`}
enableReassign reassignOptions={[{ id: `agent:${agent?.id ?? "synthetic-agent"}`, label: agentName }]}
workMode={workMode} onWorkModeChange={setWorkMode}
placeholder={`Message ${agentName} — synthetic reply…`}
draftKey={`paperclip:design-sandbox:synthetic-thread:${example.id}`}
onStop={!terminal ? async () => setStopped(true) : undefined}
pause={scenario.paused && !resumed ? { scope: scenario.paused, onResume: async () => setResumed(true) } : null}
takeover={pending && !takeoverDismissed ? {
id: pending.id, label: pending.requestType === "permission" ? "Permission" : "Questions", pendingCount: 1,
content: <TaskChatProtocolCard item={pending} presentation="takeover" onRuntimeRequestDecision={runtimeDecision} />,
onDismiss: () => setTakeoverDismissed(true), onSkip: () => runtimeDecision(pending, { action: "cancel" }),
} : null}
pendingTakeover={pending && takeoverDismissed ? { count: 1, label: "1 pending input", onOpen: () => setTakeoverDismissed(false) } : null}
onAdd={async body => setMessages(current => [...current,
{ id: `local-human-${current.length}`, kind: "message", author: "human", text: body, timestamp: "Just now", isCurrentUser: true },
{ id: `local-agent-${current.length}`, kind: "message", author: "agent", authorName: agentName, agent, text: "Preview reply received. This exchange exists only in your browser; no agent was started.", timestamp: "Just now" },
])}
/>
</TaskChatComposerDock> : null}
</section>;
}