Back

Archived SessionNew

A muted banner takes the composer's place in an archived agent session; the transcript stays readable and one Unarchive button makes it writable again in place.

Add a share dialog to the session header.

Done — the dialog has Private and Public options and warns when the repo is private. Pushed to the branch.

This session is archived. Unarchive it to keep working in it.

Archived after 7 days without activity.

"use client";

import * as React from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { Archive, LoaderCircle } from "lucide-react";

import { cn } from "@/lib/utils";

export interface ArchivedSessionBannerProps {
  /** Whether the session is archived. While true the banner replaces the composer. */
  archived: boolean;
  /** Brings the session back. Resolve when it can take messages again; reject to show `error`. */
  onUnarchive: () => Promise<void> | void;
  /** Shown once the session is active again — usually the ordinary composer. */
  children: React.ReactNode;
  /** One sentence on what the person has to do ("Unarchive it to keep working in it."). */
  message?: string;
  /** Optional detail: when or why it was archived ("Archived after 7 days without activity."). */
  detail?: string;
  className?: string;
}

/**
 * Takes the composer's place in an archived session. The transcript stays
 * readable above it; the one action that makes the session writable again
 * sits right where the person was going to type.
 */
export function ArchivedSessionBanner({
  archived,
  onUnarchive,
  children,
  message = "This session is archived. Unarchive it to keep working in it.",
  detail,
  className,
}: ArchivedSessionBannerProps) {
  const reduce = useReducedMotion();
  const [pending, setPending] = React.useState(false);
  const [error, setError] = React.useState<string | null>(null);
  const buttonRef = React.useRef<HTMLButtonElement>(null);
  const wrapperRef = React.useRef<HTMLDivElement>(null);
  const wasArchived = React.useRef(archived);

  // When the session comes back, hand focus to whatever replaced the banner.
  React.useEffect(() => {
    if (wasArchived.current && !archived) {
      const el = wrapperRef.current?.querySelector<HTMLElement>("textarea, input, [contenteditable='true']");
      el?.focus();
    }
    wasArchived.current = archived;
  }, [archived]);

  async function unarchive() {
    if (pending) return;
    setPending(true);
    setError(null);
    try {
      await onUnarchive();
    } catch {
      setError("Couldn't unarchive the session. Try again.");
      buttonRef.current?.focus();
    } finally {
      setPending(false);
    }
  }

  const fade = reduce ? { opacity: 0 } : { opacity: 0, y: 6 };

  return (
    <div ref={wrapperRef} className={cn("relative", className)}>
      <AnimatePresence mode="wait" initial={false}>
        {archived ? (
          <motion.div
            key="archived"
            role="status"
            initial={fade}
            animate={{ opacity: 1, y: 0 }}
            exit={fade}
            transition={{ duration: 0.18, ease: "easeOut" }}
            className="flex flex-col gap-3 rounded-2xl bg-muted px-4 py-3 sm:flex-row sm:items-center"
          >
            <div className="flex min-w-0 flex-1 items-start gap-2.5">
              <Archive className="mt-0.5 size-4 shrink-0 text-muted-foreground" aria-hidden />
              <div className="min-w-0">
                <p className="text-sm">{message}</p>
                {detail && <p className="mt-0.5 text-xs text-muted-foreground">{detail}</p>}
                {error && (
                  <p role="alert" className="mt-0.5 text-xs text-destructive">
                    {error}
                  </p>
                )}
              </div>
            </div>
            <button
              ref={buttonRef}
              type="button"
              onClick={unarchive}
              disabled={pending}
              aria-busy={pending}
              className="inline-flex shrink-0 items-center justify-center gap-1.5 self-end rounded-lg bg-foreground/[0.06] px-3 py-1.5 text-sm font-medium transition-colors hover:bg-foreground/10 disabled:opacity-70 sm:self-auto"
            >
              {pending && <LoaderCircle className="size-3.5 animate-spin motion-reduce:animate-none" aria-hidden />}
              {pending ? "Unarchiving…" : "Unarchive"}
            </button>
          </motion.div>
        ) : (
          <motion.div
            key="active"
            initial={fade}
            animate={{ opacity: 1, y: 0 }}
            exit={fade}
            transition={{ duration: 0.18, ease: "easeOut" }}
          >
            {children}
          </motion.div>
        )}
      </AnimatePresence>
    </div>
  );
}

