Files
PaperClipAI/ui/src/components/interrupt-handoff/InterruptHandoffViews.tsx
T
1ef3b08714 feat(ui): integrate agent personas across the app (#13171)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - A stable agent persona is useful only when the same identity appears
across the app.
> - Lists, task messages, selectors, and activity feeds need inexpensive
static avatars.
> - Onboarding and agent headers need a larger character with
expressions and pointer tracking.
> - This pull request connects the persona foundation to those existing
views and preserves onboarding draft assignments.
> - Full-page stories and Linux checks make the placements and
performance contract reviewable.

## Linked Issues or Issue Description

**Problem or motivation**

Agents need a stable visual identity in lists, tasks, onboarding, and
configuration. External tools also need an image URL for that identity.

**Proposed solution**

Assign each agent a permanent palette from a fixed ClipLab character
library. Store the assignment on the agent. Render and cache preset PNG
URLs on demand. Use static images in dense views and one animated
character in larger placements.

**Alternatives considered**

A generated image bundle requires a separate asset build. A live
renderer in every avatar adds unnecessary work in large lists. Arbitrary
uploaded images do not provide the requested shared character system.

**Roadmap alignment**

This improves agent identity across existing control-plane views. It
preserves agent permissions, company boundaries, and status labels.
ROADMAP.md has no separate ClipLab persona milestone.

Related approaches: #2422 adds configurable image URLs and DiceBear
generation; #5578 adds optional uploaded avatars. This work uses a
fixed, versioned character library and preset URLs.

## What Changed

- Replace agent icons with static persona images across lists, the
sidebar, org charts, tasks, comments, selectors, activity, and dashboard
views.
- Put one animated character in the agent header. Let it follow the
pointer across the page, with reduced-motion and touch fallbacks.
- Add larger padded characters to agent creation. Keep the palette
stable across draft refreshes and connection retries, then reveal it
after success.
- Pass appearance through shared projections rather than fetching each
agent separately.
- Add real full-page Storybook examples for the agent list, overview,
task, dashboard, new-agent dialog, and connection page.
- Add Linux screenshot, clipping, density, and 500-avatar performance
checks.

## Verification

- `pnpm -r typecheck`, `pnpm build`, and token gates pass on the rebased
tree. Persona lifecycle tests pass.
- The rebased feature passes 38 Linux screenshot/performance checks,
including both display densities, corner pointer positions, and the
no-WebGL/no-live-download contract for 500 avatars.
- The final Linux persona suite passes all 38 visual, lifecycle,
density, and full-page checks using the standard Storybook configuration
and real on-demand avatar endpoint.
- Final local focused verification: 45 avatar/native-recovery tests
pass; UI identity/routine tests, typecheck/build, token gates, and
Storybook build pass.
- Current-head CI passes: full workspace/server tests, all serialized
server groups, typecheck/release checks, build, canary validation, and
end-to-end shards. The build passed after retrying a native-runner
concurrency-test failure; its three targeted cases also pass locally.
- Manual inspection covered stable identities in the app, header
placement, full-page mouse tracking, onboarding size, and task/dashboard
placements.


### Screenshots

Linux captures use synthetic Storybook fixtures. Full-page captures use
reduced motion. The live character, mouse tracking, and disposal are
checked separately.

<details>
<summary>Agent overview with the character in its header</summary>

<img
src="https://raw.githubusercontent.com/paperclipai/paperclip/8c68f42b268ada22b67d79d0fe1bb0a2f84ec25c/screenshots/full-page-agent-overview.png"
width="900" alt="Agent overview with the character in its header" />

</details>
<details>
<summary>Task messages and assignee identity</summary>

<img
src="https://raw.githubusercontent.com/paperclipai/paperclip/8c68f42b268ada22b67d79d0fe1bb0a2f84ec25c/screenshots/full-page-task.png"
width="900" alt="Task messages and assignee identity" />

</details>
<details>
<summary>Larger onboarding character with room for expressions</summary>

<img
src="https://raw.githubusercontent.com/paperclipai/paperclip/8c68f42b268ada22b67d79d0fe1bb0a2f84ec25c/screenshots/full-page-meet-your-next-agent.png"
width="900" alt="Larger onboarding character with room for expressions"
/>

</details>
<details>
<summary>Dashboard agent activity</summary>

<img
src="https://raw.githubusercontent.com/paperclipai/paperclip/8c68f42b268ada22b67d79d0fe1bb0a2f84ec25c/screenshots/full-page-company-dashboard.png"
width="900" alt="Dashboard agent activity" />

</details>

## Risks

- This PR depends on #13170, the persona foundation. Merge the
foundation first, then retarget this PR to master.
- Many placements change from icons to character silhouettes. Human
avatars and authoritative agent status labels retain their existing
behavior.
- Only one character can render live per view. Reduced motion,
hidden/offscreen content, touch input, and renderer failures use the
defined fallbacks.
- The full-page stories use fixture data. They do not contact a real
company or complete real provider sign-in.

## Model Used

OpenAI Codex, GPT-6 family. The exact model identifier and context
window are not exposed in this session. Used code editing, shell
execution, browser inspection, and Linux visual testing.

## 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)
- [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
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run 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 any 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: Paperclip <noreply@paperclip.ing>
Co-authored-by: Tonio <tonework@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-19 07:57:53 -05:00

350 lines
11 KiB
TypeScript

import { AlertTriangle, Info, PauseCircle, User, X } from "lucide-react";
import { cn } from "../../lib/utils";
import { AgentAvatar, type AvatarAgent } from "../AgentAvatar";
import {
classifyAssigneeHandoff,
resolveRunStatusPresentation,
type ComposerHandoffPreview,
type PauseAffectsSummary,
type PlainAgentNameCandidate,
type ReassignInterruptCopy,
type TimelineAssigneeLike,
} from "../../lib/interrupt-handoff";
/**
* Presentational views for the interrupt-handoff UX clarity surfaces (PAP-10669).
* All logic lives in `lib/interrupt-handoff.ts`; these components only render it,
* so they can be exercised in isolation by component tests and Storybook.
*/
export interface HandoffAgentLike extends AvatarAgent {
name: string;
icon?: string | null;
}
export interface HandoffChipResolvers {
agentMap?: ReadonlyMap<string, HandoffAgentLike> | null;
resolveUserLabel?: (userId: string) => string | null;
currentUserId?: string | null;
}
function agentName(agentId: string, resolvers: HandoffChipResolvers): string {
return resolvers.agentMap?.get(agentId)?.name ?? agentId.slice(0, 8);
}
function agentIcon(agentId: string, resolvers: HandoffChipResolvers): string | null {
return resolvers.agentMap?.get(agentId)?.icon ?? null;
}
function userLabel(userId: string, resolvers: HandoffChipResolvers): string {
const label = resolvers.resolveUserLabel?.(userId) ?? null;
const base = label ?? "Board";
return resolvers.currentUserId && resolvers.currentUserId === userId ? `${base} (you)` : base;
}
const CHIP_CLASS =
"inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs";
/** A labelled assignee chip — agent, user, or unassigned — that never lets a
* user owner read like an agent. */
export function AssigneeChip({
assignee,
resolvers,
className,
}: {
assignee: TimelineAssigneeLike;
resolvers: HandoffChipResolvers;
className?: string;
}) {
if (assignee.agentId) {
return (
<span className={cn(CHIP_CLASS, className)} data-testid="handoff-assignee-chip" data-kind="agent">
<span className="sr-only">Agent </span>
<AgentAvatar agent={{ ...resolvers.agentMap?.get(assignee.agentId), id: assignee.agentId }} size={16} />
<span className="max-w-(--sz-12rem) truncate">{agentName(assignee.agentId, resolvers)}</span>
</span>
);
}
if (assignee.userId) {
return (
<span className={cn(CHIP_CLASS, className)} data-testid="handoff-assignee-chip" data-kind="user">
<span className="sr-only">User </span>
<User className="h-3 w-3 shrink-0 text-muted-foreground" />
<span className="max-w-(--sz-12rem) truncate">{userLabel(assignee.userId, resolvers)}</span>
</span>
);
}
return (
<span
className={cn("text-xs italic text-muted-foreground", className)}
data-testid="handoff-assignee-chip"
data-kind="unassigned"
>
<span className="sr-only">No responsible — </span>
Unassigned
</span>
);
}
/** The "Wake" sub-row that makes each handoff state self-describing: a queued
* agent wake, a board-user handoff with no wake, or no agent selected. */
export function HandoffWakeRow({
to,
resolvers,
interruptedRunAttached = false,
}: {
to: TimelineAssigneeLike;
resolvers: HandoffChipResolvers;
interruptedRunAttached?: boolean;
}) {
const info = classifyAssigneeHandoff(to, {
agentName: to.agentId ? agentName(to.agentId, resolvers) : null,
interruptedRunAttached,
});
return (
<div
className="flex flex-wrap items-center gap-1.5 text-xs"
data-testid="handoff-wake-row"
data-kind={info.kind}
>
<span className="text-xs font-medium uppercase tracking-wider text-muted-foreground">Wake</span>
<span className={cn(info.kind === "agent_wake" ? "text-foreground" : "text-muted-foreground")}>
{info.wakeText}
</span>
</div>
);
}
/** Run status text that distinguishes an intentional operator interrupt
* (amber "interrupted") from a generic muted "cancelled". */
export function RunStatusBadge({
status,
operatorInterrupted = false,
className,
}: {
status: string;
operatorInterrupted?: boolean;
className?: string;
}) {
const p = resolveRunStatusPresentation(status, { operatorInterrupted });
return (
<span
className={cn("font-medium", p.className, className)}
data-testid="run-status-badge"
data-interrupted={operatorInterrupted ? "true" : "false"}
>
{p.label}
{p.srHint ? <span className="sr-only"> — {p.srHint}</span> : null}
</span>
);
}
function PreviewChip({
chip,
resolvers,
}: {
chip: NonNullable<ComposerHandoffPreview["chip"]>;
resolvers: HandoffChipResolvers;
}) {
return (
<AssigneeChip
assignee={chip.kind === "agent" ? { agentId: chip.id, userId: null } : { agentId: null, userId: chip.id }}
resolvers={resolvers}
/>
);
}
/** One-line interpretation of what submitting the comment will durably do. */
export function ComposerHandoffPreviewRow({
preview,
resolvers,
}: {
preview: ComposerHandoffPreview;
resolvers: HandoffChipResolvers;
}) {
if (preview.kind === "none") return null;
return (
<div
className={cn(
"flex flex-wrap items-center justify-end gap-1.5 text-xs",
preview.tone === "warn" ? "text-amber-700 dark:text-amber-300" : "text-muted-foreground",
)}
data-testid="composer-handoff-preview"
data-kind={preview.kind}
role="status"
aria-live="polite"
>
<span>{preview.text}</span>
{preview.chip ? <PreviewChip chip={preview.chip} resolvers={resolvers} /> : null}
{preview.suffix ? <span>{preview.suffix}</span> : null}
</div>
);
}
/** Inline coach shown when the body contains a plain agent name without a chip,
* offering a one-click upgrade to a real mention. */
export function ComposerMentionCoach({
candidate,
agentDisplayName,
onInsert,
onDismiss,
}: {
candidate: PlainAgentNameCandidate;
agentDisplayName: string;
onInsert: () => void;
onDismiss: () => void;
}) {
return (
<div
className="flex items-center gap-2 rounded-md border border-amber-300/40 bg-amber-50/70 px-2 py-1.5 text-xs text-amber-700 dark:bg-amber-500/10 dark:text-amber-300"
data-testid="composer-mention-coach"
role="alert"
aria-live="polite"
>
<Info className="h-3.5 w-3.5 shrink-0" aria-hidden />
<span className="min-w-0 flex-1">
Did you mean <span className="font-medium">@{candidate.matchedText}</span>? Plain text won't
notify or assign an agent.
</span>
<button
type="button"
onClick={onInsert}
className="shrink-0 rounded border border-amber-400/50 px-1.5 py-0.5 font-medium hover:bg-amber-100/60 dark:hover:bg-amber-500/20"
aria-label={`Insert mention for ${agentDisplayName} into your comment`}
>
Insert mention
</button>
<button
type="button"
onClick={onDismiss}
className="shrink-0 rounded p-0.5 hover:bg-amber-100/60 dark:hover:bg-amber-500/20"
aria-label="Dismiss suggestion"
>
<X className="h-3.5 w-3.5" aria-hidden />
</button>
</div>
);
}
/** Live banner shown at the top of the responsible picker while a run is in flight,
* warning that reassigning will interrupt it. (design surface 2) */
export function AssigneeRunningBanner({
copy,
className,
}: {
copy: ReassignInterruptCopy;
className?: string;
}) {
return (
<div
role="status"
aria-live="polite"
data-testid="assignee-running-banner"
className={cn(
"flex items-start gap-1.5 rounded-md border border-amber-300/40 bg-amber-50/70 px-2 py-1.5 text-xs text-amber-700 dark:bg-amber-500/10 dark:text-amber-300",
className,
)}
>
<AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" aria-hidden />
<span className="min-w-0 flex-1">{copy.banner}</span>
</div>
);
}
/** "Interrupt & assign" confirm step shown when an operator picks a different
* target while a run is live. (design surface 2) */
export function InterruptAssignConfirm({
copy,
to,
resolvers,
onConfirm,
onCancel,
}: {
copy: ReassignInterruptCopy;
/** The target the operator selected. */
to: TimelineAssigneeLike;
resolvers: HandoffChipResolvers;
onConfirm: () => void;
onCancel: () => void;
}) {
return (
<div
data-testid="interrupt-assign-confirm"
className="space-y-2 rounded-md border border-amber-300/40 bg-amber-50/70 p-2 text-xs text-amber-700 dark:bg-amber-500/10 dark:text-amber-300"
>
<div className="flex items-start gap-1.5">
<AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" aria-hidden />
<div className="min-w-0 flex-1 space-y-1">
<p className="font-medium">{copy.confirmTitle}</p>
<p className="flex flex-wrap items-center gap-1 text-amber-700/90 dark:text-amber-300/90">
<span>Hand off to</span>
<AssigneeChip assignee={to} resolvers={resolvers} />
</p>
</div>
</div>
<div className="flex justify-end gap-2">
<button
type="button"
onClick={onCancel}
className="rounded border border-amber-400/50 px-2 py-0.5 font-medium hover:bg-amber-100/60 dark:hover:bg-amber-500/20"
>
{copy.cancelAction}
</button>
<button
type="button"
onClick={onConfirm}
data-testid="interrupt-assign-confirm-action"
className="rounded bg-amber-600 px-2 py-0.5 font-medium text-white hover:bg-amber-700 dark:bg-amber-500 dark:hover:bg-amber-400"
>
{copy.confirmAction}
</button>
</div>
</div>
);
}
/** "What this affects" bucket summary for the pause/hold dialog. (design surface 4) */
export function PauseAffectsSummaryView({
summary,
className,
}: {
summary: PauseAffectsSummary;
className?: string;
}) {
const visibleBuckets = summary.buckets.filter((bucket) => bucket.count > 0);
return (
<div
data-testid="pause-affects-summary"
className={cn("space-y-2 rounded-md border border-border bg-muted/30 p-3", className)}
>
<div className="flex items-center gap-1.5 text-xs font-medium uppercase tracking-wider text-muted-foreground">
<PauseCircle className="h-3.5 w-3.5" aria-hidden />
What this affects
</div>
{summary.nothingLive ? (
<p role="status" className="text-xs text-muted-foreground" data-testid="pause-nothing-live">
Nothing live to pause — no agent run is in flight or queued. This records a hold so new work
won't start until you resume.
</p>
) : null}
{visibleBuckets.length > 0 ? (
<ul className="space-y-1">
{visibleBuckets.map((bucket) => (
<li
key={bucket.key}
data-bucket={bucket.key}
className="flex flex-wrap items-baseline gap-x-1.5 gap-y-0.5 text-xs"
>
<span className="font-medium text-foreground">{bucket.label}:</span>
<span className="tabular-nums text-foreground">{bucket.count}</span>
<span className="text-muted-foreground">— {bucket.detail}</span>
</li>
))}
</ul>
) : (
<p className="text-xs text-muted-foreground">No tasks are affected.</p>
)}
</div>
);
}