{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slash-commands",
  "title": "Slash commands",
  "description": "Skill and workflow command palette triggered by typing / in an AI composer: filter /plan, /review, /compact, /test and /pr with keyboard navigation and argument hints.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/components/slash-commands.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useMemo, useRef, useState, type KeyboardEvent } from \"react\";\nimport { Check, Compass, FlaskConical, GitPullRequest, Minimize2, ScanSearch, Sparkles, Terminal, X } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type SlashCommandParam = { name: string; optional?: boolean; hint: string };\n\nexport type SlashCommandItem = {\n  command: string;\n  argsHint?: string;\n  description: string;\n  category?: \"workflow\" | \"context\" | \"skill\";\n  params?: SlashCommandParam[];\n};\n\nexport type SlashCommandsProps = {\n  commands?: SlashCommandItem[];\n  placeholder?: string;\n  /** Called with the command and the argument text typed after it. */\n  onRun?: (command: SlashCommandItem, args: string) => void;\n  /** Loop a scripted pick → fill args → run demo. */\n  autoPlay?: boolean;\n  className?: string;\n};\n\nconst DEFAULT_COMMANDS: SlashCommandItem[] = [\n  {\n    command: \"/plan\",\n    argsHint: \"<goal>\",\n    description: \"Draft a step-by-step plan before editing files\",\n    category: \"workflow\",\n    params: [{ name: \"goal\", hint: \"What should be true when the plan is done\" }],\n  },\n  {\n    command: \"/test\",\n    argsHint: \"[pattern]\",\n    description: \"Run affected tests and fix failing assertions\",\n    category: \"workflow\",\n    params: [{ name: \"pattern\", optional: true, hint: \"Glob or test name · defaults to changed files\" }],\n  },\n  {\n    command: \"/review\",\n    argsHint: \"[branch]\",\n    description: \"Audit the diff for bugs, security and regressions\",\n    category: \"skill\",\n    params: [\n      { name: \"branch\", optional: true, hint: \"Compare against · defaults to the base branch\" },\n      { name: \"--strict\", optional: true, hint: \"Also flag style and naming issues\" },\n    ],\n  },\n  {\n    command: \"/pr\",\n    argsHint: \"[title]\",\n    description: \"Commit, write a summary and open a pull request\",\n    category: \"skill\",\n    params: [{ name: \"title\", optional: true, hint: \"Leave empty to generate one from the diff\" }],\n  },\n  {\n    command: \"/compact\",\n    argsHint: \"[focus]\",\n    description: \"Summarize earlier turns to free the context window\",\n    category: \"context\",\n    params: [{ name: \"focus\", optional: true, hint: \"What the summary should keep in detail\" }],\n  },\n];\n\nconst GROUPS: { id: NonNullable<SlashCommandItem[\"category\"]>; label: string; tone: string }[] = [\n  { id: \"workflow\", label: \"Workflow\", tone: \"bg-sky-500\" },\n  { id: \"skill\", label: \"Skill\", tone: \"bg-violet-500\" },\n  { id: \"context\", label: \"Context\", tone: \"bg-amber-500\" },\n];\n\nconst ICONS: Record<string, typeof Compass> = {\n  \"/plan\": Compass,\n  \"/test\": FlaskConical,\n  \"/review\": ScanSearch,\n  \"/pr\": GitPullRequest,\n  \"/compact\": Minimize2,\n};\n\nconst EASE = [0.22, 1, 0.36, 1] as const;\nconst TICK = 100;\nconst LOOP = 9400;\n\nfunction useDemoClock(enabled: boolean, loop: number) {\n  const ref = useRef<HTMLDivElement>(null);\n  const [visible, setVisible] = useState(false);\n  const [elapsed, setElapsed] = useState(0);\n  useEffect(() => {\n    const el = ref.current;\n    if (!el || !enabled) return;\n    const io = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));\n    io.observe(el);\n    return () => io.disconnect();\n  }, [enabled]);\n  useEffect(() => {\n    if (!enabled || !visible) return;\n    const id = setInterval(() => setElapsed((e) => e + TICK), TICK);\n    return () => clearInterval(id);\n  }, [enabled, visible]);\n  return { ref, t: elapsed % loop };\n}\n\ntype Phase = \"pick\" | \"args\" | \"running\" | \"done\";\ntype View = { input: string; active: number; chosen: string | null; phase: Phase; progress: number };\n\nfunction typed(str: string, t: number, start: number, per: number) {\n  if (t < start) return \"\";\n  return str.slice(0, Math.min(str.length, Math.floor((t - start) / per) + 1));\n}\n\nfunction demoView(t: number): View {\n  if (t < 3000) {\n    const q = typed(\"re\", t, 2300, 220);\n    return { input: `/${q}`, active: q ? 0 : t >= 1700 ? 1 : t >= 1200 ? 2 : t >= 700 ? 1 : 0, chosen: null, phase: \"pick\", progress: 0 };\n  }\n  const args = typed(\"main\", t, 3700, 140);\n  if (t < 4900) return { input: `/review ${args}`, active: 0, chosen: \"/review\", phase: \"args\", progress: 0 };\n  if (t < 7000) return { input: \"/review main\", active: 0, chosen: \"/review\", phase: \"running\", progress: Math.min(1, (t - 4900) / 1900) };\n  return { input: \"/review main\", active: 0, chosen: \"/review\", phase: \"done\", progress: 1 };\n}\n\nfunction filter(commands: SlashCommandItem[], input: string) {\n  const q = input.replace(/^\\//, \"\").split(/\\s/)[0].toLowerCase();\n  if (!q) return commands;\n  const byName = commands.filter((c) => c.command.slice(1).toLowerCase().includes(q));\n  if (byName.length) return byName.sort((a, b) => Number(!a.command.startsWith(`/${q}`)) - Number(!b.command.startsWith(`/${q}`)));\n  return commands.filter((c) => new RegExp(`\\\\b${q.replace(/[^a-z0-9]/g, \"\")}`, \"i\").test(c.description));\n}\n\n/** \"/\" command palette for a prompt box: grouped skills and workflows with argument hints, type badges and keyboard navigation. */\nexport function SlashCommands({\n  commands = DEFAULT_COMMANDS,\n  placeholder = \"Type / for commands\",\n  onRun,\n  autoPlay = false,\n  className,\n}: SlashCommandsProps) {\n  const reduce = useReducedMotion() ?? false;\n  const uid = useId();\n  const [touched, setTouched] = useState(false);\n  const [focused, setFocused] = useState(false);\n  const [view, setView] = useState<View>({ input: \"/\", active: 0, chosen: null, phase: \"pick\", progress: 0 });\n  const demo = autoPlay && !reduce && !touched;\n  const { ref, t } = useDemoClock(demo, LOOP);\n  const runTimer = useRef<ReturnType<typeof setInterval> | null>(null);\n\n  // Sync the scripted frame during render (no effect → no extra commit per tick).\n  const [syncedT, setSyncedT] = useState(-1);\n  if (demo && t !== syncedT) {\n    setSyncedT(t);\n    setView(demoView(t));\n  }\n  useEffect(() => () => {\n    if (runTimer.current) clearInterval(runTimer.current);\n  }, []);\n\n  const filtered = useMemo(() => filter(commands, view.input), [commands, view.input]);\n  const ordered = useMemo(\n    () => GROUPS.flatMap((g) => filtered.filter((c) => (c.category ?? \"workflow\") === g.id)),\n    [filtered],\n  );\n  const chosen = commands.find((c) => c.command === view.chosen) ?? null;\n  const args = chosen ? view.input.slice(chosen.command.length).trimStart() : \"\";\n\n  const pick = (cmd: SlashCommandItem) => {\n    setTouched(true);\n    setView({ input: `${cmd.command} `, active: 0, chosen: cmd.command, phase: \"args\", progress: 0 });\n  };\n\n  const run = () => {\n    if (!chosen) return;\n    setTouched(true);\n    onRun?.(chosen, args);\n    if (runTimer.current) clearInterval(runTimer.current);\n    setView((v) => ({ ...v, phase: \"running\", progress: 0 }));\n    runTimer.current = setInterval(() => {\n      setView((v) => {\n        const progress = Math.min(1, v.progress + 0.06);\n        if (progress >= 1 && runTimer.current) clearInterval(runTimer.current);\n        return { ...v, progress, phase: progress >= 1 ? \"done\" : \"running\" };\n      });\n    }, 100);\n  };\n\n  const reset = () => {\n    setTouched(true);\n    if (runTimer.current) clearInterval(runTimer.current);\n    setView({ input: \"/\", active: 0, chosen: null, phase: \"pick\", progress: 0 });\n  };\n\n  const onChange = (value: string) => {\n    setTouched(true);\n    if (chosen && value.startsWith(chosen.command)) return setView((v) => ({ ...v, input: value }));\n    setView({ input: value, active: 0, chosen: null, phase: \"pick\", progress: 0 });\n  };\n\n  const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"Escape\") return reset();\n    if (view.phase === \"args\" && e.key === \"Enter\") {\n      e.preventDefault();\n      return run();\n    }\n    if (view.phase !== \"pick\" || !ordered.length) return;\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      const d = e.key === \"ArrowDown\" ? 1 : -1;\n      setTouched(true);\n      setView((v) => ({ ...v, active: (v.active + d + ordered.length) % ordered.length }));\n    } else if (e.key === \"Enter\" || e.key === \"Tab\") {\n      e.preventDefault();\n      const target = ordered[view.active];\n      if (target) pick(target);\n    }\n  };\n\n  const ghost = chosen && view.phase === \"args\" && !args ? chosen.argsHint : null;\n  const listId = `${uid}-list`;\n  const Icon = chosen ? (ICONS[chosen.command] ?? Sparkles) : Terminal;\n\n  return (\n    <div ref={ref} className={cn(\"w-full max-w-md text-sm\", className)}>\n      <div className=\"overflow-hidden rounded-2xl border bg-card text-card-foreground shadow-[0_1px_2px_rgb(0_0_0/0.04),0_12px_32px_-18px_rgb(0_0_0/0.25)]\">\n        {/* Prompt line */}\n        <div className=\"flex items-center gap-2.5 bg-gradient-to-b from-muted/50 to-transparent px-3.5 py-3\">\n          <motion.span\n            key={chosen?.command ?? \"none\"}\n            initial={reduce ? false : { scale: 0.6, rotate: -20, opacity: 0 }}\n            animate={{ scale: 1, rotate: 0, opacity: 1 }}\n            transition={{ type: \"spring\", stiffness: 500, damping: 22 }}\n            className={cn(\n              \"grid size-7 shrink-0 place-items-center rounded-lg border shadow-xs\",\n              chosen ? \"border-foreground bg-foreground text-background\" : \"bg-background text-muted-foreground\",\n            )}\n          >\n            <Icon className=\"size-3.5\" aria-hidden />\n          </motion.span>\n          <div className=\"relative min-w-0 flex-1\">\n            <input\n              type=\"text\"\n              role=\"combobox\"\n              aria-expanded={view.phase === \"pick\"}\n              aria-controls={listId}\n              aria-activedescendant={view.phase === \"pick\" && ordered[view.active] ? `${uid}-${ordered[view.active].command.slice(1)}` : undefined}\n              value={view.input}\n              onChange={(e) => onChange(e.target.value)}\n              onKeyDown={onKeyDown}\n              onFocus={() => setFocused(true)}\n              onBlur={() => setFocused(false)}\n              placeholder={placeholder}\n              className={cn(\n                \"w-full bg-transparent font-mono text-[13px] outline-none placeholder:font-sans placeholder:text-muted-foreground\",\n                !focused && demo && \"text-transparent\",\n              )}\n            />\n            <span\n              className={cn(\"pointer-events-none absolute inset-0 overflow-hidden font-mono text-[13px] whitespace-pre\", focused || !demo ? \"text-transparent\" : \"\")}\n              aria-hidden\n            >\n              {chosen ? (\n                <>\n                  <span className=\"font-semibold\">{chosen.command}</span>\n                  {view.input.slice(chosen.command.length)}\n                </>\n              ) : (\n                view.input\n              )}\n              {!focused && demo && <span className=\"sc-caret ml-px inline-block h-[1.05em] w-[1.5px] translate-y-[2px] bg-foreground\" />}\n              {ghost && <span className=\"text-muted-foreground/60\">{ghost}</span>}\n            </span>\n          </div>\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            {view.phase === \"pick\" ? (\n              <motion.span key=\"kbd\" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} className=\"hidden shrink-0 gap-1 sm:flex\">\n                <Kbd>↑↓</Kbd>\n                <Kbd>↵</Kbd>\n              </motion.span>\n            ) : (\n              <motion.button\n                key=\"clear\"\n                type=\"button\"\n                aria-label=\"Clear command\"\n                onClick={reset}\n                initial={{ opacity: 0, scale: 0.8 }}\n                animate={{ opacity: 1, scale: 1 }}\n                exit={{ opacity: 0, scale: 0.8 }}\n                className=\"grid size-6 shrink-0 cursor-pointer place-items-center rounded-md text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n              >\n                <X className=\"size-3.5\" aria-hidden />\n              </motion.button>\n            )}\n          </AnimatePresence>\n        </div>\n\n        <AnimatePresence mode=\"wait\" initial={false}>\n          {view.phase === \"pick\" ? (\n            <motion.ul\n              key=\"list\"\n              id={listId}\n              role=\"listbox\"\n              initial={reduce ? false : { opacity: 0, y: 6 }}\n              animate={{ opacity: 1, y: 0 }}\n              exit={reduce ? undefined : { opacity: 0, y: -6, filter: \"blur(2px)\" }}\n              transition={{ duration: 0.25, ease: EASE }}\n              className=\"border-t p-1.5\"\n            >\n              {GROUPS.map((g) => {\n                const items = ordered.filter((c) => (c.category ?? \"workflow\") === g.id);\n                if (!items.length) return null;\n                return (\n                  <li key={g.id} role=\"presentation\">\n                    <p className=\"flex items-center gap-1.5 px-2 pt-1.5 pb-1 font-mono text-[10px] tracking-wide text-muted-foreground uppercase\">\n                      <span className={cn(\"size-1.5 rounded-full\", g.tone)} />\n                      {g.label}\n                    </p>\n                    <ul role=\"presentation\" className=\"space-y-px\">\n                      {items.map((item) => {\n                        const idx = ordered.indexOf(item);\n                        const on = idx === view.active;\n                        const ItemIcon = ICONS[item.command] ?? Sparkles;\n                        return (\n                          <li key={item.command} id={`${uid}-${item.command.slice(1)}`} role=\"option\" aria-selected={on}>\n                            <button\n                              type=\"button\"\n                              tabIndex={-1}\n                              onMouseDown={(e) => e.preventDefault()}\n                              onMouseEnter={() => setView((v) => ({ ...v, active: idx }))}\n                              onClick={() => pick(item)}\n                              className=\"relative flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2 py-1.5 text-left text-xs outline-none\"\n                            >\n                              {on && (\n                                <motion.span\n                                  layoutId={`${uid}-active`}\n                                  className=\"absolute inset-0 rounded-lg bg-muted\"\n                                  transition={{ type: \"spring\", stiffness: 600, damping: 40 }}\n                                />\n                              )}\n                              <span className={cn(\"relative grid size-7 shrink-0 place-items-center rounded-md border bg-background transition-colors\", on && \"border-foreground/25 text-foreground\")}>\n                                <ItemIcon className={cn(\"size-3.5\", on ? \"text-foreground\" : \"text-muted-foreground\")} aria-hidden />\n                              </span>\n                              <span className=\"relative min-w-0 flex-1\">\n                                <span className=\"flex items-baseline gap-1.5\">\n                                  <span className=\"font-mono font-semibold\">{item.command}</span>\n                                  {item.argsHint && <span className=\"font-mono text-[10px] text-muted-foreground\">{item.argsHint}</span>}\n                                </span>\n                                <span className=\"block truncate text-[11px] text-muted-foreground\">{item.description}</span>\n                              </span>\n                              <motion.span\n                                animate={{ opacity: on ? 1 : 0, x: on ? 0 : -4 }}\n                                transition={{ duration: 0.18 }}\n                                className=\"relative shrink-0\"\n                              >\n                                <Kbd>↵</Kbd>\n                              </motion.span>\n                            </button>\n                          </li>\n                        );\n                      })}\n                    </ul>\n                  </li>\n                );\n              })}\n              {ordered.length === 0 && <li className=\"px-3 py-6 text-center text-xs text-muted-foreground\">No command matches “{view.input}”</li>}\n            </motion.ul>\n          ) : (\n            chosen && (\n              <motion.div\n                key=\"detail\"\n                initial={reduce ? false : { opacity: 0, y: 8, filter: \"blur(2px)\" }}\n                animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n                exit={reduce ? undefined : { opacity: 0, y: -6 }}\n                transition={{ duration: 0.3, ease: EASE }}\n                className=\"border-t\"\n              >\n                <div className=\"px-4 pt-3 pb-1\">\n                  <div className=\"flex items-center gap-2\">\n                    <span className=\"font-mono text-xs font-semibold\">{chosen.command}</span>\n                    <TypeBadge category={chosen.category ?? \"workflow\"} />\n                  </div>\n                  <p className=\"mt-1 text-xs text-muted-foreground\">{chosen.description}</p>\n                </div>\n                <dl className=\"mx-3 mt-2 divide-y rounded-xl border bg-background\">\n                  {(chosen.params ?? []).map((p, i) => {\n                    const filled = i === 0 && !!args;\n                    return (\n                      <motion.div\n                        key={p.name}\n                        initial={reduce ? false : { opacity: 0, x: -6 }}\n                        animate={{ opacity: 1, x: 0 }}\n                        transition={{ delay: 0.08 + i * 0.06, duration: 0.3, ease: EASE }}\n                        className=\"flex items-start gap-3 px-3 py-2 text-xs\"\n                      >\n                        <dt className=\"w-20 shrink-0 font-mono text-[11px]\">\n                          {p.name}\n                          {p.optional && <span className=\"text-muted-foreground\">?</span>}\n                        </dt>\n                        <dd className=\"min-w-0 flex-1 text-[11px] text-muted-foreground\">\n                          {filled ? (\n                            <motion.span\n                              key={args}\n                              initial={reduce ? false : { opacity: 0.4 }}\n                              animate={{ opacity: 1 }}\n                              className=\"inline-flex items-center gap-1 rounded bg-foreground/[0.07] px-1 font-mono text-foreground\"\n                            >\n                              {args.split(/\\s/)[0]}\n                            </motion.span>\n                          ) : (\n                            p.hint\n                          )}\n                        </dd>\n                      </motion.div>\n                    );\n                  })}\n                </dl>\n                <div className=\"flex h-12 items-center gap-3 px-4\">\n                  <AnimatePresence mode=\"popLayout\" initial={false}>\n                    {view.phase === \"args\" ? (\n                      <motion.div key=\"args\" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} className=\"flex flex-1 items-center justify-between gap-2\">\n                        <span className=\"text-[11px] text-muted-foreground\">\n                          <Kbd>↵</Kbd> run · <Kbd>esc</Kbd> cancel\n                        </span>\n                        <button\n                          type=\"button\"\n                          onClick={run}\n                          className=\"h-7 cursor-pointer rounded-md bg-foreground px-3 text-xs font-medium text-background outline-none hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2\"\n                        >\n                          Run {chosen.command}\n                        </button>\n                      </motion.div>\n                    ) : (\n                      <motion.div\n                        key=\"run\"\n                        role=\"status\"\n                        initial={{ opacity: 0, y: 6 }}\n                        animate={{ opacity: 1, y: 0 }}\n                        exit={{ opacity: 0 }}\n                        className=\"flex flex-1 items-center gap-2.5 text-xs\"\n                      >\n                        <span\n                          className={cn(\n                            \"grid size-5 shrink-0 place-items-center rounded-full transition-colors duration-300\",\n                            view.phase === \"done\" ? \"bg-emerald-500 text-white\" : \"bg-muted\",\n                          )}\n                        >\n                          {view.phase === \"done\" ? (\n                            <motion.span initial={reduce ? false : { scale: 0 }} animate={{ scale: 1 }} transition={{ type: \"spring\", stiffness: 600, damping: 15 }}>\n                              <Check className=\"size-3\" strokeWidth={3} aria-hidden />\n                            </motion.span>\n                          ) : (\n                            <span className={cn(\"size-2.5 rounded-full border-[1.5px] border-foreground/30 border-t-foreground\", !reduce && \"animate-spin\")} />\n                          )}\n                        </span>\n                        <span className=\"min-w-0 flex-1\">\n                          <span className=\"block truncate font-medium\">\n                            {view.phase === \"done\" ? `${chosen.command} finished · 3 findings in 2 files` : `Running ${chosen.command}${args ? ` ${args}` : \"\"}…`}\n                          </span>\n                          <span className=\"mt-1 block h-1 overflow-hidden rounded-full bg-muted\">\n                            <motion.span\n                              className={cn(\"block h-full rounded-full\", view.phase === \"done\" ? \"bg-emerald-500\" : \"bg-foreground\")}\n                              animate={{ width: `${Math.round(view.progress * 100)}%` }}\n                              transition={{ duration: 0.2, ease: \"linear\" }}\n                            />\n                          </span>\n                        </span>\n                      </motion.div>\n                    )}\n                  </AnimatePresence>\n                </div>\n              </motion.div>\n            )\n          )}\n        </AnimatePresence>\n      </div>\n      <style>{`\n        .sc-caret { animation: sc-caret 1s steps(1) infinite; }\n        @keyframes sc-caret { 50% { opacity: 0; } }\n      `}</style>\n    </div>\n  );\n}\n\nfunction TypeBadge({ category }: { category: NonNullable<SlashCommandItem[\"category\"]> }) {\n  const g = GROUPS.find((x) => x.id === category) ?? GROUPS[0];\n  return (\n    <span className=\"inline-flex items-center gap-1 rounded-full border bg-background px-1.5 font-mono text-[10px] text-muted-foreground\">\n      <span className={cn(\"size-1.5 rounded-full\", g.tone)} />\n      {g.label.toLowerCase()}\n    </span>\n  );\n}\n\nfunction Kbd({ children }: { children: React.ReactNode }) {\n  return <kbd className=\"inline-grid min-w-5 place-items-center rounded border bg-background px-1 font-mono text-[10px] leading-4 text-muted-foreground\">{children}</kbd>;\n}\n\nexport default function SlashCommandsDemo() {\n  return (\n    <div className=\"flex h-[380px] w-full items-start justify-center pt-2\">\n      <SlashCommands autoPlay />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/nextui/slash-commands.tsx"
    }
  ],
  "meta": {
    "kind": "component",
    "category": "ai",
    "previewHeight": 400,
    "new": true,
    "free": true,
    "openSource": true,
    "added": "2026-11-06"
  },
  "categories": [
    "ai"
  ],
  "type": "registry:component"
}