{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "prompt-slash-commands",
  "type": "registry:component",
  "title": "Prompt Slash Commands",
  "description": "A composer where / opens commands and @ opens context sources, with an inline ghost completion that Tab accepts. Picks become removable tokens in front of the text, and Backspace at the start removes the last one.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "agent-kit",
    "prompt",
    "slash",
    "commands",
    "mentions",
    "autocomplete",
    "tokens"
  ],
  "docs": "https://hyperblur.dev/effects/prompt-slash-commands",
  "files": [
    {
      "path": "registry/hyperblur/prompt-slash-commands.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/prompt-slash-commands.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SlashCommand {\n  name: string;\n  description: string;\n}\n\nexport interface SlashMention {\n  name: string;\n  kind?: \"doc\" | \"code\" | \"sheet\" | \"channel\";\n}\n\nexport interface SlashToken {\n  type: \"command\" | \"mention\";\n  value: string;\n}\n\nexport interface SlashSubmit {\n  commands: string[];\n  mentions: string[];\n  text: string;\n}\n\nexport interface PromptSlashCommandsProps extends Omit<React.HTMLAttributes<HTMLFormElement>, \"onSubmit\"> {\n  commands?: SlashCommand[];\n  mentions?: SlashMention[];\n  defaultTokens?: SlashToken[];\n  defaultValue?: string;\n  placeholder?: string;\n  menuPlacement?: \"top\" | \"bottom\";\n  accent?: string;\n  onTokensChange?: (tokens: SlashToken[]) => void;\n  onSubmit?: (payload: SlashSubmit) => void;\n}\n\nconst defaultCommands: SlashCommand[] = [\n  { name: \"summarize\", description: \"Condense into key points\" },\n  { name: \"translate\", description: \"Rewrite in another language\" },\n  { name: \"explain\", description: \"Break it down step by step\" },\n  { name: \"draft-email\", description: \"Turn notes into an email\" },\n  { name: \"table\", description: \"Organize the answer as a table\" },\n  { name: \"tone\", description: \"Fix grammar and adjust tone\" },\n];\n\nconst defaultMentions: SlashMention[] = [\n  { name: \"release-notes.md\", kind: \"doc\" },\n  { name: \"roadmap-q1.md\", kind: \"doc\" },\n  { name: \"pricing-page.tsx\", kind: \"code\" },\n  { name: \"weekly-metrics.csv\", kind: \"sheet\" },\n  { name: \"design-team\", kind: \"channel\" },\n];\n\ntype Option = { key: string; type: \"command\" | \"mention\"; name: string; detail: string; kind?: SlashMention[\"kind\"] };\n\nfunction rank(name: string, query: string) {\n  const n = name.toLowerCase();\n  const q = query.toLowerCase();\n  if (!q) return 1;\n  if (n.startsWith(q)) return 3;\n  if (n.split(/[-._]/).some((part) => part.startsWith(q))) return 2;\n  return n.includes(q) ? 1 : 0;\n}\n\nfunction Glyph({ option }: { option: Option }) {\n  if (option.type === \"command\") return <span className=\"hb-vl9-g\" data-type=\"command\">/</span>;\n  const label = option.kind === \"code\" ? \"</>\" : option.kind === \"sheet\" ? \"csv\" : option.kind === \"channel\" ? \"#\" : \"md\";\n  return (\n    <span className=\"hb-vl9-g\" data-type={option.kind ?? \"doc\"}>\n      {label}\n    </span>\n  );\n}\n\nconst css = `\n.hb-vl9 {\n  --hb-vl9-a: #7fb3ff;\n  position: relative;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n  box-sizing: border-box;\n}\n.hb-vl9 *, .hb-vl9 *::before, .hb-vl9 *::after { box-sizing: border-box; }\n.hb-vl9-box {\n  display: flex;\n  flex-direction: column;\n  gap: 6px;\n  padding: 10px 10px 8px;\n  border-radius: 18px;\n  background: linear-gradient(180deg, #18181b, #121214);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px rgba(255, 255, 255, 0.08), 0 24px 48px -28px rgba(0, 0, 0, 0.9);\n  transition: box-shadow 0.3s ease;\n}\n.hb-vl9-box:focus-within {\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px color-mix(in srgb, var(--hb-vl9-a) 50%, transparent), 0 0 0 4px color-mix(in srgb, var(--hb-vl9-a) 12%, transparent), 0 24px 48px -28px rgba(0, 0, 0, 0.9);\n}\n.hb-vl9-line { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; min-height: 30px; }\n.hb-vl9-tok {\n  display: inline-flex;\n  align-items: center;\n  gap: 4px;\n  height: 24px;\n  padding: 0 4px 0 8px;\n  border-radius: 7px;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 11.5px;\n  white-space: nowrap;\n  animation: hb-vl9-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;\n}\n.hb-vl9-tok[data-type=\"command\"] { background: color-mix(in srgb, var(--hb-vl9-a) 16%, #141416); color: var(--hb-vl9-a); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-vl9-a) 35%, transparent); }\n.hb-vl9-tok[data-type=\"mention\"] { background: #222226; color: #d6d6da; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08); }\n@keyframes hb-vl9-in { from { opacity: 0; transform: scale(0.7); } }\n.hb-vl9-tx {\n  display: grid;\n  place-items: center;\n  width: 16px;\n  height: 16px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 4px;\n  background: transparent;\n  color: inherit;\n  opacity: 0.6;\n  cursor: pointer;\n}\n.hb-vl9-tx:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }\n.hb-vl9-tx:focus-visible { outline: 2px solid var(--hb-vl9-a); opacity: 1; }\n.hb-vl9-field { position: relative; flex: 1 1 140px; min-width: 120px; }\n.hb-vl9-ta, .hb-vl9-mirror {\n  display: block;\n  width: 100%;\n  margin: 0;\n  padding: 4px 2px;\n  border: 0;\n  font: inherit;\n  font-size: 14px;\n  line-height: 1.5;\n  letter-spacing: normal;\n  white-space: pre-wrap;\n  overflow-wrap: break-word;\n}\n.hb-vl9-ta {\n  position: relative;\n  z-index: 1;\n  min-height: 29px;\n  outline: none;\n  resize: none;\n  overflow: hidden;\n  background: transparent;\n  color: #ededed;\n  caret-color: var(--hb-vl9-a);\n}\n.hb-vl9-ta::placeholder { color: #6f6f75; }\n.hb-vl9-mirror { position: absolute; inset: 0; color: transparent; pointer-events: none; }\n.hb-vl9-ghost { color: #5d5d64; }\n.hb-vl9-ghost-key {\n  margin-left: 6px;\n  padding: 0 4px;\n  border-radius: 4px;\n  background: #222226;\n  color: #8f8f8f;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 10px;\n}\n.hb-vl9-foot { display: flex; align-items: center; gap: 8px; }\n.hb-vl9-hint { flex: 1 1 auto; min-width: 0; overflow: hidden; font-size: 11px; color: #77777d; white-space: nowrap; text-overflow: ellipsis; }\n.hb-vl9-k {\n  padding: 1px 5px;\n  border-radius: 5px;\n  background: #222226;\n  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.07);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 10px;\n  color: #a1a1a1;\n}\n.hb-vl9-send {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 30px;\n  height: 30px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 10px;\n  background: #ededed;\n  color: #0a0a0a;\n  cursor: pointer;\n  transition: transform 0.2s ease, opacity 0.2s ease, background 0.3s ease;\n}\n.hb-vl9-send:disabled { opacity: 0.3; cursor: not-allowed; }\n.hb-vl9-send:not(:disabled):active { transform: scale(0.92); }\n.hb-vl9-send:focus-visible { outline: 2px solid var(--hb-vl9-a); outline-offset: 2px; }\n.hb-vl9-send[data-sent=\"true\"] { background: var(--hb-vl9-a); }\n.hb-vl9-menu {\n  position: absolute;\n  left: 8px;\n  z-index: 20;\n  width: min(300px, calc(100% - 16px));\n  max-height: 188px;\n  margin: 0;\n  padding: 5px;\n  overflow-y: auto;\n  border-radius: 14px;\n  background: rgba(24, 24, 27, 0.96);\n  backdrop-filter: blur(14px);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px rgba(255, 255, 255, 0.09), 0 24px 40px -12px rgba(0, 0, 0, 0.85);\n  list-style: none;\n  scrollbar-width: thin;\n  animation: hb-vl9-menu 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;\n}\n.hb-vl9-menu[data-place=\"bottom\"] { top: calc(100% + 6px); transform-origin: top left; }\n.hb-vl9-menu[data-place=\"top\"] { bottom: calc(100% + 6px); transform-origin: bottom left; }\n@keyframes hb-vl9-menu { from { opacity: 0; transform: translateY(-4px) scale(0.97); } }\n.hb-vl9-head { padding: 4px 8px 5px; font-family: var(--font-mono, ui-monospace, monospace); font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; color: #6f6f75; }\n.hb-vl9-opt {\n  display: flex;\n  align-items: center;\n  gap: 9px;\n  padding: 6px 8px;\n  border-radius: 9px;\n  cursor: pointer;\n  transition: background 0.15s ease;\n}\n.hb-vl9-opt[aria-selected=\"true\"] { background: rgba(255, 255, 255, 0.07); }\n.hb-vl9-g {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 24px;\n  height: 24px;\n  border-radius: 7px;\n  background: #222226;\n  color: #a1a1a1;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 9px;\n  font-weight: 700;\n}\n.hb-vl9-g[data-type=\"command\"] { background: color-mix(in srgb, var(--hb-vl9-a) 18%, #141416); color: var(--hb-vl9-a); font-size: 13px; }\n.hb-vl9-g[data-type=\"code\"] { color: #7fb3ff; }\n.hb-vl9-g[data-type=\"sheet\"] { color: #3ccf7a; }\n.hb-vl9-g[data-type=\"channel\"] { color: #ffad42; font-size: 12px; }\n.hb-vl9-ot { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }\n.hb-vl9-on { overflow: hidden; font-size: 12.5px; color: #d6d6da; white-space: nowrap; text-overflow: ellipsis; }\n.hb-vl9-on b { color: #ffffff; font-weight: 600; }\n.hb-vl9-od { overflow: hidden; font-size: 11px; color: #77777d; white-space: nowrap; text-overflow: ellipsis; }\n.hb-vl9-enter { margin-left: auto; font-family: var(--font-mono, ui-monospace, monospace); font-size: 10px; color: #6f6f75; opacity: 0; }\n.hb-vl9-opt[aria-selected=\"true\"] .hb-vl9-enter { opacity: 1; }\n.hb-vl9-empty { padding: 10px; font-size: 12px; color: #77777d; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-vl9 *, .hb-vl9 *::before, .hb-vl9 *::after { transition: none !important; animation: none !important; }\n}\n`;\n\nexport function PromptSlashCommands({\n  commands = defaultCommands,\n  mentions = defaultMentions,\n  defaultTokens = [{ type: \"mention\", value: \"release-notes.md\" }],\n  defaultValue = \"\",\n  placeholder = \"Ask anything, / for commands, @ to add context\",\n  menuPlacement = \"bottom\",\n  accent = \"#7fb3ff\",\n  onTokensChange,\n  onSubmit,\n  className,\n  style,\n  ...rest\n}: PromptSlashCommandsProps) {\n  const [tokens, setTokens] = React.useState<SlashToken[]>(defaultTokens);\n  const [text, setText] = React.useState(defaultValue);\n  const [caret, setCaret] = React.useState(defaultValue.length);\n  const [dismissed, setDismissed] = React.useState<string | null>(null);\n  const [cursor, setCursor] = React.useState(0);\n  const [sent, setSent] = React.useState(false);\n  const taRef = React.useRef<HTMLTextAreaElement>(null);\n  const sentTimer = React.useRef<number | undefined>(undefined);\n  const uid = React.useId().replace(/:/g, \"\");\n\n  React.useEffect(() => () => window.clearTimeout(sentTimer.current), []);\n\n  React.useLayoutEffect(() => {\n    const ta = taRef.current;\n    if (!ta) return;\n    ta.style.height = \"auto\";\n    ta.style.height = `${Math.min(ta.scrollHeight, 140)}px`;\n  }, [text]);\n\n  const before = text.slice(0, caret);\n  const match = /(^|\\s)([/@])([\\w.-]*)$/.exec(before);\n  const trigger = match ? match[2] : null;\n  const query = match ? match[3] : \"\";\n  const triggerKey = match ? `${before.length - query.length - 1}:${trigger}` : null;\n  const open = !!match && dismissed !== triggerKey;\n\n  const options: Option[] = React.useMemo(() => {\n    if (!trigger) return [];\n    const pool: Option[] =\n      trigger === \"/\"\n        ? commands.map((c) => ({ key: `c-${c.name}`, type: \"command\" as const, name: c.name, detail: c.description }))\n        : mentions.map((m) => ({\n            key: `m-${m.name}`,\n            type: \"mention\" as const,\n            name: m.name,\n            detail: m.kind === \"channel\" ? \"Channel\" : m.kind === \"code\" ? \"Source file\" : m.kind === \"sheet\" ? \"Spreadsheet\" : \"Document\",\n            kind: m.kind,\n          }));\n    return pool\n      .map((o, i) => ({ o, s: rank(o.name, query), i }))\n      .filter((x) => x.s > 0)\n      .sort((a, b) => b.s - a.s || a.i - b.i)\n      .map((x) => x.o);\n  }, [trigger, query, commands, mentions]);\n\n  const index = options.length ? Math.min(cursor, options.length - 1) : 0;\n  const top = options[index];\n  const ghost = open && top && query && top.name.toLowerCase().startsWith(query.toLowerCase()) && caret === text.length ? top.name.slice(query.length) : \"\";\n\n  const updateTokens = (next: SlashToken[]) => {\n    setTokens(next);\n    onTokensChange?.(next);\n  };\n\n  const choose = (option: Option) => {\n    const start = before.length - query.length - 1;\n    const rest = text.slice(caret).replace(/^\\s+/, \"\");\n    const head = text.slice(0, start).replace(/\\s+$/, \"\");\n    const nextText = head && rest ? `${head} ${rest}` : head || rest;\n    if (!tokens.some((t) => t.type === option.type && t.value === option.name)) {\n      updateTokens([...tokens, { type: option.type, value: option.name }]);\n    }\n    setText(nextText);\n    setCaret(head.length + (head && rest ? 1 : 0));\n    setCursor(0);\n    requestAnimationFrame(() => {\n      const ta = taRef.current;\n      if (!ta) return;\n      ta.focus();\n      const pos = head.length + (head && rest ? 1 : 0);\n      ta.setSelectionRange(pos, pos);\n    });\n  };\n\n  const submit = () => {\n    const value = text.trim();\n    if (!value && tokens.length === 0) return;\n    onSubmit?.({\n      commands: tokens.filter((t) => t.type === \"command\").map((t) => t.value),\n      mentions: tokens.filter((t) => t.type === \"mention\").map((t) => t.value),\n      text: value,\n    });\n    setText(\"\");\n    setCaret(0);\n    updateTokens([]);\n    setSent(true);\n    window.clearTimeout(sentTimer.current);\n    sentTimer.current = window.setTimeout(() => setSent(false), 900);\n  };\n\n  const onKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {\n    if (open && options.length) {\n      if (event.key === \"ArrowDown\") {\n        event.preventDefault();\n        setCursor((index + 1) % options.length);\n        return;\n      }\n      if (event.key === \"ArrowUp\") {\n        event.preventDefault();\n        setCursor((index - 1 + options.length) % options.length);\n        return;\n      }\n      if (event.key === \"Enter\" || event.key === \"Tab\") {\n        event.preventDefault();\n        choose(options[index]);\n        return;\n      }\n    }\n    if (open && event.key === \"Escape\") {\n      event.preventDefault();\n      setDismissed(triggerKey);\n      return;\n    }\n    if (event.key === \"Enter\" && !event.shiftKey && !event.nativeEvent.isComposing) {\n      event.preventDefault();\n      submit();\n      return;\n    }\n    if (event.key === \"Backspace\" && event.currentTarget.selectionStart === 0 && event.currentTarget.selectionEnd === 0 && tokens.length) {\n      event.preventDefault();\n      updateTokens(tokens.slice(0, -1));\n    }\n  };\n\n  const highlight = (name: string) => {\n    const at = query ? name.toLowerCase().indexOf(query.toLowerCase()) : -1;\n    if (at < 0) return name;\n    return (\n      <>\n        {name.slice(0, at)}\n        <b>{name.slice(at, at + query.length)}</b>\n        {name.slice(at + query.length)}\n      </>\n    );\n  };\n\n  const listId = `${uid}-list`;\n\n  return (\n    <form\n      className={[\"hb-vl9\", className].filter(Boolean).join(\" \")}\n      style={{ \"--hb-vl9-a\": accent, ...style } as React.CSSProperties}\n      onSubmit={(event) => {\n        event.preventDefault();\n        submit();\n      }}\n      {...rest}\n    >\n      <style href=\"hb-prompt-slash-commands\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vl9-box\">\n        <div className=\"hb-vl9-line\">\n          {tokens.map((token) => (\n            <span key={`${token.type}-${token.value}`} className=\"hb-vl9-tok\" data-type={token.type}>\n              {token.type === \"command\" ? \"/\" : \"@\"}\n              {token.value}\n              <button\n                type=\"button\"\n                className=\"hb-vl9-tx\"\n                aria-label={`Remove ${token.value}`}\n                onClick={() => updateTokens(tokens.filter((t) => t !== token))}\n              >\n                <svg width=\"8\" height=\"8\" viewBox=\"0 0 8 8\" aria-hidden=\"true\">\n                  <path d=\"M1.5 1.5l5 5M6.5 1.5l-5 5\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinecap=\"round\" />\n                </svg>\n              </button>\n            </span>\n          ))}\n          <div className=\"hb-vl9-field\">\n            <div className=\"hb-vl9-mirror\" aria-hidden=\"true\">\n              {text}\n              {ghost && (\n                <>\n                  <span className=\"hb-vl9-ghost\">{ghost}</span>\n                  <span className=\"hb-vl9-ghost-key\">Tab</span>\n                </>\n              )}\n            </div>\n            <textarea\n              ref={taRef}\n              className=\"hb-vl9-ta\"\n              rows={1}\n              value={text}\n              placeholder={tokens.length ? \"Add instructions...\" : placeholder}\n              aria-label=\"Message\"\n              role=\"combobox\"\n              aria-expanded={open}\n              aria-controls={listId}\n              aria-autocomplete=\"list\"\n              aria-activedescendant={open && top ? `${uid}-${top.key}` : undefined}\n              onChange={(event) => {\n                setText(event.target.value);\n                setCaret(event.target.selectionStart ?? event.target.value.length);\n                setCursor(0);\n              }}\n              onSelect={(event) => setCaret(event.currentTarget.selectionStart ?? 0)}\n              onKeyDown={onKeyDown}\n              onBlur={() => setDismissed(triggerKey)}\n              onFocus={() => setDismissed(null)}\n            />\n          </div>\n        </div>\n        <div className=\"hb-vl9-foot\">\n          <span className=\"hb-vl9-hint\">\n            <span className=\"hb-vl9-k\">/</span> commands <span className=\"hb-vl9-k\">@</span> context <span className=\"hb-vl9-k\">Tab</span> complete\n          </span>\n          <button type=\"submit\" className=\"hb-vl9-send\" aria-label=\"Send\" data-sent={sent ? \"true\" : \"false\"} disabled={!text.trim() && tokens.length === 0}>\n            {sent ? (\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\" aria-hidden=\"true\">\n                <path d=\"M3 7.3l2.6 2.6L11 4.4\" stroke=\"currentColor\" strokeWidth=\"1.9\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n              </svg>\n            ) : (\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\" aria-hidden=\"true\">\n                <path d=\"M7 11.5V2.8M3.2 6.4L7 2.6l3.8 3.8\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n              </svg>\n            )}\n          </button>\n        </div>\n      </div>\n      {open && (\n        <ul id={listId} className=\"hb-vl9-menu\" data-place={menuPlacement} role=\"listbox\" aria-label={trigger === \"/\" ? \"Commands\" : \"Context\"}>\n          <li className=\"hb-vl9-head\" role=\"presentation\">\n            {trigger === \"/\" ? \"Commands\" : \"Add context\"}\n          </li>\n          {options.length === 0 && (\n            <li className=\"hb-vl9-empty\" role=\"presentation\">\n              Nothing matches {trigger}\n              {query}\n            </li>\n          )}\n          {options.map((option, i) => (\n            <li\n              key={option.key}\n              id={`${uid}-${option.key}`}\n              role=\"option\"\n              aria-selected={i === index}\n              className=\"hb-vl9-opt\"\n              onPointerEnter={() => setCursor(i)}\n              onPointerDown={(event) => {\n                event.preventDefault();\n                choose(option);\n              }}\n            >\n              <Glyph option={option} />\n              <span className=\"hb-vl9-ot\">\n                <span className=\"hb-vl9-on\">\n                  {option.type === \"command\" ? \"/\" : \"@\"}\n                  {highlight(option.name)}\n                </span>\n                <span className=\"hb-vl9-od\">{option.detail}</span>\n              </span>\n              <span className=\"hb-vl9-enter\">Enter</span>\n            </li>\n          ))}\n        </ul>\n      )}\n    </form>\n  );\n}\n"
    }
  ]
}