A rail of run checkpoints for restoring earlier work
Enter opens a mark · Tab to Restore · Esc closes it
pnpm dlx shadcn@latest add @notchset-pro/checkpoint-railPoints in a run to go back to: choose content, chat or both, Restore, Undo.
Every shadcn style · one file
Import it and pass your content. The props that matter most are listed next.
"use client";
import * as React from "react";
import { CheckpointRail, type CheckpointMark } from "@/components/ui/notchset/checkpoint-rail";
import { useLessMotion } from "@/lib/notchset/motion";
import { pressIn, useSelfPlay } from "./self-play";
/*
* A draft's four marks alone, oldest first, Now last,. On first sight Outline drafted is picked: what
* to restore opens under it on the card, the marks after it dim, the count says what comes back; Restore lands the
* restore as a mark of its own with Undo under it. Then the hand drives it: Enter opens a mark, Tab reaches Restore,
* Esc closes. The quiet chip makes the next restore fail, said under the choice, and Restore tries again. Less motion
* shows the restore landed. Nothing is saved anywhere.
*/
/* 10:02 on the day, in UTC so the server and the browser write the same time */
const T = (min: number) => Date.UTC(2026, 10, 16, 10, min);
const MARKS: CheckpointMark[] = [
{ id: "start", at: T(2), label: "Start", note: "the draft as you wrote it", scopes: ["content", "chat"], changes: 0, messages: 1 },
{ id: "outline", at: T(4), label: "Outline drafted", by: "Assistant", scopes: ["content", "chat"], changes: 1, messages: 1, brings: "Sections 2-4 go back to the outline" },
{ id: "intro", at: T(7), label: "Intro rewritten", by: "Assistant", scopes: ["content", "chat"], changes: 3, messages: 1, brings: "The rewritten intro comes back" },
{ id: "now", at: T(9), label: "Now", scopes: ["content", "chat"], changes: 0, messages: 1 },
];
const WORDS = { failed: "Couldn’t restore: the draft changed while you chose. Try again" };
type Restored = { to: CheckpointMark; changes: number; messages: number };
export default function CheckpointRailDemo() {
const fails = false;
const marks = MARKS;
const words = WORDS;
const less = useLessMotion();
const root = React.useRef<HTMLDivElement>(null);
const play = useSelfPlay(root, { beats: [0], off: less });
const take = (e: React.SyntheticEvent) => {
if (e.nativeEvent.isTrusted) play.handOver();
};
const ending: Restored = { to: marks[1]!, changes: 3, messages: 2 };
const [restored, setRestored] = React.useState<Restored | null>(ending);
const [busy, setBusy] = React.useState(false);
const [error, setError] = React.useState<string>();
/* the chip is a switch: while it is on, every restore fails */
const timer = React.useRef(0);
React.useEffect(() => () => clearTimeout(timer.current), []);
const rail: CheckpointMark[] = restored
? [...marks.slice(0, -1), { id: "restored", at: T(10), label: `Restored to ‘${restored.to.label}’`, by: "you", scopes: ["content", "chat"], changes: 0, restore: { changes: restored.changes, messages: restored.messages } }]
: marks;
const rewind = (id: string, scopes: readonly ("content" | "chat")[]) => {
const at = rail.findIndex((m) => m.id === id);
const after = rail.slice(at + 1);
const fail = fails;
setError(undefined);
setBusy(true);
timer.current = window.setTimeout(() => {
setBusy(false);
if (fail) {
return setError(words.failed);
}
setRestored({
to: rail[at]!,
changes: scopes.includes("content") ? after.reduce((n, m) => n + m.changes, 0) : 0,
messages: scopes.includes("chat") ? after.reduce((n, m) => n + (m.messages ?? 0), 0) : 0,
});
}, 600);
};
/* the moment: a mark picked, what it costs said, Restore, the restore lands with Undo */
React.useEffect(() => {
if (play.step !== 0 || play.mine || less) return;
const ids = [
window.setTimeout(() => setRestored(null), 0),
window.setTimeout(() => pressIn(root.current, "[data-slot=checkpoint-rail-mark]:nth-child(2) button[aria-expanded]"), 500),
window.setTimeout(() => pressIn(root.current, "[data-slot=checkpoint-rail-actions] [data-intent=primary]"), 1900),
/* the script is a pointer: no keyboard ring left on the mark it restored to */
window.setTimeout(() => (document.activeElement as HTMLElement | null)?.blur?.(), 2700),
];
return () => ids.forEach(clearTimeout);
}, [play.step, play.mine, less]);
return (
<div ref={root} onPointerDownCapture={take} onKeyDownCapture={take} className="flex w-full justify-center">
<span className="sr-only">Simulated, nothing is saved.</span>
<div className="min-h-[412px] w-[400px] max-w-full">
<CheckpointRail marks={rail} timeZone="UTC" busy={busy} error={error} onRewind={rewind} onUndo={() => setRestored(null)} />
</div>
</div>
);
}"use client";
import * as React from "react";
import { CheckpointRail, type CheckpointMark } from "@/components/ui/notchset/checkpoint-rail";
import { useLessMotion } from "@/lib/notchset/motion";
import { pressIn, useSelfPlay } from "./self-play";
/*
* A draft's four marks alone, oldest first, Now last,. On first sight Outline drafted is picked: what
* to restore opens under it on the card, the marks after it dim, the count says what comes back; Restore lands the
* restore as a mark of its own with Undo under it. Then the hand drives it: Enter opens a mark, Tab reaches Restore,
* Esc closes. The quiet chip makes the next restore fail, said under the choice, and Restore tries again. Less motion
* shows the restore landed. Nothing is saved anywhere.
*/
/* 10:02 on the day, in UTC so the server and the browser write the same time */
const T = (min: number) => Date.UTC(2026, 10, 16, 10, min);
const MARKS: CheckpointMark[] = [
{ id: "start", at: T(2), label: "Start", note: "the draft as you wrote it", scopes: ["content", "chat"], changes: 0, messages: 1 },
{ id: "outline", at: T(4), label: "Outline drafted", by: "Assistant", scopes: ["content", "chat"], changes: 1, messages: 1, brings: "Sections 2-4 go back to the outline" },
{ id: "intro", at: T(7), label: "Intro rewritten", by: "Assistant", scopes: ["content", "chat"], changes: 3, messages: 1, brings: "The rewritten intro comes back" },
{ id: "now", at: T(9), label: "Now", scopes: ["content", "chat"], changes: 0, messages: 1 },
];
const WORDS = { failed: "Couldn’t restore: the draft changed while you chose. Try again" };
type Restored = { to: CheckpointMark; changes: number; messages: number };
export default function CheckpointRailDemo() {
const fails = false;
const marks = MARKS;
const words = WORDS;
const less = useLessMotion();
const root = React.useRef<HTMLDivElement>(null);
const play = useSelfPlay(root, { beats: [0], off: less });
const take = (e: React.SyntheticEvent) => {
if (e.nativeEvent.isTrusted) play.handOver();
};
const ending: Restored = { to: marks[1]!, changes: 3, messages: 2 };
const [restored, setRestored] = React.useState<Restored | null>(ending);
const [busy, setBusy] = React.useState(false);
const [error, setError] = React.useState<string>();
/* the chip is a switch: while it is on, every restore fails */
const timer = React.useRef(0);
React.useEffect(() => () => clearTimeout(timer.current), []);
const rail: CheckpointMark[] = restored
? [...marks.slice(0, -1), { id: "restored", at: T(10), label: `Restored to ‘${restored.to.label}’`, by: "you", scopes: ["content", "chat"], changes: 0, restore: { changes: restored.changes, messages: restored.messages } }]
: marks;
const rewind = (id: string, scopes: readonly ("content" | "chat")[]) => {
const at = rail.findIndex((m) => m.id === id);
const after = rail.slice(at + 1);
const fail = fails;
setError(undefined);
setBusy(true);
timer.current = window.setTimeout(() => {
setBusy(false);
if (fail) {
return setError(words.failed);
}
setRestored({
to: rail[at]!,
changes: scopes.includes("content") ? after.reduce((n, m) => n + m.changes, 0) : 0,
messages: scopes.includes("chat") ? after.reduce((n, m) => n + (m.messages ?? 0), 0) : 0,
});
}, 600);
};
/* the moment: a mark picked, what it costs said, Restore, the restore lands with Undo */
React.useEffect(() => {
if (play.step !== 0 || play.mine || less) return;
const ids = [
window.setTimeout(() => setRestored(null), 0),
window.setTimeout(() => pressIn(root.current, "[data-slot=checkpoint-rail-mark]:nth-child(2) button[aria-expanded]"), 500),
window.setTimeout(() => pressIn(root.current, "[data-slot=checkpoint-rail-actions] [data-intent=primary]"), 1900),
/* the script is a pointer: no keyboard ring left on the mark it restored to */
window.setTimeout(() => (document.activeElement as HTMLElement | null)?.blur?.(), 2700),
];
return () => ids.forEach(clearTimeout);
}, [play.step, play.mine, less]);
return (
<div ref={root} onPointerDownCapture={take} onKeyDownCapture={take} className="flex w-full justify-center">
<span className="sr-only">Simulated, nothing is saved.</span>
<div className="min-h-[412px] w-[400px] max-w-full">
<CheckpointRail marks={rail} timeZone="UTC" busy={busy} error={error} onRewind={rewind} onUndo={() => setRestored(null)} />
</div>
</div>
);
}"use client";
import * as React from "react";
/*
* A demo that plays itself until the first touch: the script lives in the demo, never in the piece, which only gets
* the props a person would give it. It moves 0.4 s after the piece is first seen, then takes each step on its beat;
* off screen or paused it waits. The first press, key or focus on the piece (bind `handOver` to it; a scroll over it never counts) makes it the
* visitor's for good and drops every queued step; with less motion (`off`) it never plays and rests in its first frame.
* A host can hand it over from outside the piece too (a settings panel beside it the visitor has used): under
* <HandedOver value>, it never plays, a remount included.
*
* const play = useSelfPlay(root, { beats: [2800, 2800], loop: true, off: less });
* <div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} onFocusCapture={play.handOver}>
* play.step // the step it is at, -1 before its first
* play.control // "pause" while it plays, "play" once paused (a new take), "replay" once it is over or yours
*
* Each step presses the piece's own controls (pressIn), so the script shows exactly what a hand can do.
*
* A host that shows the piece once (<PlayOnce value={{ settle }}>) changes three things: the script starts when the
* piece is first half in view and never again on coming back, it never loops, and with less motion (or `settle`) it
* takes every step at once, so the piece rests on the END of its moment. `hold` is a reason not to play at all that is
* not motion (a mode with nothing to show): it holds in every host. Under <PlayOnce value={{ active: false }}> (a look
* that is mounted but not shown) it waits until it is shown.
*/
type SelfPlayOptions = {
/** how long each step waits after the one before it, in ms; the first step waits 0.4 s after the piece is seen */
beats: readonly number[];
/** starts over after the last step; without it the script plays once and rests */
loop?: boolean | undefined;
/** no self-play at all (less motion): the piece is the visitor's from the start */
off: boolean;
/** no self-play for a reason other than motion (a mode with nothing to show), in every host */
hold?: boolean | undefined;
};
/** How a host shows the piece: once on arrival (see useSelfPlay). */
type PlayOnceHost = {
/** rest on the end at once, without playing (less motion, or a reset) */
settle?: boolean | undefined;
/** false while the piece is mounted but not shown: it waits */
active?: boolean | undefined;
};
const START = 400;
/**
* Whether a demo plays itself at all. Off: every piece rests in its first frame and is
* the visitor's from the start; nothing presses its controls for them.
*/
const SELF_PLAY: boolean = false;
/** True where the visitor has already taken the piece from outside it: nothing under it plays itself. */
const HandedOver = React.createContext(false);
/** A host that shows the piece once: play once on arrival, rest on the end (null: play as the demo asks). */
const PlayOnce = React.createContext<PlayOnceHost | null>(null);
function useSelfPlay(root: React.RefObject<Element | null>, { beats, loop: looped = false, off: still, hold = false }: SelfPlayOptions) {
const once = React.useContext(PlayOnce);
const active = once?.active !== false;
/* shown once: less motion (or a settled host) takes every step at once and rests on the end */
const quick = once != null && (still || Boolean(once.settle));
const loop = once == null && looped;
/* the first touch hands it over for good */
const [mine, setMine] = React.useState(false);
const handOver = React.useCallback(() => setMine(true), []);
const handedOver = React.useContext(HandedOver);
const off = !SELF_PLAY || hold || (quick ? false : still) || mine || (handedOver && !quick);
const [seen, setSeen] = React.useState(false);
const [paused, setPaused] = React.useState(false);
const [taken, setTaken] = React.useState(0);
const n = Math.max(1, beats.length);
const done = !loop && taken >= n;
React.useEffect(() => {
const el = root.current;
if (!active) return;
/* without an observer (an old browser, a test) it counts as seen */
if (!el || typeof IntersectionObserver === "undefined" || quick) {
const t = window.setTimeout(() => setSeen(true));
return () => window.clearTimeout(t);
}
/* shown once: first half in view starts it, and leaving never stops or restarts it */
const io = once
? new IntersectionObserver((es) => {
if (es.some((e) => e.isIntersecting && e.intersectionRatio >= 0.5)) {
setSeen(true);
io.disconnect();
}
}, { threshold: 0.5 })
: new IntersectionObserver((es) => setSeen(es.some((e) => e.isIntersecting)));
io.observe(el);
return () => io.disconnect();
}, [root, active, once, quick]);
const playing = !off && seen && active && !paused && !done;
const delay = quick ? 0 : taken === 0 ? START : (beats[taken % n] ?? START);
React.useEffect(() => {
if (!playing) return;
const t = window.setTimeout(() => setTaken((k) => k + 1), delay);
return () => window.clearTimeout(t);
}, [playing, taken, delay]);
/* one control in one place: Pause while it plays, Play (a new take) once paused, Replay once it is over or yours */
/* self-play off: never "over", so a demo rests in its FIRST frame, not its end frame */
const control: "pause" | "play" | "replay" = paused || !SELF_PLAY ? "play" : off || done ? "replay" : "pause";
return { step: taken === 0 ? -1 : (taken - 1) % n, taken, playing, control, mine, handOver, pause: () => setPaused(true) };
}
/**
* Presses a real control inside `root`, as the visitor would: the first match of `selector`, or the one whose text is
* `text`. A click only, so it never counts as the visitor's touch.
*/
function pressIn(root: Element | null, selector: string, text?: string) {
const all = [...(root?.querySelectorAll<HTMLElement>(selector) ?? [])];
(text == null ? all[0] : all.find((el) => el.textContent?.trim() === text))?.click();
}
export { HandedOver, PlayOnce, pressIn, useSelfPlay, type PlayOnceHost, type SelfPlayOptions };components/ui/notchset/checkpoint-rail.tsx
This component is included with Pro.
Try the live preview above. Get Pro to install the source.
LevelOrganism: made of molecules or blocks.
Made ofButton,Icon button,Rolling number,Segmented control,Stream adapters
Needs your registry key. Every components.json style gets the same files.
Works with React 18.3 or 19 on Tailwind CSS v4, in any shadcn project. What's tested
The CLI adds the styles to the CSS file named in components.json (tailwind.css). Check that it points at your global stylesheet, that the project uses Tailwind CSS v4, and that the file is imported in your root layout. Installed by hand: paste styles.css into that file.
The sound you hear is this page's: the piece you install plays none, and calls onFeedback on each move so you can add your own.
onFeedback–
(e: FeedbackEvent) => voidcalled once per move, for your sound or haptics
marks–
readonly CheckpointMark[]the marks, oldest first; the last is where the run is now
items[]
readonly CheckpointItem[]the thread between the marks, in order; picking a mark ghosts the ones a restore would take
foldedfalse
booleanthe thread starts folded to the marks alone (the head's toggle opens it)
onRewind–
(id: string, scopes: readonly Scope[]) => voidRestore pressed: the mark and what to restore of it
onUndo–
(id: string) => voidunder a restore that is the last mark: Undo puts it back as it was
busyfalse
booleanthe host is restoring: Restore spins and waits
error–
stringthe restore failed: why, in a few words, said in the well
localeDEFAULT_LOCALE
stringhow times read (en-US by default, never the viewer's)
timeZone–
stringthe zone times read in (the viewer's by default)
title–
React.ReactNodea heading in place of "Checkpoints" (a node, so a mark can sit in it)
labels–
Partial<CheckpointRailLabels>Three usesthe Assistant's document · an issue tracker's bulk edits · a run's history
Give your coding assistant the Markdown guide instead of screenshots.
https://notchset.dev/api/mcp (setup)One payment, lifetime.
v2.0.0 · 2026-10-13
Released with the Notchset system.