import type {
IssueBlockerAttention,
IssueRecoveryAction,
IssueRelationIssueSummary,
IssueScheduledRetry,
SuccessfulRunHandoffState,
} from "@paperclipai/shared";
import type { ReactNode } from "react";
import { AlertTriangle, CheckCircle2, Circle, Flag, Loader2, RotateCcw } from "lucide-react";
import { Link } from "@/lib/router";
import { cn } from "../lib/utils";
import { Button } from "@/components/ui/button";
import { createIssueDetailPath } from "../lib/issueDetailBreadcrumb";
import { formatMonitorOffset } from "../lib/issue-monitor";
import { useRetryNowMutation } from "../hooks/useRetryNowMutation";
import { IssueLinkQuicklook } from "./IssueLinkQuicklook";
import { LockedIssueChip, isLockedIssueStub } from "./LockedIssueChip";
import { RetryErrorBand } from "./IssueScheduledRetryCard";
import {
isAssignedBacklogBlocker,
orderWaitingBlockers,
type WaitingBlockerStatus,
} from "../lib/issue-blockers";
import { isSuccessfulRunHandoffRequired } from "../lib/successful-run-handoff";
import { Badge } from "@/components/ui/badge";
import {
deriveActiveRecoveryDisplayState,
RECOVERY_CHIP_DEFAULT_TONE,
recoveryChipLabel,
} from "../lib/recovery-display";
import {
formatRecoveryLineageSummary,
readRecoveryRetryLineage,
} from "../lib/recovery-lineage";
import { StatusGlyph } from "./StatusGlyph";
function BlockerRecoveryIndicator({
action,
scheduledRetry,
}: {
action: IssueRecoveryAction;
/** The blocker's own scheduled retry, used to verify that the stored attempt is in flight. */
scheduledRetry?: IssueScheduledRetry | null;
}) {
const liveness = { scheduledRetry: scheduledRetry ?? null };
const state = deriveActiveRecoveryDisplayState(action, liveness);
if (!state) return null;
const tone = RECOVERY_CHIP_DEFAULT_TONE[state];
const Icon = tone.icon;
// The blocker chip reads the same stored lineage as the source task's recovery card, so
// a parent view never contradicts the task it is waiting on.
const lineage = readRecoveryRetryLineage(action, liveness);
const label = recoveryChipLabel(state, action.kind, lineage);
const detail = lineage ? formatRecoveryLineageSummary(lineage) : null;
return (
A correction run is in progress — the agent is working. This alert returns if the run stops without choosing a next step. {shortRunId ? ( <> {" "} {assigneeAgentId ? ( run {shortRunId} ) : ( run {shortRunId} )} > ) : null}
Waiting on live work
Queued behind {total} {queuedNoun} being worked in order. This task resumes automatically when the chain is done. Comments still notify the assignee.
This task still needs a next step.
A run finished successfully, but the task is still open. Paperclip needs someone to choose what happens next.
Detected progress: {successfulRunHandoff.detectedProgressSummary}
) : null} {successfulRunRetryNow ? ({blockers.length > 0 ? isStalled ? stalledLeafBlockers.length > 1 ? <>Work on this task is blocked by {blockerLabel}, but the chain is stalled in review without a clear next step. Resolve the stalled reviews below or remove them as blockers.> : <>Work on this task is blocked by {blockerLabel}, but the chain is stalled in review without a clear next step. Resolve the stalled review below or remove it as a blocker.> : reopenSuppressed ? <>A message won’t restart this task yet — it stays blocked by {blockerLabel} until {blockers.length === 1 ? "it is" : "they are"} done, then it reopens automatically. Comments still notify {responsibleName} for questions or triage in the meantime.> : <>Work on this task is blocked by {blockerLabel} until {blockers.length === 1 ? "it is" : "they are"} complete. Comments still notify the assignee for questions or triage.> : <>Work on this task is blocked until someone moves it back to To do. Comments still notify the assignee for questions or triage.>}
{reopenSuppressed && reopenSuppressedLeafId ? (Still blocked by{" "} {reopenSuppressedLeafId} {reopenSuppressedLeafStatus ? <> ({reopenSuppressedLeafStatus})> : null} {reopenSuppressedOtherCount > 0 ? ` and ${reopenSuppressedOtherCount} other ${ reopenSuppressedOtherCount === 1 ? "task" : "tasks" }` : null} .
) : null} {blockers.length > 0 ? (