A UX spec for this pattern — written for agents implementing or reusing it, not the code.

# Archived Session

## Summary
An archived agent session stays readable but can't take new messages. Instead of a disabled composer or a dead end, a muted banner takes the composer's place. It says the session is archived and gives one action, Unarchive, that makes it writable again in place. The person keeps the transcript, the link and the context.

## When to use
- Sessions are archived automatically (after inactivity, when the container is reclaimed) or by hand, and people come back to them from history, links or notifications.
- Bringing a session back is cheap enough to do on demand: restoring its state or provisioning a fresh environment for it.
- The transcript is still worth reading while the session is archived.

## When not to use
- The session is gone for good (deleted, expired past retention). Say so and offer to start a new session; don't show an Unarchive that can't work.
- The person can't unarchive it (someone else's shared session, view-only access). Show a read-only notice without the action, or use **Access Request**.
- The run failed or was interrupted. That's **Generation Error** or **Checkpoint Restore**, not an archived state.
- Archived items in a list or sidebar. Mark them there; this pattern is the state of an open session.

## Anatomy
- Banner: sits exactly where the composer goes, same width, on a muted background with no border, so it reads as a state rather than an alert.
- Message: one sentence, what happened and what to do ("This session is archived. Unarchive it to keep working in it.").
- Detail (optional): when or why it was archived ("Archived after 7 days without activity.").
- Unarchive button: a quiet secondary button on the right; it shows a spinner and "Unarchiving…" while the session comes back.
- Transcript: above, unchanged and fully readable, with copy and links still working.

## Behavior
- While archived, nothing that writes is offered: no composer, no retry or regenerate on messages. Reading, copying and sharing still work.
- Unarchive works in place. The banner shows its pending state, then is replaced by the composer, and focus moves into it.
- Restore the unsent draft if the session had one when it was archived.
- If unarchiving fails, keep the banner, say so in a line under the message and leave the button ready to try again.
- If unarchiving takes long (provisioning a new environment), keep the pending state on the button and let the person keep reading; don't block the page.
- Archiving again (from a menu) brings the banner back with the same message.

## Content guidelines
- Lead with the state, then the action: "This session is archived. Unarchive it to keep working in it."
- Use the same verb on the button as in the message: "Unarchive", not "Restore" or "Reopen".
- Give a reason only when it helps the person decide or understand: "Archived after 7 days without activity."
- Don't imply loss. If nothing was lost, don't say "expired" or "closed".

## Accessibility
- The banner is a `role="status"` region, so its message is read when the session opens or is archived.
- The button keeps one accessible name per state ("Unarchive", then "Unarchiving…") and sets `aria-busy` while pending.
- A failure is announced with `role="alert"` and focus stays on the button so the person can try again.
- After unarchiving, focus moves to the composer that replaced the banner. Under `prefers-reduced-motion` the swap fades instead of sliding.

## Related patterns
- **Share Session** — Use it as well: an archived session can still be shared and read.
- **Checkpoint Restore** — Use it instead to go back to an earlier point inside an active session.
- **Background Tasks Drawer** — Use it to show sessions that are still running, before any of them are archived.
- **Generation Error** — Use it instead when a run failed rather than the session being put away.

Do’s and don’ts

Do use it for

  • Sessions are archived automatically (after inactivity, when the container is reclaimed) or by hand, and people come back to them from history, links or notifications.
  • Bringing a session back is cheap enough to do on demand: restoring its state or provisioning a fresh environment for it.
  • The transcript is still worth reading while the session is archived.

Don’t use it for

  • The session is gone for good (deleted, expired past retention). Say so and offer to start a new session; don't show an Unarchive that can't work.
  • The person can't unarchive it (someone else's shared session, view-only access). Show a read-only notice without the action, or use Access Request.
  • The run failed or was interrupted. That's Generation Error or Checkpoint Restore, not an archived state.
  • Archived items in a list or sidebar. Mark them there; this pattern is the state of an open session.