{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "guardrail-interlock-keys",
  "title": "Guardrail Interlock Keys",
  "description": "Output guardrails built as a trapped-key interlock: every policy gate holds one key, the release bolt only retracts when all of them are seated, and a tripped gate is a visibly empty, barred keyway rather than a red badge.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/guardrail-interlock-keys/component.tsx",
      "content": "\"use client\";\n\nimport {\n  useCallback,\n  useEffect,\n  useId,\n  useMemo,\n  useReducer,\n  useRef,\n  useState,\n} from \"react\";\n\n// ---------------------------------------------------------------------------\n// KeyInterlock — output guardrails drawn as a trapped-key interlock.\n//\n// Every policy gate physically holds one key. A gate that passed has its key\n// SEATED in its keyway; a gate still evaluating has an EMPTY keyway with a\n// breathing dashed outline; a gate that tripped has an empty keyway with a\n// solid bar drawn across it, so it cannot accept a key at all. Every state is\n// shape-coded — seated / empty-dashed / empty-barred — and there is no status\n// hue anywhere in the component, so it survives monochrome and both themes.\n//\n// Released keys travel to the RELEASE LOCK on the right. The lock's bolt only\n// retracts once every slot is filled; until then it stays shut across the\n// output port and the output panel below renders dimmed behind a diagonal\n// hatch. Overriding a tripped gate seats a HATCHED key instead of a solid one\n// and writes a permanent audit line — an overridden interlock stays visually\n// distinguishable from a passed one forever. That is the safety property.\n// ---------------------------------------------------------------------------\n\nexport type InterlockGateState = \"pending\" | \"released\" | \"tripped\";\n\nexport type InterlockGate = {\n  /** rule id, shown in Geist Mono and used in the audit line, e.g. \"pii_scan\" */\n  id: string;\n  label: string;\n  state: InterlockGateState;\n  /** one line shown in the mono strip while the gate is hovered or focused */\n  detail?: string;\n};\n\nexport interface KeyInterlockProps {\n  /** the interlock's rules, each independently tripped/released */\n  gates: InterlockGate[];\n  /** the model output the lock is holding */\n  output: string;\n  /** accessible name for the interlock group */\n  label?: string;\n  /** short caption above the row */\n  title?: string;\n  /** who is recorded on an override audit line */\n  operator?: string;\n  /** fired when a tripped gate is overridden — the owner flips that gate to\n   * \"released\" (this component never mutates the gates it was handed) */\n  onOverride?: (id: string) => void;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nconst GATE_W = 40;\nconst GATE_H = 54;\nconst LOCK_W = 88;\n/** keeps the slot run off the lock's own side walls, so the outermost slot is\n * never drawn half on top of the body outline */\nconst SLOT_INSET = 10;\nconst TRAVEL_MS = 420;\nconst TRAVEL_EASE = \"cubic-bezier(0.22,1,0.36,1)\";\n\ntype Flight = {\n  id: string;\n  x0: number;\n  y0: number;\n  x1: number;\n  y1: number;\n  hatched: boolean;\n  moved: boolean;\n};\n\nfunction stamp() {\n  return new Date().toLocaleTimeString(\"en-GB\", {\n    hour: \"2-digit\",\n    minute: \"2-digit\",\n    second: \"2-digit\",\n    hour12: false,\n  });\n}\n\nfunction stateWord(g: InterlockGate, overridden: boolean) {\n  if (g.state === \"released\")\n    return overridden ? \"released by override\" : \"key seated\";\n  if (g.state === \"tripped\") return \"tripped, keyway barred\";\n  return \"awaiting key\";\n}\n\n/** the key glyph: a 7px bit filling the keyway over a 3px stem */\nfunction KeyGlyph({\n  hatch,\n  patternId,\n}: {\n  hatch: boolean;\n  patternId: string;\n}) {\n  const fill = hatch ? `url(#${patternId})` : \"currentColor\";\n  return (\n    <>\n      <rect\n        x=\"0.5\"\n        y=\"0\"\n        width=\"7\"\n        height=\"8\"\n        fill={fill}\n        stroke={hatch ? \"currentColor\" : \"none\"}\n        strokeWidth={hatch ? 1 : 0}\n      />\n      <rect x=\"2.5\" y=\"8\" width=\"3\" height=\"18\" fill=\"currentColor\" />\n    </>\n  );\n}\n\nexport function KeyInterlock({\n  gates,\n  output,\n  label = \"Output guardrails\",\n  title = \"Output interlock\",\n  operator = \"operator\",\n  onOverride,\n  className = \"\",\n}: KeyInterlockProps) {\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const hatchId = `ns-ilk-hatch-${uid}`;\n\n  const rowRef = useRef<HTMLDivElement>(null);\n  const gateKeyRefs = useRef<Record<string, HTMLSpanElement | null>>({});\n  const lockSlotRefs = useRef<Record<string, HTMLSpanElement | null>>({});\n\n  // seeded from props so the very first paint (server and client alike) already\n  // shows the keys that are in, instead of flashing an empty lock\n  const arrivedRef = useRef<Set<string>>(\n    new Set(gates.filter((g) => g.state === \"released\").map((g) => g.id))\n  );\n  const inFlightRef = useRef<Set<string>>(new Set());\n  const overriddenRef = useRef<Set<string>>(new Set());\n  const announcedRef = useRef<Set<string>>(new Set());\n  const mountedRef = useRef(false);\n  const timersRef = useRef<number[]>([]);\n  const [, bump] = useReducer((n: number) => n + 1, 0);\n\n  const [flights, setFlights] = useState<Flight[]>([]);\n  const [audit, setAudit] = useState<string[]>([]);\n  const [activeId, setActiveId] = useState<string | null>(null);\n  const [announce, setAnnounce] = useState(\"\");\n  const [reduced, setReduced] = useState(false);\n\n  useEffect(() => {\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const sync = () => setReduced(mq.matches);\n    sync();\n    mq.addEventListener(\"change\", sync);\n    return () => mq.removeEventListener(\"change\", sync);\n  }, []);\n\n  useEffect(\n    () => () => {\n      timersRef.current.forEach((t) => window.clearTimeout(t));\n    },\n    []\n  );\n\n  const later = useCallback((fn: () => void, ms: number) => {\n    const t = window.setTimeout(fn, ms);\n    timersRef.current.push(t);\n  }, []);\n\n  const startFlight = useCallback(\n    (id: string) => {\n      const row = rowRef.current;\n      const from = gateKeyRefs.current[id];\n      const to = lockSlotRefs.current[id];\n      if (!row || !from || !to) {\n        arrivedRef.current.add(id);\n        bump();\n        return;\n      }\n      const r = row.getBoundingClientRect();\n      const a = from.getBoundingClientRect();\n      const b = to.getBoundingClientRect();\n      inFlightRef.current.add(id);\n      const flight: Flight = {\n        id,\n        x0: a.left - r.left,\n        y0: a.top - r.top,\n        x1: b.left - r.left,\n        y1: b.top - r.top,\n        hatched: overriddenRef.current.has(id),\n        moved: false,\n      };\n      setFlights((f) => [...f.filter((x) => x.id !== id), flight]);\n      requestAnimationFrame(() =>\n        requestAnimationFrame(() =>\n          setFlights((f) =>\n            f.map((x) => (x.id === id ? { ...x, moved: true } : x))\n          )\n        )\n      );\n      later(() => {\n        inFlightRef.current.delete(id);\n        arrivedRef.current.add(id);\n        setFlights((f) => f.filter((x) => x.id !== id));\n        bump();\n      }, TRAVEL_MS);\n    },\n    [later]\n  );\n\n  // reconcile the lock against the gates it was handed: a gate that reaches\n  // \"released\" sends its key across; a gate that leaves \"released\" (re-armed\n  // upstream) takes its key back out of the lock.\n  useEffect(() => {\n    let changed = false;\n    for (const g of gates) {\n      const arrived = arrivedRef.current.has(g.id);\n      const flying = inFlightRef.current.has(g.id);\n      if (g.state === \"released\" && !arrived && !flying) {\n        if (!mountedRef.current || reduced) {\n          arrivedRef.current.add(g.id);\n          changed = true;\n        } else {\n          startFlight(g.id);\n        }\n      }\n      if (g.state !== \"released\" && arrived) {\n        arrivedRef.current.delete(g.id);\n        changed = true;\n      }\n    }\n    mountedRef.current = true;\n    if (changed) bump();\n  }, [gates, reduced, startFlight]);\n\n  // announce each trip exactly once\n  useEffect(() => {\n    const fresh = gates.filter(\n      (g) => g.state === \"tripped\" && !announcedRef.current.has(g.id)\n    );\n    for (const g of gates) {\n      if (g.state !== \"tripped\") announcedRef.current.delete(g.id);\n    }\n    if (fresh.length === 0) return;\n    fresh.forEach((g) => announcedRef.current.add(g.id));\n    setAnnounce(\n      fresh.map((g) => `${g.id} tripped, output held`).join(\". \") + \".\"\n    );\n  }, [gates]);\n\n  useEffect(() => {\n    if (!activeId) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setActiveId(null);\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [activeId]);\n\n  const seated = gates.filter((g) => arrivedRef.current.has(g.id)).length;\n  const released = seated === gates.length && gates.length > 0;\n  const tripped = gates.filter((g) => g.state === \"tripped\");\n  const active = gates.find((g) => g.id === activeId) ?? null;\n\n  const slotXs = useMemo(() => {\n    const n = Math.max(gates.length, 1);\n    const step = (LOCK_W - SLOT_INSET * 2) / n;\n    return gates.map((_, i) => SLOT_INSET + step * (i + 0.5));\n  }, [gates]);\n\n  function override(g: InterlockGate) {\n    if (g.state !== \"tripped\") return;\n    overriddenRef.current.add(g.id);\n    // newest first, and the list is height-bounded rather than unbounded: an\n    // audit trail that grows the component's own box forever makes the card\n    // reframe on every entry. Nothing is ever dropped — it scrolls.\n    setAudit((a) => [`override ${g.id} · ${operator} · ${stamp()}`, ...a]);\n    setAnnounce(`${g.id} overridden by ${operator}`);\n    onOverride?.(g.id);\n  }\n\n  return (\n    <div\n      data-interlock\n      role=\"group\"\n      aria-label={label}\n      className={\"font-sans \" + className}\n    >\n      <style>{`\n.ns-ilk-breathe{animation:ns-ilk-breathe 3.2s ease-in-out infinite alternate}\n@keyframes ns-ilk-breathe{from{opacity:.45}to{opacity:1}}\n.ns-ilk-gate{transition:transform 180ms ease-out,opacity 180ms ease-out}\n.ns-ilk-strip{transition:opacity 180ms ease-out,transform 180ms ease-out}\n.ns-ilk-bolt{transition:transform ${TRAVEL_MS}ms cubic-bezier(0.34,1.8,0.64,1)}\n.ns-ilk-fly{transition:transform ${TRAVEL_MS}ms ${TRAVEL_EASE}}\n.ns-ilk-veil{transition:opacity 320ms ease-out}\n@media (prefers-reduced-motion: reduce){\n  .ns-ilk-breathe{animation:none;opacity:.75}\n  .ns-ilk-gate,.ns-ilk-strip,.ns-ilk-bolt,.ns-ilk-fly,.ns-ilk-veil{transition:none}\n}\n`}</style>\n\n      <div className=\"mb-4 flex items-end justify-between gap-4\">\n        <p className=\"font-mono text-[11px] uppercase tracking-[0.18em] text-ns-muted\">\n          {title}\n        </p>\n        <p\n          data-interlock-readout\n          className=\"shrink-0 font-mono text-[11px] text-foreground\"\n        >\n          {seated}/{gates.length} keys\n          <span className=\"px-1.5 text-ns-muted\">·</span>\n          {released ? \"output released\" : \"output held\"}\n        </p>\n      </div>\n\n      {/* ---- the interlock row ------------------------------------------ */}\n      <div\n        ref={rowRef}\n        data-interlock-row\n        className=\"relative flex items-start\"\n        onPointerLeave={() => setActiveId(null)}\n        onBlur={() => setActiveId(null)}\n      >\n        <div className=\"flex items-start gap-3\">\n          {gates.map((g, i) => {\n            const dim = activeId !== null && activeId !== g.id;\n            const lift = activeId === g.id;\n            const overridden = overriddenRef.current.has(g.id);\n            return (\n              <button\n                key={g.id}\n                type=\"button\"\n                data-interlock-gate={g.id}\n                data-state={g.state}\n                aria-label={`${g.label}: ${stateWord(g, overridden)}${\n                  g.detail ? `. ${g.detail}` : \"\"\n                }`}\n                onPointerEnter={() => setActiveId(g.id)}\n                onFocus={() => setActiveId(g.id)}\n                // a tap/click pins this gate's detail. Deliberately NOT a\n                // toggle: pointerenter has already set activeId, so toggling\n                // would blank the strip on the very click that asked for it.\n                onClick={() => setActiveId(g.id)}\n                className={\n                  \"ns-ilk-gate group flex w-16 flex-col items-center rounded-sm text-foreground focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-ns-accent \" +\n                  (dim ? \"opacity-30 \" : \"opacity-100 \") +\n                  (lift ? \"-translate-y-0.5\" : \"translate-y-0\")\n                }\n              >\n                <span className=\"relative block\">\n                  {/* keyway centre marker — the flight origin */}\n                  <span\n                    ref={(el) => {\n                      gateKeyRefs.current[g.id] = el;\n                    }}\n                    aria-hidden\n                    className=\"pointer-events-none absolute left-[16.5px] top-[3px] block h-0 w-0\"\n                  />\n                  <svg\n                    width={GATE_W}\n                    height={GATE_H}\n                    viewBox={`0 0 ${GATE_W} ${GATE_H}`}\n                    fill=\"none\"\n                    aria-hidden\n                    className=\"block text-foreground\"\n                  >\n                    <defs>\n                      <pattern\n                        id={`${hatchId}-${i}`}\n                        width=\"4\"\n                        height=\"4\"\n                        patternUnits=\"userSpaceOnUse\"\n                        patternTransform=\"rotate(45)\"\n                      >\n                        <rect\n                          width=\"2\"\n                          height=\"4\"\n                          fill=\"currentColor\"\n                          opacity=\"0.85\"\n                        />\n                      </pattern>\n                    </defs>\n                    {/* slot body with the keyway notch cut into its top edge */}\n                    <path\n                      d=\"M0.5 53.5 V0.5 H16.5 V14 H23.5 V0.5 H39.5 V53.5 Z\"\n                      className=\"stroke-border\"\n                      strokeWidth=\"1\"\n                    />\n                    {g.state === \"released\" ? (\n                      <g transform=\"translate(16,3.5)\">\n                        <KeyGlyph\n                          hatch={overridden}\n                          patternId={`${hatchId}-${i}`}\n                        />\n                      </g>\n                    ) : null}\n                    {g.state === \"pending\" ? (\n                      <rect\n                        className=\"ns-ilk-breathe stroke-foreground\"\n                        style={{ animationDelay: `${((i * 260) % 1040) - 520}ms` }}\n                        x=\"16.75\"\n                        y=\"2.75\"\n                        width=\"6.5\"\n                        height=\"10.5\"\n                        strokeWidth=\"1.5\"\n                        strokeDasharray=\"2 2\"\n                        fill=\"none\"\n                      />\n                    ) : null}\n                    {g.state === \"tripped\" ? (\n                      <line\n                        x1=\"8\"\n                        y1=\"18\"\n                        x2=\"32\"\n                        y2=\"4.1\"\n                        className=\"stroke-foreground\"\n                        strokeWidth=\"2\"\n                        strokeLinecap=\"round\"\n                      />\n                    ) : null}\n                  </svg>\n                </span>\n                <span\n                  className={\n                    \"mt-2 block w-full break-all text-center font-mono text-[10px] leading-[1.15] \" +\n                    (g.state === \"tripped\"\n                      ? \"font-medium text-foreground\"\n                      : \"text-ns-muted\")\n                  }\n                  title={g.id}\n                >\n                  {g.id}\n                </span>\n              </button>\n            );\n          })}\n        </div>\n\n        {/* rail from the gates to the lock */}\n        <div className=\"relative mx-3 h-[54px] w-8 shrink-0\" aria-hidden>\n          <div className=\"absolute inset-x-0 top-[9px] h-px bg-border\" />\n        </div>\n\n        {/* ---- the release lock ----------------------------------------- */}\n        <div className=\"flex shrink-0 flex-col items-center\">\n          <span className=\"relative block\">\n            {gates.map((g, i) => (\n              <span\n                key={g.id}\n                ref={(el) => {\n                  lockSlotRefs.current[g.id] = el;\n                }}\n                aria-hidden\n                className=\"pointer-events-none absolute top-[8px] block h-0 w-0\"\n                style={{ left: `${slotXs[i] - 3.5}px` }}\n              />\n            ))}\n            <svg\n              width={LOCK_W}\n              height={GATE_H}\n              viewBox={`0 0 ${LOCK_W} ${GATE_H}`}\n              fill=\"none\"\n              aria-hidden\n              className=\"block text-foreground\"\n            >\n              <defs>\n                <pattern\n                  id={`${hatchId}-lock`}\n                  width=\"4\"\n                  height=\"4\"\n                  patternUnits=\"userSpaceOnUse\"\n                  patternTransform=\"rotate(45)\"\n                >\n                  <rect width=\"2\" height=\"4\" fill=\"currentColor\" opacity=\"0.85\" />\n                </pattern>\n              </defs>\n              {/* lock body, open at the bottom where the output port is */}\n              <path\n                d=\"M32.5 53.5 H0.5 V0.5 H87.5 V53.5 H55.5\"\n                className=\"stroke-border\"\n                strokeWidth=\"1\"\n              />\n              {gates.map((g, i) => {\n                const filled = arrivedRef.current.has(g.id);\n                const overridden = overriddenRef.current.has(g.id);\n                return (\n                  <rect\n                    key={g.id}\n                    data-lock-slot={g.id}\n                    data-filled={filled ? \"true\" : \"false\"}\n                    x={slotXs[i] - 3.5}\n                    y=\"8\"\n                    width=\"7\"\n                    height=\"12\"\n                    fill={\n                      filled\n                        ? overridden\n                          ? `url(#${hatchId}-lock)`\n                          : \"currentColor\"\n                        : \"none\"\n                    }\n                    className={filled ? \"stroke-foreground\" : \"stroke-border\"}\n                    strokeWidth=\"1\"\n                  />\n                );\n              })}\n              {/* the bolt: shut across the output port until every key is in */}\n              <rect\n                data-interlock-bolt\n                data-retracted={released ? \"true\" : \"false\"}\n                className=\"ns-ilk-bolt fill-current\"\n                x=\"33\"\n                y=\"44\"\n                width=\"22\"\n                height=\"6\"\n                rx=\"1\"\n                style={{\n                  transform: released ? \"translateX(20px)\" : \"translateX(0)\",\n                }}\n              />\n            </svg>\n          </span>\n          <span className=\"mt-2 block font-mono text-[9px] leading-none text-ns-muted\">\n            release lock\n          </span>\n        </div>\n\n        {/* ---- key travel overlay --------------------------------------- */}\n        <div className=\"pointer-events-none absolute inset-0\" aria-hidden>\n          {flights.length > 0 ? (\n            <svg className=\"absolute inset-0 h-full w-full\" fill=\"none\">\n              {flights.map((f) => (\n                <line\n                  key={f.id}\n                  x1={f.x0 + 4}\n                  y1={f.y0 + 4}\n                  x2={f.x1 + 4}\n                  y2={f.y1 + 4}\n                  className=\"stroke-border\"\n                  strokeWidth=\"1\"\n                />\n              ))}\n            </svg>\n          ) : null}\n          {flights.map((f) => (\n            <svg\n              key={f.id}\n              width=\"8\"\n              height=\"26\"\n              viewBox=\"0 0 8 26\"\n              fill=\"none\"\n              className=\"ns-ilk-fly absolute left-0 top-0 text-foreground\"\n              style={{\n                transform: f.moved\n                  ? `translate(${f.x1}px, ${f.y1}px)`\n                  : `translate(${f.x0}px, ${f.y0}px)`,\n              }}\n            >\n              <defs>\n                <pattern\n                  id={`${hatchId}-fly-${f.id}`}\n                  width=\"4\"\n                  height=\"4\"\n                  patternUnits=\"userSpaceOnUse\"\n                  patternTransform=\"rotate(45)\"\n                >\n                  <rect width=\"2\" height=\"4\" fill=\"currentColor\" opacity=\"0.85\" />\n                </pattern>\n              </defs>\n              <KeyGlyph\n                hatch={f.hatched}\n                patternId={`${hatchId}-fly-${f.id}`}\n              />\n            </svg>\n          ))}\n        </div>\n      </div>\n\n      {/* ---- detail strip ------------------------------------------------ */}\n      <div\n        id={`${uid}-strip`}\n        className=\"ns-ilk-strip mt-4 h-[16px] font-mono text-[11px] leading-[16px] text-ns-muted\"\n        style={{\n          opacity: active ? 1 : 0,\n          transform: active ? \"translateY(0)\" : \"translateY(-2px)\",\n        }}\n      >\n        {active ? (\n          <>\n            <span className=\"text-foreground\">{active.id}</span>\n            <span className=\"px-1.5\">·</span>\n            {active.detail ?? stateWord(active, overriddenRef.current.has(active.id))}\n          </>\n        ) : null}\n      </div>\n\n      {/* ---- override controls ------------------------------------------- */}\n      {tripped.length > 0 ? (\n        <div className=\"mt-3 flex flex-wrap gap-2\">\n          {tripped.map((g) => (\n            <button\n              key={g.id}\n              type=\"button\"\n              data-override={g.id}\n              onClick={() => override(g)}\n              className=\"rounded-sm border border-border px-2.5 py-1 font-mono text-[11px] uppercase tracking-wide text-foreground transition-colors hover:bg-surface focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ns-accent\"\n            >\n              override {g.id}\n            </button>\n          ))}\n        </div>\n      ) : null}\n\n      {/* ---- the held output --------------------------------------------- */}\n      <div className=\"relative mt-5\">\n        <div\n          className=\"ns-ilk-veil rounded-md border border-border bg-surface p-4\"\n          style={{ opacity: released ? 1 : 0.35 }}\n        >\n          <p className=\"mb-2 font-mono text-[10px] uppercase tracking-[0.18em] text-ns-muted\">\n            model output\n          </p>\n          <p className=\"text-sm leading-relaxed text-foreground\">{output}</p>\n        </div>\n        <div\n          aria-hidden\n          className=\"ns-ilk-veil pointer-events-none absolute inset-0 rounded-md\"\n          style={{\n            opacity: released ? 0 : 1,\n            backgroundImage:\n              \"repeating-linear-gradient(45deg, color-mix(in srgb, var(--foreground) 8%, transparent) 0 1px, transparent 1px 4px)\",\n          }}\n        />\n      </div>\n\n      {/* ---- permanent audit trail --------------------------------------- */}\n      {audit.length > 0 ? (\n        <div className=\"mt-4 border-t border-border pt-3\">\n          <p className=\"mb-1.5 font-mono text-[10px] uppercase tracking-[0.18em] text-ns-muted\">\n            audit\n          </p>\n          {/* exactly three 17px lines + two 4px gaps — a partial clipped line\n              would read as a rendering bug rather than a scroll affordance */}\n          <ul className=\"max-h-[59px] space-y-1 overflow-y-auto\">\n            {audit.map((line, i) => (\n              <li\n                key={i}\n                data-audit-line\n                className=\"font-mono text-[11px] text-foreground\"\n              >\n                {line}\n              </li>\n            ))}\n          </ul>\n        </div>\n      ) : null}\n\n      <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n        {announce}\n      </p>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/guardrail-interlock-keys.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-ns-accent": "var(--ns-accent)",
      "color-surface": "var(--surface)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "ns-accent": "#006bff",
      "surface": "#fafafa"
    },
    "dark": {
      "ns-muted": "#8f8f8f",
      "surface": "#171717"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "agent",
      "llm",
      "guardrail",
      "policy",
      "safety",
      "interlock",
      "approval",
      "mono",
      "status",
      "accessibility"
    ],
    "instruction": "`<KeyInterlock gates={InterlockGate[]} output label? title? operator? onOverride? className? />` renders a set of output guardrails as a mechanical trapped-key interlock instead of a row of coloured status badges. Each gate is `{ id, label, state: 'pending' | 'released' | 'tripped', detail? }` and draws as a 40x54 SVG slot: a 1px `stroke-border` outline path with a 7px-wide keyway notch physically cut into its top edge (`M0.5 53.5 V0.5 H16.5 V14 H23.5 V0.5 H39.5 V53.5 Z`), so the shape itself says 'this slot takes a key'. STATE IS ENTIRELY SHAPE-CODED, never hue-coded — there is no status colour anywhere in the component, so it reads identically in monochrome and in both themes. RELEASED draws the key SEATED: a 7x8 bit filling the keyway over a 3px stem running 18px down into the slot body, solid `currentColor` (`--foreground`). PENDING draws the keyway EMPTY with a 1.5px `stroke-dasharray='2 2'` outline breathing opacity 0.45 -> 1 on a 3.2s ease-in-out infinite alternate keyframe, each gate offset by a deterministic index-derived `animationDelay` of `((i * 260) % 1040) - 520` ms (a -520..+260ms spread in 260ms steps) so the row does not pulse in lockstep — this is the only ambient motion in the piece. TRIPPED draws the keyway empty AND physically obstructed: a 2px `--foreground` line from (8,18) to (32,4.1), i.e. a bar raked at 30 degrees across the notch, so the slot visibly cannot accept a key; the rule id sits beneath every gate in Geist Mono and goes to full `--foreground` medium weight on the tripped one. To the right, past a 1px `--border` rail, sits the RELEASE LOCK: an 88x54 body whose outline path deliberately leaves a 23px gap in its bottom edge (`M32.5 53.5 H0.5 V0.5 H87.5 V53.5 H55.5`) — that gap is the output port. The lock carries one 7x12 slot per gate across its top, evenly spaced at `SLOT_INSET + (LOCK_W - 2*SLOT_INSET) / n * (i + 0.5)` with `SLOT_INSET = 10` so the run keeps clear of the body's own side walls and the slots read as separate keyholes rather than one filled bar, outlined in `--border` when empty and filled solid `--foreground` when its key has arrived. KEY TRAVEL: a gate that reaches 'released' after mount launches a key glyph from its own keyway to its slot in the lock — measured live against the row's bounding box via two zero-size marker spans (one at the keyway, one at the lock slot), rendered in a `pointer-events-none` overlay, and translated over 420ms on `cubic-bezier(0.22,1,0.36,1)` with a 1px `--border` guide line drawn along the same path for the duration; on arrival the flight unmounts and the lock slot fills. Gates that are already 'released' at mount seat instantly with no flight, and a gate the owner re-arms out of 'released' takes its key back out of the lock. THE BOLT is a 22x6 bar sitting across the output port; it is rendered retracted (`translateX(20px)`, on a 420ms `cubic-bezier(0.34,1.8,0.64,1)` that genuinely overshoots ~3px before settling) ONLY when `seatedCount === gates.length`, and extended across the port otherwise. While the bolt is shut the output panel below renders at 0.35 opacity behind a 4px-pitch 45-degree diagonal hatch built as a `repeating-linear-gradient` of `color-mix(in srgb, var(--foreground) 8%, transparent)`; both the dim and the hatch lift over 320ms once the bolt retracts. A Geist Mono readout above the row states the count and the consequence in one line: '3/5 keys · output held'. OVERRIDE is a real `<button>` per tripped gate, labelled 'override <ruleId>' in mono with a visible `--ns-accent` focus ring; pressing it records the gate in an internal overridden set and seats a HATCHED key — an SVG `pattern` of 2px diagonal stripes at 45 degrees instead of a solid bit, in both the gate keyway and the lock slot — and pushes a permanent audit line ('override pii_scan · n.sapalidis · 14:02:31') that no prop, press or re-arm ever clears. The trail is newest-first inside a 59px `overflow-y-auto` list (exactly three 17px lines plus their two 4px gaps, so no line is ever half-clipped) — every entry is kept, but the component's own box stops growing after the third one, so a repeatedly-overridden interlock does not slowly reframe the layout around it. An overridden interlock therefore stays visually distinguishable from a genuinely passed one for the life of the component, which is the actual safety property being modelled. The component is controlled: it never mutates the `gates` array it is handed, it calls `onOverride(id)` and lets the owner decide what the gate becomes. INTERACTION: hovering (or keyboard-focusing) a gate lifts it 2px, holds it at full alpha, drops every other gate to 0.3 opacity and reveals that gate's `detail` in a fixed-height Geist Mono strip under the row, all on 180ms ease-out; `pointerleave` on the group relaxes all of it on the same timing, and Escape dismisses the strip. Each gate is itself a real `<button>` carrying an `aria-label` that spells out label, state and detail, so a keyboard user gets in one string exactly what a hover reveals in the strip; `focusout` on the row clears the strip and the dimming, so tabbing past the last gate leaves nothing stale behind. ACCESSIBILITY: the whole component is a `role=group` with an accessible name; a visually-hidden `role=status`/`aria-live=polite` region announces each trip exactly once ('pii_scan tripped, output held') and each override as it happens, rather than chattering on every render; every focusable control carries a 2px `--ns-accent` focus ring (offset 4px on the gates so it clears the lifted slot, 2px on the override buttons); the SVGs are `aria-hidden` decorations sitting behind text that already carries the semantics. REDUCED MOTION (`matchMedia` with a live change listener, plus a CSS `prefers-reduced-motion: reduce` block) makes key travel and bolt retraction instant, drops the pending breathe to a static 0.75 opacity dashed outline, and removes the hover and hatch transitions — every state stays fully legible, just static. Colours are `--background --foreground --ns-muted --border --surface --ns-accent` only, via Tailwind token classes and `currentColor`; `--ns-accent` appears solely as the focus ring. DOM + SVG + CSS, no canvas, zero dependencies."
  },
  "type": "registry:ui"
}