{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-tool-permission",
  "type": "registry:component",
  "title": "Agent Tool Permission",
  "description": "A permission prompt for a file-writing tool call that previews the change as a diff per file, lets you include or drop each hunk and choose how long the permission lasts. Approve applies only the chosen hunks, and the card turns into a receipt with Undo.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "agent-kit",
    "permission",
    "approval",
    "diff",
    "tool call",
    "human in the loop",
    "agents"
  ],
  "docs": "https://hyperblur.dev/effects/agent-tool-permission",
  "files": [
    {
      "path": "registry/hyperblur/agent-tool-permission.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/agent-tool-permission.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PermissionLine {\n  t: \"+\" | \"-\" | \" \";\n  s: string;\n}\n\nexport interface PermissionHunk {\n  id: string;\n  header: string;\n  lines: PermissionLine[];\n}\n\nexport interface PermissionFile {\n  path: string;\n  hunks: PermissionHunk[];\n}\n\nexport type PermissionScope = \"once\" | \"session\" | \"always\";\n\nexport interface AgentToolPermissionProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  agent?: string;\n  tool?: string;\n  reason?: string;\n  risk?: \"low\" | \"medium\" | \"high\";\n  files?: PermissionFile[];\n  defaultScope?: PermissionScope;\n  resetAfter?: number;\n  accent?: string;\n  onApprove?: (result: { hunks: string[]; scope: PermissionScope }) => void;\n  onDeny?: () => void;\n}\n\nconst sampleFiles: PermissionFile[] = [\n  {\n    path: \"src/billing/prorate.ts\",\n    hunks: [\n      {\n        id: \"h1\",\n        header: \"@@ -12,6 +12,7 @@ export function prorate(\",\n        lines: [\n          { t: \" \", s: \"  const days = daysBetween(start, end);\" },\n          { t: \"-\", s: \"  const ratio = days / 30;\" },\n          { t: \"+\", s: \"  const ratio = days / daysInMonth(start);\" },\n          { t: \"+\", s: \"  if (ratio <= 0) return 0;\" },\n          { t: \" \", s: \"  return round(amount * ratio, 2);\" },\n        ],\n      },\n      {\n        id: \"h2\",\n        header: \"@@ -40,3 +41,4 @@ function round(\",\n        lines: [\n          { t: \"-\", s: \"  return Math.round(n * 100) / 100;\" },\n          { t: \"+\", s: \"  const f = 10 ** places;\" },\n          { t: \"+\", s: \"  return Math.round((n + Number.EPSILON) * f) / f;\" },\n        ],\n      },\n    ],\n  },\n  {\n    path: \"src/billing/prorate.test.ts\",\n    hunks: [\n      {\n        id: \"h3\",\n        header: \"@@ -58,0 +58,5 @@ describe(\\\"prorate\\\"\",\n        lines: [\n          { t: \"+\", s: \"  it(\\\"uses real month length\\\", () => {\" },\n          { t: \"+\", s: \"    expect(prorate(29, feb1, feb15)).toBe(14.5);\" },\n          { t: \"+\", s: \"  });\" },\n        ],\n      },\n    ],\n  },\n];\n\nconst scopes: { v: PermissionScope; t: string; d: string }[] = [\n  { v: \"once\", t: \"Once\", d: \"Ask again next time\" },\n  { v: \"session\", t: \"This session\", d: \"Until the chat ends\" },\n  { v: \"always\", t: \"Always in src/\", d: \"Saved to project rules\" },\n];\n\nconst css = `\n.hb-wj6 {\n  --hb-wj6-a: #2f7bff;\n  box-sizing: border-box;\n  width: 100%;\n  max-width: 480px;\n  font-family: inherit;\n  font-size: 12px;\n  color: #ededed;\n  background: #111;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  overflow: hidden;\n  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset, 0 30px 60px -36px rgba(0,0,0,0.9);\n}\n.hb-wj6 *, .hb-wj6 *::before, .hb-wj6 *::after { box-sizing: border-box; font-family: inherit; }\n.hb-wj6-top { display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px 10px; background: linear-gradient(180deg, rgba(240,178,74,0.07), transparent); border-bottom: 1px solid #1f1f1f; }\n.hb-wj6-ic { display: grid; place-items: center; flex: none; width: 26px; height: 26px; color: #f0b24a; background: rgba(240,178,74,0.12); border: 1px solid rgba(240,178,74,0.3); border-radius: 8px; }\n.hb-wj6-ic svg { width: 14px; height: 14px; }\n.hb-wj6-hd { flex: 1; min-width: 0; }\n.hb-wj6-t { margin: 0; font-size: 12.5px; font-weight: 600; letter-spacing: -0.01em; }\n.hb-wj6-t code { padding: 1px 5px; font-family: var(--font-mono), ui-monospace, monospace; font-size: 11px; font-weight: 500; color: #ffd9a0; background: rgba(240,178,74,0.1); border-radius: 4px; }\n.hb-wj6-r { margin: 3px 0 0; color: #8f8f8f; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-wj6-risk { flex: none; padding: 2px 7px; font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; border-radius: 999px; }\n.hb-wj6-risk[data-r=\"low\"] { color: #34c78a; background: rgba(52,199,138,0.12); }\n.hb-wj6-risk[data-r=\"medium\"] { color: #f0b24a; background: rgba(240,178,74,0.12); }\n.hb-wj6-risk[data-r=\"high\"] { color: #ff6b5f; background: rgba(255,90,79,0.14); }\n.hb-wj6-tabs { display: flex; gap: 2px; padding: 6px 8px 0; background: #0d0d0d; border-bottom: 1px solid #1f1f1f; overflow-x: auto; scrollbar-width: none; }\n.hb-wj6-tab { display: flex; align-items: center; gap: 6px; flex: none; padding: 6px 9px 7px; font: inherit; font-family: var(--font-mono), ui-monospace, monospace; font-size: 10.5px; color: #8f8f8f; background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer; transition: color .15s ease, border-color .2s ease; }\n.hb-wj6-tab[aria-selected=\"true\"] { color: #ededed; border-bottom-color: var(--hb-wj6-a); }\n.hb-wj6-tab small { font-size: 10px; font-variant-numeric: tabular-nums; }\n.hb-wj6-tab small b { color: #4ade80; font-weight: 500; }\n.hb-wj6-tab small i { color: #ff7a7a; font-style: normal; }\n.hb-wj6-diff { max-height: 170px; overflow: auto; background: #0a0a0a; font-family: var(--font-mono), ui-monospace, monospace; font-size: 10.5px; line-height: 1.6; scrollbar-width: thin; scrollbar-color: #2a2a2a transparent; }\n.hb-wj6-hunk { transition: opacity .25s ease, filter .25s ease; }\n.hb-wj6-hunk[data-off=\"true\"] { opacity: .38; filter: grayscale(1); }\n.hb-wj6-hunk[data-off=\"true\"] .hb-wj6-l { text-decoration: line-through; text-decoration-color: rgba(255,255,255,0.25); }\n.hb-wj6-hh { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 3px 10px; color: #7fb3ff; background: #0f1520; border-top: 1px solid #172033; border-bottom: 1px solid #172033; }\n.hb-wj6-hh span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-wj6-chk { position: relative; display: inline-flex; align-items: center; gap: 6px; flex: none; font-family: var(--font-sans), sans-serif; font-size: 10.5px; color: #a1a1a1; cursor: pointer; }\n.hb-wj6-chk input { position: absolute; opacity: 0; width: 1px; height: 1px; }\n.hb-wj6-box { display: grid; place-items: center; width: 14px; height: 14px; background: #161616; border: 1px solid #3a3a3a; border-radius: 4px; transition: background-color .15s ease, border-color .15s ease; }\n.hb-wj6-box svg { width: 9px; height: 9px; color: #fff; opacity: 0; transform: scale(.5); transition: opacity .15s ease, transform .2s cubic-bezier(.3,1.6,.5,1); }\n.hb-wj6-chk input:checked + .hb-wj6-box { background: var(--hb-wj6-a); border-color: var(--hb-wj6-a); }\n.hb-wj6-chk input:checked + .hb-wj6-box svg { opacity: 1; transform: none; }\n.hb-wj6-chk input:focus-visible + .hb-wj6-box { outline: 2px solid var(--hb-wj6-a); outline-offset: 2px; }\n.hb-wj6-l { display: flex; white-space: pre; }\n.hb-wj6-l b { flex: none; width: 22px; text-align: center; font-weight: 400; color: #4a4a4a; user-select: none; }\n.hb-wj6-l[data-t=\"+\"] { color: #c8f5d6; background: rgba(52,199,138,0.09); }\n.hb-wj6-l[data-t=\"+\"] b { color: #34c78a; }\n.hb-wj6-l[data-t=\"-\"] { color: #ffd0cc; background: rgba(255,90,79,0.09); }\n.hb-wj6-l[data-t=\"-\"] b { color: #ff6b5f; }\n.hb-wj6-l[data-t=\" \"] { color: #8f8f8f; }\n.hb-wj6-foot { display: flex; flex-direction: column; gap: 9px; padding: 10px 12px 12px; }\n.hb-wj6-scopes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }\n.hb-wj6-sc { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 5px 8px; font: inherit; text-align: left; background: #161616; border: 1px solid #262626; border-radius: 8px; cursor: pointer; transition: border-color .15s ease, background-color .15s ease; min-width: 0; }\n.hb-wj6-sc b { font-size: 11px; font-weight: 600; color: #d4d4d4; white-space: nowrap; }\n.hb-wj6-sc span { font-size: 9.5px; color: #6f6f6f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }\n.hb-wj6-sc[aria-checked=\"true\"] { background: color-mix(in srgb, var(--hb-wj6-a) 12%, #141414); border-color: color-mix(in srgb, var(--hb-wj6-a) 60%, transparent); }\n.hb-wj6-sc[aria-checked=\"true\"] b { color: #fff; }\n.hb-wj6-sc[data-v=\"always\"][aria-checked=\"true\"] { background: rgba(240,178,74,0.1); border-color: rgba(240,178,74,0.5); }\n.hb-wj6-row { display: flex; align-items: center; gap: 6px; }\n.hb-wj6-sum { flex: 1; min-width: 0; font-size: 11px; color: #8f8f8f; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-wj6-sum b { color: #ededed; font-weight: 600; }\n.hb-wj6-btn { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 11px; font: inherit; font-size: 12px; font-weight: 500; color: #ededed; background: #1b1b1b; border: 1px solid #2c2c2c; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: background-color .15s ease, transform .1s ease, opacity .15s ease; }\n.hb-wj6-btn:hover:not(:disabled) { background: #232323; }\n.hb-wj6-btn:active:not(:disabled) { transform: translateY(1px); }\n.hb-wj6-btn:disabled { opacity: .4; cursor: default; }\n.hb-wj6-btn kbd { padding: 0 4px; font-family: inherit; font-size: 10px; color: inherit; opacity: .6; border: 1px solid currentColor; border-radius: 4px; }\n.hb-wj6-btn[data-primary=\"true\"] { color: #fff; background: var(--hb-wj6-a); border-color: transparent; box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 6px 16px -8px var(--hb-wj6-a); }\n.hb-wj6-btn[data-primary=\"true\"]:hover:not(:disabled) { background: color-mix(in srgb, var(--hb-wj6-a) 88%, #fff); }\n.hb-wj6-done { display: flex; align-items: center; gap: 10px; padding: 12px; animation: hb-wj6-in .35s cubic-bezier(.2,.8,.2,1) both; }\n.hb-wj6-badge { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%; }\n.hb-wj6-badge svg { width: 13px; height: 13px; }\n.hb-wj6-done[data-d=\"approved\"] .hb-wj6-badge { color: #0a0a0a; background: #34c78a; box-shadow: 0 0 0 4px rgba(52,199,138,0.15); }\n.hb-wj6-done[data-d=\"denied\"] .hb-wj6-badge { color: #fff; background: #3a3a3a; }\n.hb-wj6-done p { flex: 1; min-width: 0; margin: 0; line-height: 1.4; color: #a1a1a1; }\n.hb-wj6-done p b { display: block; color: #ededed; font-weight: 600; }\n.hb-wj6-tab:focus-visible, .hb-wj6-sc:focus-visible, .hb-wj6-btn:focus-visible { outline: 2px solid var(--hb-wj6-a); outline-offset: 2px; }\n@keyframes hb-wj6-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wj6 *, .hb-wj6-done { transition: none !important; animation: none !important; }\n}\n`;\n\nconst count = (h: PermissionHunk, t: \"+\" | \"-\") => h.lines.filter((l) => l.t === t).length;\n\nexport function AgentToolPermission({\n  agent = \"Coder\",\n  tool = \"fs.write_file\",\n  reason = \"Fix proration for months that are not 30 days long.\",\n  risk = \"medium\",\n  files = sampleFiles,\n  defaultScope = \"once\",\n  resetAfter = 0,\n  accent = \"#2f7bff\",\n  onApprove,\n  onDeny,\n  className,\n  style,\n  onKeyDown,\n  ...rest\n}: AgentToolPermissionProps) {\n  const all = React.useMemo(() => files.flatMap((f) => f.hunks.map((h) => h.id)), [files]);\n  const [on, setOn] = React.useState<Set<string>>(() => new Set(all));\n  const [tab, setTab] = React.useState(0);\n  const [scope, setScope] = React.useState<PermissionScope>(defaultScope);\n  const [decision, setDecision] = React.useState<null | \"approved\" | \"denied\">(null);\n\n  React.useEffect(() => {\n    if (!decision || resetAfter <= 0) return;\n    const t = window.setTimeout(() => {\n      setDecision(null);\n      setOn(new Set(all));\n    }, resetAfter);\n    return () => window.clearTimeout(t);\n  }, [decision, resetAfter, all]);\n\n  const hunks = files.flatMap((f) => f.hunks);\n  const chosen = hunks.filter((h) => on.has(h.id));\n  const add = chosen.reduce((s, h) => s + count(h, \"+\"), 0);\n  const del = chosen.reduce((s, h) => s + count(h, \"-\"), 0);\n  const filesTouched = files.filter((f) => f.hunks.some((h) => on.has(h.id))).length;\n  const file = files[Math.min(tab, files.length - 1)];\n\n  const approve = () => {\n    if (!chosen.length) return;\n    setDecision(\"approved\");\n    onApprove?.({ hunks: chosen.map((h) => h.id), scope });\n  };\n  const deny = () => {\n    setDecision(\"denied\");\n    onDeny?.();\n  };\n\n  const toggle = (id: string) =>\n    setOn((s) => {\n      const n = new Set(s);\n      if (n.has(id)) n.delete(id);\n      else n.add(id);\n      return n;\n    });\n\n  const scopeText = scope === \"once\" ? \"for this call\" : scope === \"session\" ? \"for this session\" : \"in src/ from now on\";\n\n  return (\n    <div\n      className={[\"hb-wj6\", className].filter(Boolean).join(\" \")}\n      style={{ \"--hb-wj6-a\": accent, ...style } as React.CSSProperties}\n      role=\"group\"\n      aria-label={`${agent} requests permission to run ${tool}`}\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        if (decision) return;\n        if (e.key === \"Enter\" && (e.metaKey || e.ctrlKey)) {\n          e.preventDefault();\n          approve();\n        }\n      }}\n      {...rest}\n    >\n      <style href=\"hb-agent-tool-permission\" precedence=\"default\">{css}</style>\n      <div className=\"hb-wj6-top\">\n        <span className=\"hb-wj6-ic\">\n          <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"M8 2 13.5 4.2v3.6c0 3-2.3 5.1-5.5 6.2C4.8 12.9 2.5 10.8 2.5 7.8V4.2Z\" /><path d=\"M8 6v2.6M8 10.8v.1\" /></svg>\n        </span>\n        <div className=\"hb-wj6-hd\">\n          <p className=\"hb-wj6-t\">{agent} wants to run <code>{tool}</code></p>\n          <p className=\"hb-wj6-r\" title={reason}>{reason}</p>\n        </div>\n        <span className=\"hb-wj6-risk\" data-r={risk}>{risk} risk</span>\n      </div>\n      {decision ? (\n        <div className=\"hb-wj6-done\" data-d={decision} role=\"status\">\n          <span className=\"hb-wj6-badge\">\n            {decision === \"approved\" ? (\n              <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"m3.5 8.5 3 3 6-7\" /></svg>\n            ) : (\n              <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\"><path d=\"m4.5 4.5 7 7M11.5 4.5l-7 7\" /></svg>\n            )}\n          </span>\n          <p>\n            <b>{decision === \"approved\" ? `Applied ${chosen.length} of ${hunks.length} changes to ${filesTouched} ${filesTouched === 1 ? \"file\" : \"files\"}` : \"Request denied\"}</b>\n            {decision === \"approved\" ? `${tool} allowed ${scopeText}.` : `${agent} will propose another approach.`}\n          </p>\n          <button type=\"button\" className=\"hb-wj6-btn\" onClick={() => { setDecision(null); }}>\n            Undo\n          </button>\n        </div>\n      ) : (\n        <>\n          <div className=\"hb-wj6-tabs\" role=\"tablist\" aria-label=\"Changed files\">\n            {files.map((f, i) => {\n              const a = f.hunks.filter((h) => on.has(h.id)).reduce((s, h) => s + count(h, \"+\"), 0);\n              const d = f.hunks.filter((h) => on.has(h.id)).reduce((s, h) => s + count(h, \"-\"), 0);\n              return (\n                <button\n                  key={f.path}\n                  type=\"button\"\n                  role=\"tab\"\n                  aria-selected={i === tab}\n                  tabIndex={i === tab ? 0 : -1}\n                  className=\"hb-wj6-tab\"\n                  onClick={() => setTab(i)}\n                  onKeyDown={(e) => {\n                    if (e.key !== \"ArrowRight\" && e.key !== \"ArrowLeft\") return;\n                    e.preventDefault();\n                    setTab((i + (e.key === \"ArrowRight\" ? 1 : -1) + files.length) % files.length);\n                  }}\n                >\n                  {f.path.split(\"/\").pop()}\n                  <small><b>+{a}</b> <i>−{d}</i></small>\n                </button>\n              );\n            })}\n          </div>\n          <div className=\"hb-wj6-diff\" role=\"tabpanel\" aria-label={file.path}>\n            {file.hunks.map((h) => (\n              <div key={h.id} className=\"hb-wj6-hunk\" data-off={!on.has(h.id)}>\n                <div className=\"hb-wj6-hh\">\n                  <span>{h.header}</span>\n                  <label className=\"hb-wj6-chk\">\n                    <input type=\"checkbox\" checked={on.has(h.id)} onChange={() => toggle(h.id)} />\n                    <span className=\"hb-wj6-box\"><svg viewBox=\"0 0 10 10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"m2 5.2 2 2 4-4.4\" /></svg></span>\n                    Include\n                  </label>\n                </div>\n                {h.lines.map((l, k) => (\n                  <div key={k} className=\"hb-wj6-l\" data-t={l.t}>\n                    <b>{l.t === \" \" ? \"\" : l.t === \"-\" ? \"−\" : \"+\"}</b>\n                    {l.s}\n                  </div>\n                ))}\n              </div>\n            ))}\n          </div>\n          <div className=\"hb-wj6-foot\">\n            <div className=\"hb-wj6-scopes\" role=\"radiogroup\" aria-label=\"Allow\">\n              {scopes.map((s) => (\n                <button key={s.v} type=\"button\" role=\"radio\" aria-checked={scope === s.v} data-v={s.v} className=\"hb-wj6-sc\" onClick={() => setScope(s.v)}>\n                  <b>{s.t}</b>\n                  <span>{s.d}</span>\n                </button>\n              ))}\n            </div>\n            <div className=\"hb-wj6-row\">\n              <span className=\"hb-wj6-sum\"><b>{chosen.length}/{hunks.length}</b> changes · <b>+{add}</b> −{del}</span>\n              <button type=\"button\" className=\"hb-wj6-btn\" onClick={deny}>Deny</button>\n              <button type=\"button\" className=\"hb-wj6-btn\" data-primary=\"true\" disabled={!chosen.length} onClick={approve}>\n                Approve <kbd>⌘↵</kbd>\n              </button>\n            </div>\n          </div>\n        </>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}