{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"failure-recovery","type":"registry:component","title":"Failure Recovery Surface","description":"Understand what completed and choose how to recover.","dependencies":[],"categories":["systems","recovery","failure","operations"],"files":[{"path":"components/lab/failure-recovery/failure-recovery.tsx","target":"components/lab/failure-recovery/failure-recovery.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useRef, useState } from \"react\";\nimport \"./failure-recovery.css\";\n\nexport type RecoveryStepStatus = \"pending\" | \"running\" | \"complete\" | \"failed\" | \"rolled-back\";\nexport type RecoveryStep = { id: string; label: string; status: RecoveryStepStatus; detail?: string };\nexport type RecoveryPhase = \"idle\" | \"running\" | \"failed\" | \"complete\" | \"rolled-back\";\nexport type RetrySafety = \"safe\" | \"confirm\" | \"unavailable\";\nexport type FailureRecoveryProps = {\n  title: string;\n  phase: RecoveryPhase;\n  steps: RecoveryStep[];\n  /** Host-provided description of preserved work and whether it is usable. */\n  preserved: string;\n  retrySafety: RetrySafety;\n  rollbackAvailable: boolean;\n  onStart?: () => void;\n  onRetry?: (stepId: string) => void;\n  onRollback?: () => void;\n};\n\nconst LABEL: Record<RecoveryStepStatus, string> = { pending: \"Waiting\", running: \"In progress\", complete: \"Complete\", failed: \"Failed\", \"rolled-back\": \"Rolled back\" };\nconst PHASE: Record<RecoveryPhase, string> = { idle: \"Ready to export\", running: \"Export in progress\", failed: \"Export needs attention\", complete: \"Export complete\", \"rolled-back\": \"Rollback complete\" };\n\n/** Presents confirmed host state; the host executes and deduplicates operations. */\nexport function FailureRecoverySurface({ title, phase, steps, preserved, retrySafety, rollbackAvailable, onStart, onRetry, onRollback }: FailureRecoveryProps) {\n  const [confirmRetry, setConfirmRetry] = useState(false);\n  const root = useRef<HTMLElement>(null);\n  const failed = steps.find((step) => step.status === \"failed\");\n  const marker = `${phase}:${failed?.id ?? \"\"}:${retrySafety}`;\n  const [lastMarker, setLastMarker] = useState(marker);\n  if (marker !== lastMarker) { setLastMarker(marker); setConfirmRetry(false); }\n  const requestRetry = () => {\n    if (!failed || !onRetry || retrySafety === \"unavailable\") return;\n    if (retrySafety === \"confirm\" && !confirmRetry) { setConfirmRetry(true); return; }\n    setConfirmRetry(false);\n    root.current?.focus();\n    onRetry(failed.id);\n  };\n  return <section ref={root} tabIndex={-1} className=\"fr-root\" aria-label={title}>\n    <header className=\"fr-head\"><div><p className=\"fr-eyebrow\">WORKSPACE EXPORT</p><h3>{title}</h3></div><span className=\"fr-phase\" data-phase={phase}>{PHASE[phase]}</span></header>\n    <p className=\"fr-preserved\" role=\"status\" aria-live=\"polite\">{preserved}</p>\n    <ol className=\"fr-steps\">{steps.map((step, index) => <li key={step.id} data-status={step.status}><span className=\"fr-number\" aria-hidden=\"true\">{String(index + 1).padStart(2, \"0\")}</span><div><strong>{step.label}</strong>{step.detail ? <p>{step.detail}</p> : null}</div><span className=\"fr-step-status\">{LABEL[step.status]}</span></li>)}</ol>\n    {phase === \"idle\" && onStart ? <div className=\"fr-actions\"><button type=\"button\" className=\"fr-primary\" onClick={() => { root.current?.focus(); onStart(); }}>Start export</button></div> : null}\n    {phase === \"failed\" ? <div className=\"fr-recovery\"><h4>Choose a next step</h4><p>{retrySafety === \"safe\" ? \"The host reports that retrying the failed step is safe.\" : retrySafety === \"confirm\" ? \"Retry requires confirmation because the host cannot guarantee it is safe.\" : \"Retry is not available for this operation.\"}</p>{confirmRetry && retrySafety === \"confirm\" ? <p className=\"fr-warning\">Retrying may repeat work. Confirm with the host before proceeding.</p> : null}<div className=\"fr-actions\">{failed && onRetry && retrySafety !== \"unavailable\" ? <button type=\"button\" className=\"fr-primary\" onClick={requestRetry}>{confirmRetry ? \"Confirm retry\" : `Retry ${failed.label}`}</button> : null}{confirmRetry ? <button type=\"button\" onClick={() => setConfirmRetry(false)}>Cancel</button> : null}{rollbackAvailable && onRollback ? <button type=\"button\" onClick={() => { root.current?.focus(); onRollback(); }}>Roll back</button> : <span>Rollback unavailable</span>}</div></div> : null}\n    <p className=\"fr-foot\">The host runs, deduplicates and confirms every operation.</p>\n  </section>;\n}\n"},{"path":"components/lab/failure-recovery/failure-recovery.css","target":"components/lab/failure-recovery/failure-recovery.css","type":"registry:file","content":".fr-root{padding:20px;border:1px solid #dedee3;border-radius:14px;background:#fff;color:#17171b;font:inherit}.fr-head{display:flex;justify-content:space-between;align-items:start;gap:12px}.fr-eyebrow{margin:0;color:#5f5f68;font:600 10px/1.4 ui-monospace,monospace;letter-spacing:.1em}.fr-head h3{margin:4px 0 0;font-size:19px;line-height:1.2}.fr-phase{border-radius:999px;background:#f1eefc;color:#32119c;padding:5px 9px;font-size:11px;white-space:nowrap}.fr-phase[data-phase=\"failed\"]{background:#fbefea;color:#8b3219}.fr-preserved{margin:14px 0;color:#4f4f58;font-size:13px;line-height:1.5}.fr-steps{list-style:none;margin:0;padding:0;border-top:1px solid #e9e9e6}.fr-steps li{display:grid;grid-template-columns:28px minmax(0,1fr) auto;gap:10px;align-items:start;padding:10px 0;border-bottom:1px solid #e9e9e6}.fr-number{color:#77717e;font:11px/1.5 ui-monospace,monospace}.fr-steps strong{font-size:13px}.fr-steps p{margin:2px 0 0;color:#5f5f68;font-size:12px;line-height:1.4}.fr-step-status{color:#5f5f68;font:11px/1.5 ui-monospace,monospace;text-align:right}.fr-steps li[data-status=\"failed\"] .fr-step-status{color:#8b3219;font-weight:600}.fr-recovery{margin-top:16px;padding:14px;border-radius:9px;background:#f8f5f2}.fr-recovery h4{margin:0;font-size:14px}.fr-recovery p,.fr-foot{margin:7px 0 0;color:#5f5f68;font-size:12px;line-height:1.5}.fr-recovery .fr-warning{color:#7a341a}.fr-actions{display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin-top:12px}.fr-root button{border:1px solid #d1d0d6;border-radius:8px;background:#fff;padding:8px 11px;color:#24242b;font:inherit;font-size:12px;font-weight:600;cursor:pointer}.fr-root .fr-primary{border-color:#4f27e0;background:#4f27e0;color:#fff}.fr-actions span{font-size:12px;color:#5f5f68}.fr-root :focus-visible{outline:2px solid #4f27e0;outline-offset:3px}.fr-foot{margin-top:16px;font-size:11px}@media(max-width:360px){.fr-root{padding:16px}.fr-head{flex-wrap:wrap}.fr-steps li{grid-template-columns:24px minmax(0,1fr)}.fr-step-status{grid-column:2;text-align:left}}\n"}]}