Merge upstream/master into dev (13 commits — includes #5922, #5938, blocked inbox, recovery actions)

This commit is contained in:
2026-05-13 22:35:18 -04:00
180 changed files with 31626 additions and 545 deletions
+33 -1
View File
@@ -1,17 +1,44 @@
import { memo, useMemo } from "react";
import { Link } from "@/lib/router";
import { useQueries, useQuery } from "@tanstack/react-query";
import type { Issue } from "@paperclipai/shared";
import type { Issue, IssueRecoveryAction } from "@paperclipai/shared";
import { heartbeatsApi, type LiveRunForIssue } from "../api/heartbeats";
import type { TranscriptEntry } from "../adapters";
import { issuesApi } from "../api/issues";
import { queryKeys } from "../lib/queryKeys";
import { cn, relativeTime } from "../lib/utils";
import {
deriveActiveRecoveryDisplayState,
RECOVERY_CHIP_DEFAULT_TONE,
} from "../lib/recovery-display";
import { ExternalLink } from "lucide-react";
import { Identity } from "./Identity";
import { RunChatSurface } from "./RunChatSurface";
import { useLiveRunTranscripts } from "./transcript/useLiveRunTranscripts";
function RunCardRecoveryChip({ action }: { action: IssueRecoveryAction }) {
const state = deriveActiveRecoveryDisplayState(action);
if (!state) return null;
const tone = RECOVERY_CHIP_DEFAULT_TONE[state];
const Icon = tone.icon;
return (
<span
data-testid="active-agent-run-recovery-indicator"
data-recovery-state={state}
role="status"
aria-label={tone.label}
title={`${tone.label} — open the source issue to act.`}
className={cn(
"inline-flex shrink-0 items-center gap-0.5 rounded-full border px-1.5 py-0.5 text-[10px] font-medium",
tone.className,
)}
>
<Icon className="h-2.5 w-2.5" aria-hidden />
{tone.label}
</span>
);
}
const MIN_DASHBOARD_RUNS = 4;
const DASHBOARD_RUN_CARD_LIMIT = 4;
const DASHBOARD_LOG_POLL_INTERVAL_MS = 15_000;
@@ -189,6 +216,11 @@ const AgentRunCard = memo(function AgentRunCard({
{issue?.identifier ?? run.issueId.slice(0, 8)}
{issue?.title ? ` - ${issue.title}` : ""}
</Link>
{issue?.activeRecoveryAction ? (
<div className="mt-1.5">
<RunCardRecoveryChip action={issue.activeRecoveryAction} />
</div>
) : null}
</div>
)}
</div>
+329
View File
@@ -0,0 +1,329 @@
// @vitest-environment jsdom
import { act } from "react";
import { createRoot } from "react-dom/client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import type { Issue, IssueBlockedInboxAttention } from "@paperclipai/shared";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const mockIssuesApi = vi.hoisted(() => ({
list: vi.fn(),
count: vi.fn(),
}));
vi.mock("../api/issues", () => ({
issuesApi: mockIssuesApi,
}));
vi.mock("@/lib/router", () => ({
Link: ({
children,
className,
disableIssueQuicklook: _disableIssueQuicklook,
issuePrefetch: _issuePrefetch,
...props
}: React.ComponentProps<"a"> & { disableIssueQuicklook?: boolean; issuePrefetch?: Issue | null }) => (
<a className={className} {...props}>
{children}
</a>
),
}));
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
import { BlockedInboxView } from "./BlockedInboxView";
import { defaultIssueFilterState } from "../lib/issue-filters";
function attention(
overrides: Partial<IssueBlockedInboxAttention> = {},
): IssueBlockedInboxAttention {
return {
kind: "blocked",
state: "needs_attention",
reason: "blocked_chain_stalled",
severity: "medium",
stoppedSinceAt: "2026-05-08T10:00:00.000Z",
owner: { type: "agent", agentId: "agent-1", userId: null, label: null },
action: { label: "Resolve PAP-77", detail: null },
sourceIssue: null,
leafIssue: null,
recoveryIssue: null,
approvalId: null,
interactionId: null,
sampleIssueIdentifier: null,
redaction: { externalDetailsRedacted: false, secretFieldsOmitted: true },
...overrides,
};
}
function makeIssue(
id: string,
identifier: string,
title: string,
attentionPayload: IssueBlockedInboxAttention,
): Issue {
return {
id,
companyId: "company-1",
projectId: null,
projectWorkspaceId: null,
goalId: null,
parentId: null,
title,
description: null,
status: "in_progress",
workMode: "standard",
priority: "medium",
assigneeAgentId: "agent-1",
assigneeUserId: null,
checkoutRunId: null,
executionRunId: null,
executionAgentNameKey: null,
executionLockedAt: null,
createdByAgentId: null,
createdByUserId: null,
issueNumber: 1,
identifier,
requestDepth: 0,
billingCode: null,
assigneeAdapterOverrides: null,
executionWorkspaceId: null,
executionWorkspacePreference: null,
executionWorkspaceSettings: null,
startedAt: null,
completedAt: null,
cancelledAt: null,
hiddenAt: null,
blockedInboxAttention: attentionPayload,
createdAt: new Date("2026-05-09T00:00:00.000Z"),
updatedAt: new Date("2026-05-09T00:00:00.000Z"),
} as Issue;
}
function renderWithClient(node: React.ReactNode, container: HTMLDivElement) {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, staleTime: 0, gcTime: 0 } },
});
const root = createRoot(container);
act(() => {
root.render(<QueryClientProvider client={queryClient}>{node}</QueryClientProvider>);
});
return { root, queryClient };
}
const blockedViewProps = {
companyId: "company-1",
searchQuery: "",
agentNameById: new Map<string, string>(),
issueLinkState: null,
groupBy: "none" as const,
sortBy: "most_recent" as const,
issueFilters: defaultIssueFilterState,
currentUserId: "local-board",
liveIssueIds: new Set<string>(),
workspaceFilterContext: {},
showStatusColumn: true,
showIdentifierColumn: true,
showUpdatedColumn: true,
};
async function waitFor(predicate: () => boolean, attempts = 30): Promise<void> {
for (let i = 0; i < attempts; i += 1) {
if (predicate()) return;
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 5));
});
}
throw new Error("waitFor predicate did not become true");
}
describe("BlockedInboxView", () => {
let container: HTMLDivElement;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
mockIssuesApi.list.mockReset();
});
afterEach(() => {
container.remove();
});
it("shows the empty state when no blocked issues are returned", async () => {
mockIssuesApi.list.mockResolvedValue([]);
const { root } = renderWithClient(
<BlockedInboxView
{...blockedViewProps}
/>,
container,
);
await waitFor(() => container.querySelector('[data-testid="blocked-inbox-empty"]') !== null);
expect(container.querySelector('[data-testid="blocked-inbox-empty"]')).not.toBeNull();
act(() => root.unmount());
});
it("defaults to no grouping and orders rows by most recent stopped item first", async () => {
const issues: Issue[] = [
makeIssue(
"issue-low",
"PAP-1",
"External wait row",
attention({ reason: "external_owner_action", severity: "low" }),
),
makeIssue(
"issue-stalled-high",
"PAP-2",
"Stalled chain row",
attention({
reason: "blocked_chain_stalled",
severity: "high",
stoppedSinceAt: "2026-05-09T01:00:00.000Z",
action: { label: "Resolve PAP-9", detail: null },
}),
),
makeIssue(
"issue-stalled-critical",
"PAP-3",
"Critical stalled row",
attention({
reason: "blocked_chain_stalled",
severity: "critical",
stoppedSinceAt: "2026-05-09T05:00:00.000Z",
action: { label: "Resolve PAP-10", detail: null },
}),
),
makeIssue(
"issue-decision",
"PAP-4",
"Pending board decision",
attention({
reason: "pending_board_decision",
severity: "medium",
owner: { type: "board", agentId: null, userId: null, label: "Board" },
action: { label: "Accept or reject", detail: null },
}),
),
];
mockIssuesApi.list.mockResolvedValue(issues);
const { root } = renderWithClient(
<BlockedInboxView
{...blockedViewProps}
agentNameById={new Map([["agent-1", "ClaudeCoder"]])}
/>,
container,
);
await waitFor(() => container.querySelectorAll("a").length === 4);
expect(container.querySelectorAll('[data-testid^="blocked-inbox-group-"]')).toHaveLength(0);
const titles = Array.from(container.querySelectorAll("a")).map((a) => a.textContent ?? "");
expect(titles[0]).toContain("Critical stalled row");
expect(titles[1]).toContain("Stalled chain row");
expect(mockIssuesApi.list).toHaveBeenCalledWith("company-1", expect.objectContaining({
attention: "blocked",
includeBlockedInboxAttention: true,
includeBlockedBy: true,
}));
act(() => root.unmount());
});
it("places blocker reason chips with the title before owner and timestamp metadata", async () => {
mockIssuesApi.list.mockResolvedValue([
makeIssue(
"issue-decision",
"PAP-4",
"Pending board decision",
attention({
reason: "pending_board_decision",
severity: "medium",
owner: { type: "board", agentId: null, userId: null, label: "Board" },
action: { label: "Accept or reject", detail: null },
}),
),
]);
const { root } = renderWithClient(
<BlockedInboxView
{...blockedViewProps}
/>,
container,
);
await waitFor(() => container.querySelector("a") !== null);
const rowText = container.querySelector("a")?.textContent ?? "";
expect(rowText.indexOf("Pending board decision")).toBeGreaterThanOrEqual(0);
expect(rowText.indexOf("Needs decision")).toBeGreaterThan(rowText.indexOf("Pending board decision"));
expect(rowText.indexOf("Board")).toBeGreaterThan(rowText.indexOf("Needs decision"));
expect(rowText).not.toContain("Accept or reject");
expect(container.querySelector('[data-testid="blocked-row-reason-column"]')?.textContent).toContain("Needs decision");
act(() => root.unmount());
});
it("filters rows by search query against title, identifier, owner and action", async () => {
const issues: Issue[] = [
makeIssue(
"issue-1",
"PAP-77",
"Resume parked work",
attention({
reason: "blocked_by_assigned_backlog_issue",
owner: { type: "agent", agentId: null, userId: null, label: "Charlie" },
action: { label: "Resume parked blocker", detail: null },
}),
),
makeIssue(
"issue-2",
"PAP-99",
"Other unrelated thing",
attention({
reason: "external_owner_action",
owner: { type: "external", agentId: null, userId: null, label: "Vendor" },
action: { label: "Awaiting Vendor", detail: null },
}),
),
];
mockIssuesApi.list.mockResolvedValue(issues);
const { root } = renderWithClient(
<BlockedInboxView
{...blockedViewProps}
searchQuery="charlie"
/>,
container,
);
await waitFor(() => container.querySelectorAll("a").length > 0);
const links = container.querySelectorAll("a");
const titles = Array.from(links).map((a) => a.textContent ?? "");
expect(titles.some((t) => t.includes("Resume parked work"))).toBe(true);
expect(titles.some((t) => t.includes("Other unrelated thing"))).toBe(false);
act(() => root.unmount());
});
it("renders the visible error banner with retry when the query fails", async () => {
mockIssuesApi.list.mockRejectedValue(new Error("network down"));
const { root } = renderWithClient(
<BlockedInboxView
{...blockedViewProps}
/>,
container,
);
await waitFor(() =>
container.querySelector('[data-testid="blocked-inbox-error"]') !== null,
);
const banner = container.querySelector('[data-testid="blocked-inbox-error"]');
expect(banner).not.toBeNull();
expect(banner?.getAttribute("role")).toBe("alert");
expect(banner?.textContent).toContain("Couldn't load the Blocked tab");
act(() => root.unmount());
});
});
+386
View File
@@ -0,0 +1,386 @@
import { useMemo, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { AlertTriangle, CheckCircle2 } from "lucide-react";
import type { Issue } from "@paperclipai/shared";
import { issuesApi } from "../api/issues";
import { queryKeys } from "../lib/queryKeys";
import { cn } from "../lib/utils";
import { applyIssueFilters, type IssueFilterState, type IssueFilterWorkspaceContext } from "../lib/issue-filters";
import {
blockedRowMatchesSearch,
buildBlockedInboxRows,
formatStoppedAge,
groupBlockedInboxRows,
sortBlockedInboxRows,
type BlockedInboxGroupBy,
type BlockedInboxIssueRow,
type BlockedInboxSort,
} from "../lib/blockedInbox";
import { BlockedReasonChip } from "./BlockedReasonChip";
import { IssueGroupHeader } from "./IssueGroupHeader";
import { IssueRow } from "./IssueRow";
import { Identity } from "./Identity";
import { StatusIcon } from "./StatusIcon";
import { Button } from "@/components/ui/button";
interface BlockedInboxViewProps {
companyId: string;
searchQuery: string;
agentNameById: ReadonlyMap<string, string>;
userLabelById?: ReadonlyMap<string, string>;
issueLinkState: unknown;
groupBy: BlockedInboxGroupBy;
sortBy: BlockedInboxSort;
issueFilters: IssueFilterState;
currentUserId: string | null;
liveIssueIds: ReadonlySet<string>;
workspaceFilterContext: IssueFilterWorkspaceContext;
showStatusColumn: boolean;
showIdentifierColumn: boolean;
showUpdatedColumn: boolean;
}
const BLOCKED_LIST_LIMIT = 200;
export function BlockedInboxView({
companyId,
searchQuery,
agentNameById,
userLabelById,
issueLinkState,
groupBy,
sortBy,
issueFilters,
currentUserId,
liveIssueIds,
workspaceFilterContext,
showStatusColumn,
showIdentifierColumn,
showUpdatedColumn,
}: BlockedInboxViewProps) {
const [collapsedVariants, setCollapsedVariants] = useState<Set<string>>(() => new Set());
const {
data: issues = [] as Issue[],
isLoading,
isFetching,
error,
refetch,
} = useQuery({
queryKey: queryKeys.issues.listBlockedAttention(companyId),
queryFn: () =>
issuesApi.list(companyId, {
attention: "blocked",
includeBlockedInboxAttention: true,
includeBlockedBy: true,
limit: BLOCKED_LIST_LIMIT,
}),
});
const allRows = useMemo(() => buildBlockedInboxRows(issues), [issues]);
const filteredRows = useMemo(
() => allRows.filter((row) => blockedRowMatchesSearch(row, searchQuery)),
[allRows, searchQuery],
);
const issueFilteredRows = useMemo(() => {
const visibleIssueIds = new Set(
applyIssueFilters(
filteredRows.map((row) => row.issue),
issueFilters,
currentUserId,
true,
liveIssueIds,
workspaceFilterContext,
).map((issue) => issue.id),
);
return filteredRows.filter((row) => visibleIssueIds.has(row.issue.id));
}, [currentUserId, filteredRows, issueFilters, liveIssueIds, workspaceFilterContext]);
const sortedRows = useMemo(() => sortBlockedInboxRows(issueFilteredRows, sortBy), [issueFilteredRows, sortBy]);
const groups = useMemo(
() => groupBlockedInboxRows(issueFilteredRows, sortBy),
[issueFilteredRows, sortBy],
);
const toggleVariant = (variant: string) => {
setCollapsedVariants((prev) => {
const next = new Set(prev);
if (next.has(variant)) next.delete(variant);
else next.add(variant);
return next;
});
};
if (isLoading) {
return (
<div data-testid="blocked-inbox-loading" className="space-y-3" aria-busy="true">
{Array.from({ length: 3 }).map((_, groupIdx) => (
<div key={groupIdx} className="space-y-1">
<div className="h-4 w-40 animate-pulse rounded bg-muted/70" />
{Array.from({ length: 2 }).map((__, rowIdx) => (
<div
key={rowIdx}
className="flex items-center gap-3 border-b border-border/60 px-3 py-2.5 sm:px-4"
>
<div className="h-3.5 w-3.5 animate-pulse rounded-full bg-muted" />
<div className="h-4 w-16 animate-pulse rounded bg-muted/70" />
<div className="h-4 w-32 animate-pulse rounded-md bg-muted/70" />
<div className="h-4 flex-1 animate-pulse rounded bg-muted/60" />
<div className="hidden h-3 w-24 animate-pulse rounded bg-muted/60 sm:block" />
</div>
))}
</div>
))}
</div>
);
}
if (error) {
const message =
error instanceof Error ? error.message : "Couldn't load the Blocked tab.";
return (
<div
data-testid="blocked-inbox-error"
role="alert"
className="flex flex-col gap-2 rounded-md border border-amber-300/70 bg-amber-50/90 p-4 text-amber-900 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-200"
>
<div className="flex items-start gap-2">
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0" aria-hidden="true" />
<div className="flex-1 space-y-1">
<p className="text-sm font-medium">Couldn't load the Blocked tab.</p>
<p className="text-xs opacity-80">
Other Inbox tabs still work. {message}
</p>
</div>
<Button
type="button"
variant="outline"
size="sm"
className="h-7 shrink-0 border-amber-400/70 bg-white/40 text-amber-900 hover:bg-white/70 dark:bg-amber-500/20 dark:text-amber-100"
onClick={() => void refetch()}
disabled={isFetching}
>
{isFetching ? "Trying…" : "Try again"}
</Button>
</div>
</div>
);
}
if (allRows.length === 0) {
return (
<div
data-testid="blocked-inbox-empty"
className="flex flex-col items-center gap-3 rounded-lg border border-border/70 bg-card/40 px-6 py-10 text-center"
>
<span className="inline-flex h-10 w-10 items-center justify-center rounded-full bg-emerald-100 text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-300">
<CheckCircle2 className="h-5 w-5" aria-hidden="true" />
</span>
<div className="space-y-1">
<p className="text-sm font-medium text-foreground">No work is stopped.</p>
<p className="text-xs text-muted-foreground">
Issues that need a decision, recovery, or external action will appear here.
</p>
</div>
</div>
);
}
if (groups.length === 0) {
return (
<div className="space-y-3">
<div
data-testid="blocked-inbox-no-search-results"
className="rounded-lg border border-border/70 bg-card/40 px-4 py-6 text-center text-sm text-muted-foreground"
>
No stopped items match your search.
</div>
</div>
);
}
return (
<div data-testid="blocked-inbox" className="space-y-3">
<div className="overflow-hidden rounded-xl">
{groupBy === "none" ? (
sortedRows.map((row) => (
<BlockedInboxRow
key={row.issue.id}
row={row}
issueLinkState={issueLinkState}
agentNameById={agentNameById}
userLabelById={userLabelById}
showStatusColumn={showStatusColumn}
showIdentifierColumn={showIdentifierColumn}
showUpdatedColumn={showUpdatedColumn}
/>
))
) : (
groups.map((group) => {
const isCollapsed = collapsedVariants.has(group.variant);
return (
<div key={group.variant} data-testid={`blocked-inbox-group-${group.variant}`}>
<div className="px-3 sm:px-4">
<IssueGroupHeader
label={`${group.label} · ${group.rows.length}`}
collapsible
collapsed={isCollapsed}
onToggle={() => toggleVariant(group.variant)}
/>
</div>
{!isCollapsed && (
<div>
{group.rows.map((row) => (
<BlockedInboxRow
key={row.issue.id}
row={row}
issueLinkState={issueLinkState}
agentNameById={agentNameById}
userLabelById={userLabelById}
showStatusColumn={showStatusColumn}
showIdentifierColumn={showIdentifierColumn}
showUpdatedColumn={showUpdatedColumn}
/>
))}
</div>
)}
</div>
);
})
)}
</div>
</div>
);
}
interface BlockedInboxRowProps {
row: BlockedInboxIssueRow;
issueLinkState: unknown;
agentNameById: ReadonlyMap<string, string>;
userLabelById?: ReadonlyMap<string, string>;
showStatusColumn: boolean;
showIdentifierColumn: boolean;
showUpdatedColumn: boolean;
}
function resolveOwnerName(
row: BlockedInboxIssueRow,
agentNameById: ReadonlyMap<string, string>,
userLabelById?: ReadonlyMap<string, string>,
): { label: string | null; isAgent: boolean } {
const owner = row.attention.owner;
if (owner.label) return { label: owner.label, isAgent: owner.type === "agent" };
if (owner.agentId) {
return { label: agentNameById.get(owner.agentId) ?? null, isAgent: true };
}
if (owner.userId) {
return { label: userLabelById?.get(owner.userId) ?? null, isAgent: false };
}
return { label: null, isAgent: false };
}
function BlockedInboxRow({
row,
issueLinkState,
agentNameById,
userLabelById,
showStatusColumn,
showIdentifierColumn,
showUpdatedColumn,
}: BlockedInboxRowProps) {
const { label: ownerName, isAgent } = resolveOwnerName(row, agentNameById, userLabelById);
const stoppedAge = formatStoppedAge(row.attention.stoppedSinceAt);
const desktopTrailing = (
<span className="flex shrink-0 items-center gap-3 text-xs">
<span
className="hidden w-[10.5rem] shrink-0 justify-start sm:inline-flex"
data-testid="blocked-row-reason-column"
>
<BlockedReasonChip
reason={row.attention.reason}
severity={row.attention.severity}
className="max-w-full"
/>
</span>
{ownerName ? (
<span className="hidden w-[150px] min-w-0 items-center text-muted-foreground sm:inline-flex">
<Identity
name={ownerName}
size="xs"
className="max-w-full"
/>
</span>
) : (
<span className="hidden w-[150px] shrink-0 sm:inline-flex" aria-hidden="true" />
)}
{showUpdatedColumn ? (
<span className="hidden w-[5.75rem] text-right text-muted-foreground sm:inline" data-testid="blocked-row-age">
{stoppedAge}
</span>
) : null}
</span>
);
const mobileMeta = (
<span className="flex flex-wrap items-center gap-x-1.5 gap-y-1 text-xs text-muted-foreground">
<span data-testid="blocked-row-age-mobile">{stoppedAge}</span>
{ownerName ? (
<>
<span aria-hidden="true">·</span>
<span
className={cn(isAgent ? "font-medium text-foreground/90" : null)}
data-testid="blocked-row-owner-mobile"
>
{ownerName}
</span>
</>
) : null}
</span>
);
return (
<IssueRow
issue={row.issue}
issueLinkState={issueLinkState}
desktopMetaLeading={
<BlockedRowDesktopMeta
row={row}
showStatusColumn={showStatusColumn}
showIdentifierColumn={showIdentifierColumn}
/>
}
mobileLeading={
<span className="flex shrink-0 items-center gap-1.5 pt-px">
<StatusIcon status={row.issue.status} blockerAttention={row.issue.blockerAttention} />
</span>
}
titleSuffix={
<BlockedReasonChip
reason={row.attention.reason}
severity={row.attention.severity}
className="ml-2 max-w-[12rem] align-middle sm:hidden"
/>
}
mobileMeta={mobileMeta}
desktopTrailing={desktopTrailing}
/>
);
}
function BlockedRowDesktopMeta({
row,
showStatusColumn,
showIdentifierColumn,
}: {
row: BlockedInboxIssueRow;
showStatusColumn: boolean;
showIdentifierColumn: boolean;
}) {
const identifier = row.issue.identifier ?? row.issue.id.slice(0, 8);
return (
<span className="hidden shrink-0 items-center gap-2 sm:inline-flex">
{showStatusColumn ? <StatusIcon status={row.issue.status} blockerAttention={row.issue.blockerAttention} /> : null}
{showIdentifierColumn ? <span className="font-mono text-xs text-muted-foreground">{identifier}</span> : null}
</span>
);
}
@@ -0,0 +1,85 @@
// @vitest-environment jsdom
import { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { BlockedReasonChip } from "./BlockedReasonChip";
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
describe("BlockedReasonChip", () => {
let container: HTMLDivElement;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
});
afterEach(() => {
container.remove();
});
it("renders the canonical group label and exposes severity via aria-label", () => {
const root = createRoot(container);
act(() => {
root.render(
<BlockedReasonChip reason="pending_board_decision" severity="high" />,
);
});
const chip = container.querySelector('[data-testid="blocked-reason-chip"]');
expect(chip).not.toBeNull();
expect(chip?.getAttribute("data-variant")).toBe("needs_decision");
expect(chip?.getAttribute("data-severity")).toBe("high");
expect(chip?.getAttribute("aria-label")).toBe("Reason: Needs decision, severity high");
expect(chip?.textContent).toContain("Needs decision");
act(() => {
root.unmount();
});
});
it("includes a severity dot for critical and high but not medium/low", () => {
const cases: Array<["critical" | "high" | "medium" | "low", boolean]> = [
["critical", true],
["high", true],
["medium", false],
["low", false],
];
for (const [severity, hasDot] of cases) {
const local = document.createElement("div");
document.body.appendChild(local);
const root = createRoot(local);
act(() => {
root.render(<BlockedReasonChip reason="blocked_chain_stalled" severity={severity} />);
});
const chip = local.querySelector('[data-testid="blocked-reason-chip"]');
const dot = chip?.querySelector('[aria-hidden="true"]');
if (hasDot) {
expect(dot).not.toBeNull();
} else {
// The first inner span (icon) is always aria-hidden, but the dot is the first child.
// Distinguish by class name presence of bg-red-500/bg-orange-500.
const classy = chip?.querySelector('span[class*="bg-red-500"], span[class*="bg-orange-500"]');
expect(classy).toBeNull();
}
act(() => {
root.unmount();
});
local.remove();
}
});
it("hides the icon when compact is true", () => {
const root = createRoot(container);
act(() => {
root.render(
<BlockedReasonChip reason="external_owner_action" severity="low" compact />,
);
});
const chip = container.querySelector('[data-testid="blocked-reason-chip"]');
const svg = chip?.querySelector("svg");
expect(svg).toBeNull();
act(() => {
root.unmount();
});
});
});
+82
View File
@@ -0,0 +1,82 @@
import { AlertTriangle, Clock, Pause, User, Wrench } from "lucide-react";
import type { ComponentType } from "react";
import type { IssueBlockedInboxSeverity } from "@paperclipai/shared";
import { cn } from "../lib/utils";
import {
blockedReasonVariant,
blockedVariantLabel,
type BlockedReasonVariant,
} from "../lib/blockedInbox";
import type { IssueBlockedInboxReason } from "@paperclipai/shared";
interface BlockedReasonChipProps {
reason: IssueBlockedInboxReason;
severity: IssueBlockedInboxSeverity;
compact?: boolean;
className?: string;
}
type IconComponent = ComponentType<{ className?: string; "aria-hidden"?: boolean | "true" | "false" }>;
const VARIANT_STYLES: Record<BlockedReasonVariant, string> = {
needs_decision:
"border-violet-300/70 bg-violet-50 text-violet-800 dark:border-violet-500/30 dark:bg-violet-500/10 dark:text-violet-300",
recovery_required:
"border-cyan-300/70 bg-cyan-50 text-cyan-800 dark:border-cyan-500/30 dark:bg-cyan-500/10 dark:text-cyan-300",
stalled:
"border-amber-400/70 bg-amber-100 text-amber-900 dark:border-amber-500/40 dark:bg-amber-500/15 dark:text-amber-200",
needs_attention:
"border-amber-300/70 bg-amber-50 text-amber-800 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-300",
external_wait:
"border-slate-300 bg-slate-50 text-slate-700 dark:border-slate-500/30 dark:bg-slate-500/15 dark:text-slate-300",
owner_paused:
"border-red-300/70 bg-red-50 text-red-800 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-300",
};
const VARIANT_ICONS: Record<BlockedReasonVariant, IconComponent> = {
needs_decision: Clock,
recovery_required: Wrench,
stalled: AlertTriangle,
needs_attention: AlertTriangle,
external_wait: User,
owner_paused: Pause,
};
const SEVERITY_DOT: Partial<Record<IssueBlockedInboxSeverity, string>> = {
critical: "bg-red-500",
high: "bg-orange-500",
};
export function BlockedReasonChip({
reason,
severity,
compact = false,
className,
}: BlockedReasonChipProps) {
const variant = blockedReasonVariant(reason);
const label = blockedVariantLabel(variant);
const Icon = VARIANT_ICONS[variant];
const dotClass = SEVERITY_DOT[severity];
return (
<span
data-testid="blocked-reason-chip"
data-variant={variant}
data-severity={severity}
aria-label={`Reason: ${label}, severity ${severity}`}
className={cn(
"inline-flex shrink-0 items-center gap-1 rounded-md border px-2 py-0.5 text-[10px] font-medium leading-tight sm:text-[11px]",
VARIANT_STYLES[variant],
className,
)}
>
{dotClass ? (
<span
aria-hidden="true"
className={cn("inline-block h-1.5 w-1.5 shrink-0 rounded-full", dotClass)}
/>
) : null}
{compact ? null : <Icon className="h-3 w-3 shrink-0" aria-hidden="true" />}
<span className="truncate">{label}</span>
</span>
);
}
+67 -2
View File
@@ -2,8 +2,10 @@
import { act } from "react";
import { createRoot } from "react-dom/client";
import type { AnchorHTMLAttributes, ReactElement } from "react";
import type { AnchorHTMLAttributes, ReactElement, ReactNode } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { MemoryRouter } from "react-router-dom";
import { IssueBlockedNotice } from "./IssueBlockedNotice";
vi.mock("@/lib/router", () => ({
@@ -27,11 +29,20 @@ afterEach(() => {
container = null;
});
function withProviders(node: ReactNode) {
const client = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 0, staleTime: 0 } } });
return (
<MemoryRouter>
<QueryClientProvider client={client}>{node}</QueryClientProvider>
</MemoryRouter>
);
}
function render(element: ReactElement) {
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
act(() => root?.render(element));
act(() => root?.render(withProviders(element)));
return container;
}
@@ -102,4 +113,58 @@ describe("IssueBlockedNotice", () => {
expect(node.textContent).toBe("");
});
it("renders a recovery indicator on a blocker chip when the blocker has an active recovery action", () => {
const node = render(
<IssueBlockedNotice
issueStatus="blocked"
blockers={[
{
id: "blocker-1",
identifier: "PAP-123",
title: "Build still red",
status: "in_progress",
priority: "medium",
assigneeAgentId: null,
assigneeUserId: null,
activeRecoveryAction: {
id: "rec-1",
companyId: "co-1",
sourceIssueId: "blocker-1",
recoveryIssueId: null,
kind: "missing_disposition",
status: "active",
ownerType: "agent",
ownerAgentId: "agent-cto",
ownerUserId: null,
previousOwnerAgentId: null,
returnOwnerAgentId: null,
cause: "successful_run_missing_state",
fingerprint: "fp-1",
evidence: {},
nextAction: "choose disposition",
wakePolicy: { type: "wake_owner" },
monitorPolicy: null,
attemptCount: 1,
maxAttempts: 3,
timeoutAt: null,
lastAttemptAt: null,
outcome: null,
resolutionNote: null,
resolvedAt: null,
createdAt: "2026-05-01T00:00:00.000Z",
updatedAt: "2026-05-01T00:00:00.000Z",
},
},
]}
/>,
);
const indicator = node.querySelector(
'[data-testid="issue-blocked-notice-recovery-indicator"]',
);
expect(indicator).not.toBeNull();
expect(indicator?.getAttribute("data-recovery-state")).toBe("needed");
expect(indicator?.textContent).toContain("Recovery needed");
});
});
+32 -1
View File
@@ -1,9 +1,38 @@
import type { IssueBlockerAttention, IssueRelationIssueSummary, SuccessfulRunHandoffState } from "@paperclipai/shared";
import type {
IssueBlockerAttention,
IssueRecoveryAction,
IssueRelationIssueSummary,
SuccessfulRunHandoffState,
} from "@paperclipai/shared";
import { AlertTriangle, Flag } from "lucide-react";
import { Link } from "@/lib/router";
import { createIssueDetailPath } from "../lib/issueDetailBreadcrumb";
import { IssueLinkQuicklook } from "./IssueLinkQuicklook";
import { isAssignedBacklogBlocker } from "../lib/issue-blockers";
import {
deriveActiveRecoveryDisplayState,
RECOVERY_CHIP_DEFAULT_TONE,
} from "../lib/recovery-display";
function BlockerRecoveryIndicator({ action }: { action: IssueRecoveryAction }) {
const state = deriveActiveRecoveryDisplayState(action);
if (!state) return null;
const tone = RECOVERY_CHIP_DEFAULT_TONE[state];
const Icon = tone.icon;
return (
<span
data-testid="issue-blocked-notice-recovery-indicator"
data-recovery-state={state}
role="status"
aria-label={tone.label}
title={`${tone.label} — open the source issue to act.`}
className={`inline-flex shrink-0 items-center gap-0.5 rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${tone.className}`}
>
<Icon className="h-2.5 w-2.5" aria-hidden />
{tone.label}
</span>
);
}
export function IssueBlockedNotice({
issueStatus,
@@ -69,6 +98,7 @@ export function IssueBlockedNotice({
const renderBlockerChip = (blocker: IssueRelationIssueSummary) => {
const issuePathId = blocker.identifier ?? blocker.id;
const recoveryAction = blocker.activeRecoveryAction ?? null;
return (
<IssueLinkQuicklook
key={blocker.id}
@@ -80,6 +110,7 @@ export function IssueBlockedNotice({
<span className="max-w-[18rem] truncate font-sans text-[11px] text-amber-800 dark:text-amber-200">
{blocker.title}
</span>
{recoveryAction ? <BlockerRecoveryIndicator action={recoveryAction} /> : null}
</IssueLinkQuicklook>
);
};
@@ -346,6 +346,39 @@ describe("IssueChatThread", () => {
});
});
it("renders footer content inside the thread viewport before the bottom anchor", () => {
const root = createRoot(container);
act(() => {
root.render(
<MemoryRouter>
<IssueChatThread
comments={[]}
linkedRuns={[]}
timelineEvents={[]}
liveRuns={[]}
onAdd={async () => {}}
showComposer={false}
enableLiveTranscriptPolling={false}
footer={<div>Sibling footer</div>}
/>
</MemoryRouter>,
);
});
const viewport = container.querySelector('[data-testid="thread-viewport"]');
const footer = container.querySelector('[data-testid="issue-chat-thread-footer"]');
expect(viewport).not.toBeNull();
expect(footer).not.toBeNull();
expect(footer?.textContent).toBe("Sibling footer");
expect(footer?.parentElement).toBe(viewport);
expect(footer?.nextElementSibling?.textContent).toBe("");
act(() => {
root.unmount();
});
});
it("renders the composer in planning mode when the issue is in planning mode", () => {
const root = createRoot(container);
+56 -1
View File
@@ -36,6 +36,7 @@ import type {
FeedbackVoteValue,
IssueAttachment,
IssueBlockerAttention,
IssueRecoveryAction,
IssueRelationIssueSummary,
SuccessfulRunHandoffState,
IssueWorkMode,
@@ -134,6 +135,7 @@ import { Textarea } from "@/components/ui/textarea";
import { AlertTriangle, ArrowRight, Brain, Check, ChevronDown, ClipboardList, Copy, Hammer, Loader2, MoreHorizontal, Paperclip, PauseCircle, Search, Square, ThumbsDown, ThumbsUp } from "lucide-react";
import { IssueBlockedNotice } from "./IssueBlockedNotice";
import { IssueAssignedBacklogNotice } from "./IssueAssignedBacklogNotice";
import { IssueRecoveryActionCard, type RecoveryResolveOutcome } from "./IssueRecoveryActionCard";
interface IssueChatMessageContext {
feedbackDataSharingPreference: FeedbackDataSharingPreference;
@@ -297,6 +299,14 @@ interface IssueChatThreadProps {
blockedBy?: IssueRelationIssueSummary[];
blockerAttention?: IssueBlockerAttention | null;
successfulRunHandoff?: SuccessfulRunHandoffState | null;
recoveryAction?: IssueRecoveryAction | null;
onResolveRecoveryAction?: (outcome: RecoveryResolveOutcome) => void;
canFalsePositiveRecoveryAction?: boolean;
legacyRecoverySourceIssue?: {
identifier: string | null;
href: string;
title?: string | null;
} | null;
assigneeUserId?: string | null;
onResumeFromBacklog?: () => Promise<void> | void;
resumeFromBacklogPending?: boolean;
@@ -332,6 +342,7 @@ interface IssueChatThreadProps {
showComposer?: boolean;
showJumpToLatest?: boolean;
emptyMessage?: string;
footer?: ReactNode;
variant?: "full" | "embedded";
enableLiveTranscriptPolling?: boolean;
transcriptsByRunId?: ReadonlyMap<string, readonly IssueChatTranscriptEntry[]>;
@@ -3609,6 +3620,10 @@ export function IssueChatThread({
blockedBy = [],
blockerAttention = null,
successfulRunHandoff = null,
recoveryAction = null,
onResolveRecoveryAction,
canFalsePositiveRecoveryAction = false,
legacyRecoverySourceIssue = null,
companyId,
projectId,
issueStatus,
@@ -3636,6 +3651,7 @@ export function IssueChatThread({
showComposer = true,
showJumpToLatest,
emptyMessage,
footer,
variant = "full",
enableLiveTranscriptPolling = true,
transcriptsByRunId,
@@ -4244,11 +4260,49 @@ export function IssueChatThread({
onResume={onResumeFromBacklog}
resuming={resumeFromBacklogPending}
/>
{recoveryAction ? (
<IssueRecoveryActionCard
action={recoveryAction}
agentMap={agentMap}
onResolve={onResolveRecoveryAction}
canFalsePositive={canFalsePositiveRecoveryAction}
/>
) : null}
{legacyRecoverySourceIssue ? (
<SystemNotice
tone="info"
label="Legacy recovery issue"
body={
<span>
Legacy recovery issue. Newer recovery actions live on the source issue
{legacyRecoverySourceIssue.identifier ? (
<>
{" "}
<Link
to={legacyRecoverySourceIssue.href}
className="underline-offset-2 hover:underline"
>
{legacyRecoverySourceIssue.identifier}
{legacyRecoverySourceIssue.title ? (
<span className="text-muted-foreground">
{" "}
— {legacyRecoverySourceIssue.title}
</span>
) : null}
</Link>
</>
) : (
"."
)}
</span>
}
/>
) : null}
<IssueBlockedNotice
issueStatus={issueStatus}
blockers={unresolvedBlockers}
blockerAttention={blockerAttention}
successfulRunHandoff={successfulRunHandoff}
successfulRunHandoff={recoveryAction ? null : successfulRunHandoff}
agentName={
successfulRunHandoff?.assigneeAgentId
? agentMap?.get(successfulRunHandoff.assigneeAgentId)?.name ?? null
@@ -4258,6 +4312,7 @@ export function IssueChatThread({
<IssueAssigneePausedNotice agent={assignedAgent} />
</div>
) : null}
{footer ? <div data-testid="issue-chat-thread-footer">{footer}</div> : null}
<div ref={bottomAnchorRef} />
{showComposer ? (
<div
@@ -0,0 +1,136 @@
// @vitest-environment jsdom
import { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { MemoryRouter } from "react-router-dom";
import type { Issue } from "@paperclipai/shared";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { IssueLinkQuicklook } from "./IssueLinkQuicklook";
const mockIssuesApiGet = vi.hoisted(() => vi.fn());
vi.mock("@/api/issues", () => ({
issuesApi: {
get: mockIssuesApiGet,
},
}));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
function createIssue(overrides: Partial<Issue> = {}): Issue {
return {
id: "issue-1",
identifier: "PAP-1",
companyId: "company-1",
projectId: null,
projectWorkspaceId: null,
goalId: null,
parentId: null,
title: "Quicklook title",
description: "Quicklook description",
status: "todo",
priority: "medium",
assigneeAgentId: null,
assigneeUserId: null,
createdByAgentId: null,
createdByUserId: null,
issueNumber: 1,
requestDepth: 0,
billingCode: null,
assigneeAdapterOverrides: null,
executionWorkspaceId: null,
executionWorkspacePreference: null,
executionWorkspaceSettings: null,
checkoutRunId: null,
executionRunId: null,
executionAgentNameKey: null,
executionLockedAt: null,
startedAt: null,
completedAt: null,
cancelledAt: null,
hiddenAt: null,
createdAt: new Date("2026-05-01T00:00:00.000Z"),
updatedAt: new Date("2026-05-01T00:00:00.000Z"),
labels: [],
labelIds: [],
myLastTouchAt: null,
lastExternalCommentAt: null,
isUnreadForMe: false,
workMode: "standard",
...overrides,
};
}
describe("IssueLinkQuicklook", () => {
let container: HTMLDivElement;
let root: Root;
let queryClient: QueryClient;
beforeEach(() => {
vi.useFakeTimers();
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
});
mockIssuesApiGet.mockResolvedValue(createIssue());
});
afterEach(() => {
act(() => {
root.unmount();
});
queryClient.clear();
container.remove();
vi.useRealTimers();
vi.clearAllMocks();
});
it("keeps portaled quicklook links mounted until after blur click handling", () => {
const issue = createIssue();
act(() => {
root.render(
<QueryClientProvider client={queryClient}>
<MemoryRouter>
<IssueLinkQuicklook
issuePathId="PAP-1"
issuePrefetch={issue}
to="/companies/company-1/issues/PAP-1"
>
PAP-1
</IssueLinkQuicklook>
</MemoryRouter>
</QueryClientProvider>,
);
});
const trigger = container.querySelector("a") as HTMLAnchorElement | null;
expect(trigger).not.toBeNull();
act(() => {
trigger?.focus();
});
expect(document.body.textContent).toContain("Quicklook title");
act(() => {
trigger?.blur();
});
expect(document.body.textContent).toContain("Quicklook title");
act(() => {
vi.runOnlyPendingTimers();
});
expect(document.body.textContent).not.toContain("Quicklook title");
});
});
+13 -2
View File
@@ -75,6 +75,8 @@ export const IssueLinkQuicklook = React.forwardRef<
issuePathId: string;
disableIssueQuicklook?: boolean;
issuePrefetch?: Issue | null;
issueQuicklookSide?: React.ComponentProps<typeof PopoverContent>["side"];
issueQuicklookAlign?: React.ComponentProps<typeof PopoverContent>["align"];
}
>(function IssueLinkQuicklookImpl(
{
@@ -85,10 +87,13 @@ export const IssueLinkQuicklook = React.forwardRef<
state,
disableIssueQuicklook = false,
issuePrefetch = null,
issueQuicklookSide = "top",
issueQuicklookAlign = "start",
onClick,
onClickCapture,
onMouseEnter,
onFocus,
onBlur,
onTouchStart,
...props
},
@@ -119,8 +124,14 @@ export const IssueLinkQuicklook = React.forwardRef<
}}
onFocus={(event) => {
handlePrefetch();
setOpen(true);
onFocus?.(event);
}}
onBlur={(event) => {
// Let clicks inside the portaled quicklook content finish before closing.
setTimeout(() => setOpen(false), 0);
onBlur?.(event);
}}
onTouchStart={(event) => {
handlePrefetch();
onTouchStart?.(event);
@@ -157,8 +168,8 @@ export const IssueLinkQuicklook = React.forwardRef<
</PopoverTrigger>
<PopoverContent
className="w-72 p-3"
side="top"
align="start"
side={issueQuicklookSide}
align={issueQuicklookAlign}
onMouseEnter={() => setOpen(true)}
onMouseLeave={() => setOpen(false)}
onOpenAutoFocus={(event) => event.preventDefault()}
@@ -0,0 +1,218 @@
// @vitest-environment jsdom
import { act } from "react";
import { createRoot } from "react-dom/client";
import type { AnchorHTMLAttributes, ReactElement } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { Agent, IssueRecoveryAction } from "@paperclipai/shared";
import { IssueRecoveryActionCard, deriveRecoveryCardState } from "./IssueRecoveryActionCard";
vi.mock("@/lib/router", () => ({
Link: ({ children, to, ...props }: AnchorHTMLAttributes<HTMLAnchorElement> & { to: string }) => (
<a href={to} {...props}>{children}</a>
),
}));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
let root: ReturnType<typeof createRoot> | null = null;
let container: HTMLDivElement | null = null;
afterEach(() => {
if (root) {
act(() => root?.unmount());
}
root = null;
container?.remove();
container = null;
});
function render(element: ReactElement) {
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
act(() => root?.render(element));
return container;
}
function click(element: Element | null) {
if (!element) throw new Error("Expected element to exist");
act(() => {
element.dispatchEvent(new MouseEvent("click", { bubbles: true }));
});
}
const ownerAgent: Agent = {
id: "11111111-1111-1111-1111-111111111111",
companyId: "company-1",
name: "ClaudeCoder",
role: "engineer",
status: "idle",
adapterType: "claude_local",
adapterConfig: {},
runtimeConfig: {},
permissions: {},
urlKey: "claudecoder",
} as unknown as Agent;
const returnAgent: Agent = {
...ownerAgent,
id: "22222222-2222-2222-2222-222222222222",
name: "CodexCoder",
urlKey: "codexcoder",
} as Agent;
function buildAction(overrides: Partial<IssueRecoveryAction> = {}): IssueRecoveryAction {
return {
id: "00000000-0000-0000-0000-0000000000aa",
companyId: "company-1",
sourceIssueId: "00000000-0000-0000-0000-0000000000ff",
recoveryIssueId: null,
kind: "missing_disposition",
status: "active",
ownerType: "agent",
ownerAgentId: ownerAgent.id,
ownerUserId: null,
previousOwnerAgentId: returnAgent.id,
returnOwnerAgentId: returnAgent.id,
cause: "missing_disposition",
fingerprint: "fp",
evidence: {
summary: "Run finished but no disposition was chosen.",
sourceRunId: "7accd7a4-c9ca-4db2-9233-3228a037cc09",
},
nextAction: "Choose and record a valid issue disposition.",
wakePolicy: { type: "wake_owner" },
monitorPolicy: null,
attemptCount: 1,
maxAttempts: 3,
timeoutAt: null,
lastAttemptAt: "2026-05-09T19:30:00.000Z",
outcome: null,
resolutionNote: null,
resolvedAt: null,
createdAt: "2026-05-09T19:30:00.000Z",
updatedAt: "2026-05-09T19:30:00.000Z",
...overrides,
};
}
describe("deriveRecoveryCardState", () => {
it("maps active missing_disposition to needed", () => {
expect(deriveRecoveryCardState(buildAction())).toBe("needed");
});
it("maps active_run_watchdog to observe_only", () => {
expect(deriveRecoveryCardState(buildAction({ kind: "active_run_watchdog" }))).toBe("observe_only");
});
it("maps escalated status to escalated", () => {
expect(deriveRecoveryCardState(buildAction({ status: "escalated" }))).toBe("escalated");
});
it("maps resolved/cancelled to resolved", () => {
expect(deriveRecoveryCardState(buildAction({ status: "resolved" }))).toBe("resolved");
expect(deriveRecoveryCardState(buildAction({ status: "cancelled" }))).toBe("resolved");
});
});
describe("IssueRecoveryActionCard", () => {
it("renders required fields and an aria-label naming the state", () => {
const node = render(
<IssueRecoveryActionCard
action={buildAction()}
agentMap={new Map([
[ownerAgent.id, ownerAgent],
[returnAgent.id, returnAgent],
])}
onResolve={() => {}}
/>,
);
const section = node.querySelector("section[aria-label]");
expect(section?.getAttribute("aria-label")).toBe("Recovery action: needed");
expect(node.textContent).toContain("RECOVERY NEEDED");
expect(node.textContent).toContain("Missing Disposition");
expect(node.textContent).not.toContain("missing_disposition");
expect(node.textContent).toContain("This issue's run finished, but no next step was chosen.");
expect(node.textContent).toContain("ClaudeCoder");
expect(node.textContent).toContain("CodexCoder");
expect(node.textContent).toContain("Choose and record a valid issue disposition.");
expect(node.textContent).toContain("Corrective wake queued");
});
it("falls back to em dash when wake policy is absent", () => {
const node = render(
<IssueRecoveryActionCard action={buildAction({ wakePolicy: null })} />,
);
expect(node.textContent).toContain("—");
});
it("renders observe_only tone for active_run_watchdog", () => {
const node = render(
<IssueRecoveryActionCard action={buildAction({ kind: "active_run_watchdog" })} />,
);
const section = node.querySelector("section[aria-label]");
expect(section?.getAttribute("aria-label")).toBe("Recovery action: observing active run");
expect(node.textContent).toContain("OBSERVING ACTIVE RUN");
});
it("renders the resolved label and outcome when resolved", () => {
const node = render(
<IssueRecoveryActionCard action={buildAction({ status: "resolved", outcome: "restored", resolvedAt: "2026-05-09T19:35:00.000Z" })} />,
);
expect(node.textContent).toContain("RECOVERY RESOLVED");
expect(node.textContent).toContain("Resolved as restored");
});
it("calls resolve with done and does not offer delegated recovery", () => {
const onResolve = vi.fn();
const node = render(
<IssueRecoveryActionCard action={buildAction()} onResolve={onResolve} />,
);
click(node.querySelector("[data-testid='recovery-action-resolve-trigger']"));
expect(document.body.textContent).toContain("Mark issue done");
expect(document.body.textContent).not.toContain("Mark blocked");
expect(document.body.textContent).not.toContain("Delegate follow-up issue");
click([...document.body.querySelectorAll("button")].find((button) => button.textContent?.includes("Mark issue done")) ?? null);
expect(onResolve).toHaveBeenCalledWith("done");
});
it("does not offer blocked recovery resolution without a blocker selection flow", () => {
const node = render(
<IssueRecoveryActionCard action={buildAction()} onResolve={() => {}} canFalsePositive />,
);
click(node.querySelector("[data-testid='recovery-action-resolve-trigger']"));
expect(document.body.textContent).toContain("Mark issue done");
expect(document.body.textContent).toContain("Send for review");
expect(document.body.textContent).toContain("False positive, done");
expect(document.body.textContent).toContain("False positive, review");
expect(document.body.textContent).not.toContain("Mark blocked");
});
it("hides false-positive options unless canFalsePositive is set", () => {
const first = render(
<IssueRecoveryActionCard action={buildAction()} onResolve={() => {}} />,
);
click(first.querySelector("[data-testid='recovery-action-resolve-trigger']"));
expect(document.body.textContent).not.toContain("False positive");
act(() => root?.unmount());
root = null;
container?.remove();
container = null;
const onResolve = vi.fn();
const second = render(
<IssueRecoveryActionCard action={buildAction()} onResolve={onResolve} canFalsePositive />,
);
click(second.querySelector("[data-testid='recovery-action-resolve-trigger']"));
expect(document.body.textContent).toContain("False positive, done");
expect(document.body.textContent).toContain("False positive, review");
click([...document.body.querySelectorAll("button")].find((button) => button.textContent?.includes("False positive, done")) ?? null);
expect(onResolve).toHaveBeenCalledWith("false_positive_done");
});
});
@@ -0,0 +1,537 @@
import { useMemo } from "react";
import type {
Agent,
IssueRecoveryAction,
IssueRecoveryActionKind,
IssueRecoveryActionOutcome,
IssueRecoveryActionStatus,
} from "@paperclipai/shared";
import { Eye, OctagonAlert, RefreshCw, Sparkles, TriangleAlert } from "lucide-react";
import { Link } from "@/lib/router";
import { Button } from "@/components/ui/button";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { agentUrl } from "@/lib/utils";
import { cn } from "@/lib/utils";
import {
deriveRecoveryDisplayState,
type RecoveryDisplayState,
} from "@/lib/recovery-display";
export type RecoveryCardCardState = RecoveryDisplayState;
export const deriveRecoveryCardState = deriveRecoveryDisplayState;
export type RecoveryResolveOutcome =
| "done"
| "in_review"
| "false_positive_done"
| "false_positive_in_review";
export interface IssueRecoveryActionCardProps {
action: IssueRecoveryAction;
agentMap?: ReadonlyMap<string, Agent>;
/** Preferred state hint (e.g. observe_only when watchdog tone is requested). Falls back to derived state. */
forcedState?: RecoveryCardCardState;
/** Optional click handler for resolve menu actions. If omitted, the buttons are not rendered. */
onResolve?: (outcome: RecoveryResolveOutcome) => void;
/** Whether the viewer can run destructive board-only actions (e.g. false-positive dismissal). */
canFalsePositive?: boolean;
className?: string;
}
const KIND_LABEL: Record<IssueRecoveryActionKind, string> = {
missing_disposition: "Missing Disposition",
stranded_assigned_issue: "Stranded Issue",
active_run_watchdog: "Active Watchdog",
issue_graph_liveness: "Graph Liveness",
};
const KIND_HEADLINE: Record<IssueRecoveryActionKind, string> = {
missing_disposition: "This issue's run finished, but no next step was chosen.",
stranded_assigned_issue:
"Paperclip retried this issue's last run and it still has no live execution path.",
active_run_watchdog:
"The active run has been silent. Recovery is observing without interrupting it.",
issue_graph_liveness:
"Paperclip detected this issue lost a live action path. A recovery owner needs to act.",
};
const STATE_TONE: Record<RecoveryCardCardState, {
label: string;
containerClass: string;
iconWrapClass: string;
iconClass: string;
labelClass: string;
Icon: typeof TriangleAlert;
divider: string;
}> = {
needed: {
label: "RECOVERY NEEDED",
containerClass:
"border-amber-300/70 bg-amber-50/85 text-amber-950 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-100",
iconWrapClass: "bg-amber-100 text-amber-800 dark:bg-amber-500/20 dark:text-amber-200",
iconClass: "text-amber-700 dark:text-amber-300",
labelClass: "text-amber-900 dark:text-amber-200",
Icon: TriangleAlert,
divider: "border-amber-300/60 dark:border-amber-500/30",
},
in_progress: {
label: "RECOVERY IN PROGRESS",
containerClass:
"border-sky-300/70 bg-sky-50/80 text-sky-950 dark:border-sky-500/40 dark:bg-sky-500/10 dark:text-sky-100",
iconWrapClass: "bg-sky-100 text-sky-800 dark:bg-sky-500/20 dark:text-sky-200",
iconClass: "text-sky-700 dark:text-sky-300",
labelClass: "text-sky-900 dark:text-sky-200",
Icon: RefreshCw,
divider: "border-sky-300/60 dark:border-sky-500/30",
},
observe_only: {
label: "OBSERVING ACTIVE RUN",
containerClass:
"border-border bg-muted/40 text-foreground dark:bg-muted/20",
iconWrapClass: "bg-muted text-foreground/70",
iconClass: "text-muted-foreground",
labelClass: "text-muted-foreground",
Icon: Eye,
divider: "border-border/70",
},
escalated: {
label: "RECOVERY ESCALATED",
containerClass:
"border-red-400/60 bg-red-50/85 text-red-950 dark:border-red-500/40 dark:bg-red-500/10 dark:text-red-100",
iconWrapClass: "bg-red-100 text-red-800 dark:bg-red-500/20 dark:text-red-200",
iconClass: "text-red-700 dark:text-red-300",
labelClass: "text-red-900 dark:text-red-200",
Icon: OctagonAlert,
divider: "border-red-400/50 dark:border-red-500/30",
},
resolved: {
label: "RECOVERY RESOLVED",
containerClass:
"border-emerald-300/70 bg-emerald-50/80 text-emerald-950 dark:border-emerald-500/40 dark:bg-emerald-500/10 dark:text-emerald-100",
iconWrapClass: "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/20 dark:text-emerald-200",
iconClass: "text-emerald-700 dark:text-emerald-300",
labelClass: "text-emerald-900 dark:text-emerald-200",
Icon: Sparkles,
divider: "border-emerald-300/60 dark:border-emerald-500/30",
},
};
const OUTCOME_LABEL: Record<IssueRecoveryActionOutcome, string> = {
restored: "restored",
delegated: "delegated to follow-up",
false_positive: "false positive",
blocked: "blocked",
escalated: "escalated",
cancelled: "cancelled",
};
function readEvidenceString(value: unknown): string | null {
if (typeof value !== "string") return null;
const trimmed = value.trim();
if (!trimmed) return null;
return trimmed.length > 240 ? `${trimmed.slice(0, 237)}` : trimmed;
}
function pickEvidenceSummary(action: IssueRecoveryAction): string | null {
const evidence = action.evidence ?? {};
const candidates = [
"summary",
"detectedProgressSummary",
"missingDisposition",
"retryReason",
"latestRunErrorCode",
"latestRunStatus",
"latestIssueStatus",
] as const;
for (const key of candidates) {
const next = readEvidenceString(evidence[key]);
if (next) return next;
}
return null;
}
function readEvidenceRunId(action: IssueRecoveryAction, key: "sourceRunId" | "correctiveRunId" | "latestRunId") {
const evidence = action.evidence ?? {};
const next = readEvidenceString(evidence[key]);
return next;
}
function readWakePolicySummary(action: IssueRecoveryAction): string | null {
const policy = action.wakePolicy;
if (!policy) return null;
const type = readEvidenceString(policy.type);
if (!type) return null;
if (type === "wake_owner") return "Corrective wake queued";
if (type === "board_escalation") return "Escalated to board";
if (type === "manual") return "Manual";
if (type === "monitor") {
const interval = readEvidenceString(policy.intervalLabel);
return interval ? `Monitor scheduled · ${interval}` : "Monitor scheduled";
}
return type.replaceAll("_", " ");
}
function formatTimeShort(value: string | Date | null | undefined): string | null {
if (!value) return null;
try {
const date = value instanceof Date ? value : new Date(value);
if (Number.isNaN(date.getTime())) return null;
const now = Date.now();
const diffMs = date.getTime() - now;
const absMin = Math.round(Math.abs(diffMs) / 60_000);
if (absMin < 60) {
return diffMs >= 0 ? `in ${absMin}m` : `${absMin}m ago`;
}
return date.toLocaleString(undefined, {
month: "short",
day: "numeric",
hour: "numeric",
minute: "2-digit",
});
} catch {
return null;
}
}
function shortenRunId(runId: string | null | undefined) {
if (!runId) return null;
if (runId.length <= 12) return runId;
return runId.slice(0, 8);
}
function MetadataRow({
label,
children,
}: {
label: string;
children: React.ReactNode;
}) {
return (
<div className="grid grid-cols-[7.5rem_1fr] gap-x-3 gap-y-0 px-3 py-1.5 text-xs sm:px-4">
<dt className="truncate text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground">
{label}
</dt>
<dd className="min-w-0 break-words text-foreground/90">{children}</dd>
</div>
);
}
function MissingValue() {
return <span className="text-muted-foreground"></span>;
}
function AgentLink({
agentId,
agentMap,
fallback,
}: {
agentId: string | null | undefined;
agentMap?: ReadonlyMap<string, Agent>;
fallback?: string | null;
}) {
if (!agentId) {
return fallback ? <span>{fallback}</span> : <MissingValue />;
}
const agent = agentMap?.get(agentId);
const label = agent?.name ?? `agent ${agentId.slice(0, 8)}`;
if (agent) {
return (
<Link
to={agentUrl(agent)}
className="rounded-sm font-medium underline-offset-2 hover:underline"
>
{label}
</Link>
);
}
return <span className="font-medium">{label}</span>;
}
function RunChip({
runId,
agentId,
status,
}: {
runId: string | null;
agentId: string | null | undefined;
status?: string | null;
}) {
if (!runId) return <MissingValue />;
const short = shortenRunId(runId);
const inner = (
<>
<code className="rounded bg-background/80 px-1.5 py-0.5 font-mono text-[11px] text-foreground/80">
run {short}
</code>
{status ? (
<span className="font-sans text-[11px] text-muted-foreground">{status}</span>
) : null}
</>
);
if (agentId) {
return (
<Link
to={`/agents/${agentId}/runs/${runId}`}
className="inline-flex items-center gap-2 rounded-sm underline-offset-2 hover:underline"
>
{inner}
</Link>
);
}
return <span className="inline-flex items-center gap-2">{inner}</span>;
}
const RESOLVE_OPTIONS: Array<{
outcome: RecoveryResolveOutcome;
label: string;
description: string;
destructive?: boolean;
boardOnly?: boolean;
}> = [
{
outcome: "done",
label: "Mark issue done",
description: "Restore by recording the requested work as complete.",
},
{
outcome: "in_review",
label: "Send for review",
description: "Hand off to a reviewer with a real review path.",
},
{
outcome: "false_positive_done",
label: "False positive, done",
description: "Dismiss recovery and mark the source issue complete.",
destructive: true,
boardOnly: true,
},
{
outcome: "false_positive_in_review",
label: "False positive, review",
description: "Dismiss recovery and send the source issue for review.",
destructive: true,
boardOnly: true,
},
];
export function IssueRecoveryActionCard({
action,
agentMap,
forcedState,
onResolve,
canFalsePositive = false,
className,
}: IssueRecoveryActionCardProps) {
const cardState: RecoveryCardCardState = forcedState ?? deriveRecoveryCardState(action);
const tone = STATE_TONE[cardState];
const ToneIcon = tone.Icon;
const headline = useMemo(() => {
if (cardState === "resolved" && action.outcome) {
return `Recovery resolved as ${OUTCOME_LABEL[action.outcome] ?? action.outcome}.`;
}
return KIND_HEADLINE[action.kind] ?? KIND_HEADLINE.missing_disposition;
}, [action.kind, action.outcome, cardState]);
const wakeSummary = readWakePolicySummary(action);
const evidenceSummary = pickEvidenceSummary(action);
const sourceRunId = readEvidenceRunId(action, "sourceRunId") ?? readEvidenceRunId(action, "latestRunId");
const correctiveRunId = readEvidenceRunId(action, "correctiveRunId");
const showAttempt = action.attemptCount > 1 && action.maxAttempts !== null;
const showTimeoutInline = (() => {
if (!action.timeoutAt) return false;
try {
const date = action.timeoutAt instanceof Date ? action.timeoutAt : new Date(action.timeoutAt);
const diffMs = date.getTime() - Date.now();
return diffMs > 0 && diffMs < 60 * 60 * 1000;
} catch {
return false;
}
})();
const updatedAtLabel = formatTimeShort(action.updatedAt);
const ariaState = ({
needed: "needed",
in_progress: "in progress",
observe_only: "observing active run",
escalated: "escalated",
resolved: "resolved",
} satisfies Record<RecoveryCardCardState, string>)[cardState];
const showResolveActions = onResolve !== undefined && cardState !== "resolved";
const visibleResolveOptions = RESOLVE_OPTIONS.filter((option) => {
if (option.boardOnly && !canFalsePositive) return false;
return true;
});
return (
<section
role="status"
aria-label={`Recovery action: ${ariaState}`}
data-recovery-state={cardState}
data-recovery-kind={action.kind}
className={cn(
"relative w-full overflow-hidden rounded-lg border text-sm shadow-[0_1px_0_rgba(15,23,42,0.02)]",
tone.containerClass,
className,
)}
>
<header className="flex items-start gap-3 px-3 py-2.5 sm:px-4">
<span
className={cn(
"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-md",
tone.iconWrapClass,
)}
aria-hidden
>
<ToneIcon className={cn("h-4 w-4", tone.iconClass)} />
</span>
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] font-semibold uppercase tracking-[0.14em]">
<span className={tone.labelClass}>{tone.label}</span>
<span className="text-muted-foreground/60" aria-hidden>·</span>
<code className="rounded bg-background/70 px-1.5 py-0.5 font-mono text-[11px] tracking-normal text-muted-foreground">
{KIND_LABEL[action.kind] ?? action.kind}
</code>
{updatedAtLabel ? (
<>
<span className="text-muted-foreground/60" aria-hidden>·</span>
<span className="font-medium normal-case tracking-normal text-muted-foreground">
{updatedAtLabel}
</span>
</>
) : null}
</div>
<p className="mt-1 text-[14px] leading-6">{headline}</p>
</div>
</header>
<dl className={cn("border-t bg-background/40 dark:bg-background/20", tone.divider)}>
<MetadataRow label="Owner">
<span className="inline-flex flex-wrap items-center gap-1.5">
{action.ownerType === "agent" && action.ownerAgentId ? (
<>
<span className="text-muted-foreground">Recovery:</span>
<AgentLink agentId={action.ownerAgentId} agentMap={agentMap} />
</>
) : action.ownerType === "board" ? (
<span className="font-medium">Board</span>
) : action.ownerType === "user" && action.ownerUserId ? (
<span className="font-medium">user {action.ownerUserId.slice(0, 6)}</span>
) : action.ownerType === "system" ? (
<span className="font-medium">System</span>
) : (
<span className="text-muted-foreground">unassigned pick one to wake them</span>
)}
{action.returnOwnerAgentId ? (
<>
<span className="text-muted-foreground"> Returns to:</span>
<AgentLink agentId={action.returnOwnerAgentId} agentMap={agentMap} />
</>
) : null}
</span>
</MetadataRow>
<MetadataRow label="Source run">
<RunChip runId={sourceRunId} agentId={action.previousOwnerAgentId} />
</MetadataRow>
{correctiveRunId ? (
<MetadataRow label="Corrective run">
<RunChip runId={correctiveRunId} agentId={action.previousOwnerAgentId} />
</MetadataRow>
) : null}
<MetadataRow label="Evidence">
{evidenceSummary ? (
<span className="break-words font-mono text-[11px] text-foreground/80">{evidenceSummary}</span>
) : (
<MissingValue />
)}
</MetadataRow>
<MetadataRow label="Next action">
{action.nextAction ? <span>{action.nextAction}</span> : <MissingValue />}
</MetadataRow>
<MetadataRow label="Wake">
<span className="inline-flex flex-wrap items-center gap-1.5">
{wakeSummary ? <span>{wakeSummary}</span> : <MissingValue />}
{showAttempt ? (
<span className="rounded-md border border-border/50 bg-background/60 px-1.5 py-0.5 text-[11px] text-muted-foreground">
attempt {action.attemptCount} of {action.maxAttempts}
</span>
) : null}
{showTimeoutInline ? (
<span className="rounded-md border border-border/50 bg-background/60 px-1.5 py-0.5 text-[11px] text-muted-foreground">
Times out {formatTimeShort(action.timeoutAt) ?? "soon"}
</span>
) : null}
</span>
</MetadataRow>
{cardState === "resolved" && action.outcome ? (
<MetadataRow label="Resolution">
<span className={cn("font-medium", tone.labelClass)}>
Resolved as {OUTCOME_LABEL[action.outcome]}
{action.resolvedAt ? ` · ${formatTimeShort(action.resolvedAt) ?? ""}` : ""}
</span>
</MetadataRow>
) : null}
</dl>
{showResolveActions ? (
<div className={cn("flex flex-wrap items-center gap-2 border-t px-3 py-2.5 sm:px-4", tone.divider)}>
<Popover>
<PopoverTrigger asChild>
<Button
type="button"
size="sm"
variant="default"
data-testid="recovery-action-resolve-trigger"
aria-label="Resolve recovery"
>
Resolve
</Button>
</PopoverTrigger>
<PopoverContent
align="start"
sideOffset={6}
className="w-72 p-1.5"
>
<div className="px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground">
Resolve recovery
</div>
<div className="flex flex-col">
{visibleResolveOptions.map((option) => (
<button
key={option.outcome}
type="button"
onClick={() => onResolve?.(option.outcome)}
className={cn(
"flex flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left text-sm transition-colors",
"hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50",
option.destructive ? "text-destructive" : null,
)}
>
<span className="font-medium leading-5">{option.label}</span>
<span className="text-[11px] leading-4 text-muted-foreground">{option.description}</span>
</button>
))}
</div>
</PopoverContent>
</Popover>
{cardState === "observe_only" ? (
<span className="text-[11px] text-muted-foreground">
Recovery is observing without interrupting the live run.
</span>
) : (
<span className="text-[11px] text-muted-foreground">
The card stays open until an explicit decision is recorded.
</span>
)}
</div>
) : null}
</section>
);
}
export type { IssueRecoveryActionStatus };
export default IssueRecoveryActionCard;
+30 -1
View File
@@ -1,5 +1,5 @@
import type { ReactNode } from "react";
import type { Issue } from "@paperclipai/shared";
import type { Issue, IssueRecoveryAction } from "@paperclipai/shared";
import { Link } from "@/lib/router";
import { Eye, Flag, X } from "lucide-react";
import {
@@ -8,6 +8,7 @@ import {
withIssueDetailHeaderSeed,
} from "../lib/issueDetailBreadcrumb";
import { cn } from "../lib/utils";
import { deriveActiveRecoveryDisplayState, RECOVERY_CHIP_DEFAULT_TONE } from "../lib/recovery-display";
import { StatusIcon } from "./StatusIcon";
import { productivityReviewTriggerLabel } from "./ProductivityReviewBadge";
import { hasAssignedBacklogBlocker } from "../lib/issue-blockers";
@@ -92,6 +93,8 @@ export function IssueRow({
Planning
</span>
) : null;
const recoveryAction = issue.activeRecoveryAction ?? null;
const recoveryIndicator = recoveryAction ? renderRecoveryChip(recoveryAction, selected) : null;
const parkedBlockerIndicator = hasAssignedBacklogBlocker(issue.blockedBy) ? (
<span
data-testid="issue-row-parked-blocker"
@@ -125,6 +128,7 @@ export function IssueRow({
{productivityReviewIndicator}
{planningModeIndicator}
{parkedBlockerIndicator}
{recoveryIndicator}
</span>
<span className="flex min-w-0 flex-1 flex-col gap-1 sm:contents">
<span className={cn("line-clamp-2 text-sm sm:order-2 sm:min-w-0 sm:flex-1 sm:truncate sm:line-clamp-none", titleClassName)}>
@@ -151,6 +155,7 @@ export function IssueRow({
</span>
{planningModeIndicator}
{parkedBlockerIndicator}
{recoveryIndicator}
</>
)}
{mobileMeta ? (
@@ -230,3 +235,27 @@ export function IssueRow({
</Link>
);
}
function renderRecoveryChip(action: IssueRecoveryAction, selected: boolean): ReactNode {
const state = deriveActiveRecoveryDisplayState(action);
if (!state) return null;
const tone = RECOVERY_CHIP_DEFAULT_TONE[state];
const Icon = tone.icon;
return (
<span
data-testid="issue-row-recovery-indicator"
data-recovery-state={state}
role="status"
aria-label={tone.label}
className={cn(
"ml-1.5 inline-flex shrink-0 items-center gap-0.5 rounded-full border px-2 py-0.5 text-[10px] font-medium",
tone.className,
selected ? "!border-muted-foreground !text-muted-foreground" : null,
)}
title={`${tone.label} — open the source issue to act.`}
>
<Icon className="h-2.5 w-2.5" aria-hidden />
{tone.label}
</span>
);
}
@@ -0,0 +1,130 @@
// @vitest-environment jsdom
import { act, type AnchorHTMLAttributes, type ReactNode } from "react";
import { createRoot, type Root } from "react-dom/client";
import type { Issue } from "@paperclipai/shared";
import { afterEach, describe, expect, it, vi } from "vitest";
import { IssueSiblingNavigation } from "./IssueSiblingNavigation";
vi.mock("@/lib/router", () => ({
Link: ({
children,
to,
issueQuicklookAlign,
issueQuicklookSide,
issuePrefetch: _issuePrefetch,
state: _state,
...props
}: AnchorHTMLAttributes<HTMLAnchorElement> & {
to: string;
issueQuicklookAlign?: string;
issueQuicklookSide?: string;
issuePrefetch?: unknown;
state?: unknown;
children?: ReactNode;
}) => (
<a
href={to}
data-quicklook-align={issueQuicklookAlign}
data-quicklook-side={issueQuicklookSide}
{...props}
>
{children}
</a>
),
}));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
function issue(id: string, overrides: Partial<Issue> = {}): Issue {
return {
id,
identifier: `PAP-${id}`,
title: `Sibling ${id}`,
status: "todo",
blockerAttention: null,
createdAt: new Date("2026-05-01T00:00:00.000Z"),
updatedAt: new Date("2026-05-01T00:00:00.000Z"),
...overrides,
} as Issue;
}
let root: Root | null = null;
let container: HTMLDivElement | null = null;
afterEach(() => {
if (root) {
act(() => root?.unmount());
}
root = null;
container?.remove();
container = null;
});
function render(node: ReactNode) {
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
act(() => root?.render(node));
return container;
}
describe("IssueSiblingNavigation", () => {
it("renders the locked card anatomy for previous and next siblings", () => {
const node = render(
<IssueSiblingNavigation
navigation={{
previous: issue("1", { title: "Previous sibling title" }),
next: issue("3", { title: "Next sibling title" }),
currentIndex: 1,
totalCount: 3,
}}
/>,
);
const nav = node.querySelector("nav");
expect(nav?.getAttribute("aria-label")).toBe("Sub-issue navigation");
expect(nav?.className).toContain("sm:grid-cols-2");
expect(nav?.className).not.toContain("border-t");
const links = Array.from(node.querySelectorAll("a"));
expect(links).toHaveLength(2);
expect(links[0].textContent).toContain("Previous");
expect(links[0].textContent).toContain("PAP-1");
expect(links[0].textContent).toContain("Previous sibling title");
expect(links[0].getAttribute("aria-label")).toBe("Previous sub-issue: PAP-1 - Previous sibling title");
expect(links[0].getAttribute("data-quicklook-align")).toBe("start");
expect(links[1].textContent).toContain("Next");
expect(links[1].textContent).toContain("PAP-3");
expect(links[1].textContent).toContain("Next sibling title");
expect(links[1].getAttribute("aria-label")).toBe("Next sub-issue: PAP-3 - Next sibling title");
expect(links[1].getAttribute("data-quicklook-align")).toBe("end");
expect(links[1].className).toContain("sm:text-right");
expect(links[0].className).toContain("rounded-lg");
expect(links[0].className).toContain("hover:bg-accent/50");
expect(links[0].className).toContain("focus-visible:ring-[3px]");
expect(node.querySelector(".truncate")?.textContent).toBe("Previous sibling title");
});
it("keeps a lone next card in the right desktop column", () => {
const node = render(
<IssueSiblingNavigation
navigation={{
previous: null,
next: issue("2"),
currentIndex: 0,
totalCount: 2,
}}
/>,
);
const links = Array.from(node.querySelectorAll("a"));
expect(links).toHaveLength(1);
expect(links[0].textContent).toContain("Next");
expect(links[0].className).toContain("sm:col-start-2");
expect(node.textContent).not.toContain("Previous");
});
});
@@ -0,0 +1,90 @@
import { ChevronLeft, ChevronRight } from "lucide-react";
import type { Issue } from "@paperclipai/shared";
import type { IssueSiblingNavigation as IssueSiblingNavigationState } from "@/lib/issue-detail-subissues";
import { createIssueDetailPath, withIssueDetailHeaderSeed } from "@/lib/issueDetailBreadcrumb";
import { cn } from "@/lib/utils";
import { Link } from "@/lib/router";
import { StatusIcon } from "./StatusIcon";
type IssueSiblingNavigationProps = {
navigation: IssueSiblingNavigationState | null;
linkState?: unknown;
};
export function IssueSiblingNavigation({ navigation, linkState }: IssueSiblingNavigationProps) {
if (!navigation) return null;
return (
<nav
aria-label="Sub-issue navigation"
className="mt-4 flex flex-col gap-3 sm:mt-6 sm:grid sm:grid-cols-2"
>
{navigation.previous ? (
<SiblingLink direction="previous" issue={navigation.previous} linkState={linkState} />
) : null}
{navigation.next ? (
<SiblingLink
direction="next"
issue={navigation.next}
linkState={linkState}
className={!navigation.previous ? "sm:col-start-2" : undefined}
/>
) : null}
</nav>
);
}
function SiblingLink({
direction,
issue,
linkState,
className,
}: {
direction: "previous" | "next";
issue: Issue;
linkState?: unknown;
className?: string;
}) {
const issuePathId = issue.identifier ?? issue.id;
const label = direction === "previous" ? "Previous" : "Next";
const ariaDirection = direction === "previous" ? "Previous sub-issue" : "Next sub-issue";
const identifier = issue.identifier ?? issue.id.slice(0, 8);
const Icon = direction === "previous" ? ChevronLeft : ChevronRight;
return (
<Link
to={createIssueDetailPath(issuePathId)}
state={withIssueDetailHeaderSeed(linkState, issue)}
issuePrefetch={issue}
issueQuicklookSide="top"
issueQuicklookAlign={direction === "previous" ? "start" : "end"}
aria-label={`${ariaDirection}: ${identifier} - ${issue.title}`}
className={cn(
"group min-w-0 rounded-lg border border-border bg-card px-3 py-2.5 text-left no-underline transition-colors hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring",
direction === "next" && "sm:text-right",
className,
)}
>
<div className="min-w-0 space-y-1.5">
<div className={cn(
"flex items-center gap-1.5 text-xs text-muted-foreground transition-colors group-hover:text-foreground",
direction === "next" && "sm:justify-end",
)}>
{direction === "previous" ? <Icon className="h-3.5 w-3.5 shrink-0" /> : null}
<span>{label}</span>
{direction === "next" ? <Icon className="h-3.5 w-3.5 shrink-0" /> : null}
</div>
<div className={cn(
"flex min-w-0 items-center gap-1.5 text-xs font-mono text-muted-foreground transition-colors group-hover:text-foreground",
direction === "next" && "sm:justify-end",
)}>
<StatusIcon status={issue.status} blockerAttention={issue.blockerAttention} />
<span className="shrink-0">{identifier}</span>
</div>
<div className="truncate text-sm text-foreground">
{issue.title}
</div>
</div>
</Link>
);
}
@@ -23,6 +23,12 @@ export type ManagedRoutineMissingRef = {
resourceKey: string;
};
export type ManagedRoutineDefaultDrift = {
changedFields: string[];
defaultTitle?: string | null;
defaultDescription?: string | null;
};
export type ManagedRoutinesListItem = {
key: string;
title: string;
@@ -37,6 +43,7 @@ export type ManagedRoutinesListItem = {
lastRunStatus?: string | null;
managedByPluginDisplayName?: string | null;
missingRefs?: ManagedRoutineMissingRef[];
defaultDrift?: ManagedRoutineDefaultDrift | null;
};
export type ManagedRoutinesListProps = {