{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-memory-panel",
  "type": "registry:component",
  "title": "Agent Memory Panel",
  "description": "A list of facts the agent remembers, each with a source chip and a confidence meter. Facts can be edited in place or forgotten with an animated removal.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "agent-kit",
    "agent",
    "memory",
    "facts",
    "confidence",
    "privacy",
    "settings"
  ],
  "docs": "https://hyperblur.dev/effects/agent-memory-panel",
  "files": [
    {
      "path": "registry/hyperblur/agent-memory-panel.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/agent-memory-panel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MemoryItem {\n  id: string;\n  text: string;\n  source: string;\n  confidence: number;\n}\n\nexport interface AgentMemoryPanelProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"title\"> {\n  items?: MemoryItem[];\n  defaultItems?: MemoryItem[];\n  onItemsChange?: (items: MemoryItem[]) => void;\n  onForget?: (item: MemoryItem) => void;\n  onEdit?: (item: MemoryItem) => void;\n  title?: string;\n  accent?: string;\n}\n\nconst defaultMemories: MemoryItem[] = [\n  { id: \"m1\", text: \"Prefers short answers with the code first.\", source: \"chat, Mar 3\", confidence: 0.94 },\n  { id: \"m2\", text: \"Deploys to Vercel from the main branch.\", source: \"repo scan\", confidence: 0.81 },\n  { id: \"m3\", text: \"Works in the Lisbon time zone.\", source: \"inferred\", confidence: 0.52 },\n  { id: \"m4\", text: \"Uses pnpm, never npm.\", source: \"chat, Feb 21\", confidence: 0.9 },\n];\n\nconst css = `\n.hb-yf3 {\n  box-sizing: border-box;\n  width: 100%;\n  padding: 8px 8px 6px;\n  font-family: inherit;\n  font-size: 12px;\n  line-height: 1.35;\n  color: #ededed;\n  background: #111111;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  text-align: left;\n}\n.hb-yf3 *, .hb-yf3 *::before, .hb-yf3 *::after { box-sizing: border-box; font-family: inherit; }\n.hb-yf3-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 6px 8px; }\n.hb-yf3-title { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 12.5px; font-weight: 600; letter-spacing: -0.005em; }\n.hb-yf3-brain { width: 14px; height: 14px; color: var(--hb-yf3-a, #2f7bff); }\n.hb-yf3-count { padding: 1px 7px; font-size: 10.5px; font-weight: 500; font-variant-numeric: tabular-nums; color: #a1a1a1; background: #1a1a1a; border: 1px solid #262626; border-radius: 999px; }\n.hb-yf3-list { list-style: none; margin: 0; padding: 0; }\n.hb-yf3-item { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.22s ease, transform 0.28s ease; }\n.hb-yf3-item[data-leaving=\"true\"] { grid-template-rows: 0fr; opacity: 0; transform: translateX(14px); pointer-events: none; }\n.hb-yf3-clip { min-height: 0; overflow: hidden; }\n.hb-yf3-card {\n  display: flex;\n  align-items: flex-start;\n  justify-content: space-between;\n  gap: 8px;\n  margin: 0 0 2px;\n  padding: 5px 6px 5px 10px;\n  border-radius: 10px;\n  transition: background-color 0.15s ease;\n}\n.hb-yf3-card:hover, .hb-yf3-card:focus-within { background: #171717; }\n.hb-yf3-body { flex: 1; min-width: 0; }\n.hb-yf3-text { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: #ededed; }\n.hb-yf3-meta { display: flex; align-items: center; gap: 8px; margin-top: 3px; }\n.hb-yf3-chip { display: inline-flex; align-items: center; gap: 5px; min-width: 0; padding: 1px 7px 1px 5px; font-size: 10.5px; color: #a1a1a1; background: #1a1a1a; border: 1px solid #262626; border-radius: 999px; white-space: nowrap; }\n.hb-yf3-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--hb-yf3-h, #7fb3ff); }\n.hb-yf3-conf { display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; font-variant-numeric: tabular-nums; color: #8f8f8f; }\n.hb-yf3-track { position: relative; width: 34px; height: 4px; overflow: hidden; background: #242424; border-radius: 4px; }\n.hb-yf3-bar { display: block; height: 100%; border-radius: 4px; background: var(--hb-yf3-c, #3ecf8e); transform-origin: left center; animation: hb-yf3-grow 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both; animation-delay: calc(var(--hb-yf3-i, 0) * 80ms); }\n.hb-yf3-actions { display: flex; flex: none; gap: 2px; opacity: 0.5; transition: opacity 0.15s ease; }\n.hb-yf3-card:hover .hb-yf3-actions, .hb-yf3-card:focus-within .hb-yf3-actions { opacity: 1; }\n.hb-yf3-btn { display: grid; place-items: center; width: 24px; height: 24px; margin: 0; padding: 0; color: #a1a1a1; background: transparent; border: 0; border-radius: 7px; cursor: pointer; transition: background-color 0.15s ease, color 0.15s ease; }\n.hb-yf3-btn svg { width: 13px; height: 13px; }\n.hb-yf3-btn:hover { color: #ededed; background: rgba(255, 255, 255, 0.08); }\n.hb-yf3-btn[data-kind=\"forget\"]:hover { color: #ff7a7a; background: rgba(255, 93, 93, 0.12); }\n.hb-yf3-btn[data-kind=\"save\"] { color: #3ecf8e; }\n.hb-yf3-btn:focus-visible { outline: 2px solid var(--hb-yf3-a, #2f7bff); outline-offset: 1px; }\n.hb-yf3-input { width: 100%; padding: 3px 7px; margin: -3px 0 0 -7px; font: inherit; font-size: 12px; color: #ededed; background: #0a0a0a; border: 1px solid var(--hb-yf3-a, #2f7bff); border-radius: 6px; outline: none; }\n.hb-yf3-empty { display: grid; justify-items: center; gap: 6px; padding: 22px 12px; color: #8f8f8f; text-align: center; }\n.hb-yf3-empty svg { width: 22px; height: 22px; color: #4a4a4a; }\n.hb-yf3-empty p { margin: 0; }\n@keyframes hb-yf3-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-yf3-item, .hb-yf3-card, .hb-yf3-actions, .hb-yf3-btn { transition: none; }\n  .hb-yf3-bar { animation: none; }\n  .hb-yf3-item[data-leaving=\"true\"] { transform: none; }\n}\n`;\n\nfunction hueOf(text: string) {\n  let h = 2166136261;\n  for (let i = 0; i < text.length; i += 1) {\n    h = Math.imul(h ^ text.charCodeAt(i), 16777619);\n  }\n  return (h >>> 0) % 360;\n}\n\nfunction confColor(c: number) {\n  if (c >= 0.8) return \"#3ecf8e\";\n  if (c >= 0.6) return \"#7fb3ff\";\n  return \"#f5b544\";\n}\n\nexport function AgentMemoryPanel({\n  items,\n  defaultItems = defaultMemories,\n  onItemsChange,\n  onForget,\n  onEdit,\n  title = \"Memory\",\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: AgentMemoryPanelProps) {\n  const [inner, setInner] = React.useState<MemoryItem[]>(defaultItems);\n  const [leaving, setLeaving] = React.useState<string[]>([]);\n  const [editing, setEditing] = React.useState<string | null>(null);\n  const [draft, setDraft] = React.useState(\"\");\n  const timers = React.useRef<number[]>([]);\n  const controlled = items !== undefined;\n  const list = controlled ? items : inner;\n  const listRef = React.useRef(list);\n\n  React.useEffect(() => {\n    listRef.current = list;\n  }, [list]);\n\n  React.useEffect(() => {\n    const pending = timers.current;\n    return () => pending.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  function commit(next: MemoryItem[]) {\n    if (!controlled) setInner(next);\n    onItemsChange?.(next);\n  }\n\n  function forget(item: MemoryItem) {\n    if (leaving.includes(item.id)) return;\n    setLeaving((l) => [...l, item.id]);\n    if (editing === item.id) setEditing(null);\n    const t = window.setTimeout(() => {\n      setLeaving((l) => l.filter((id) => id !== item.id));\n      commit(listRef.current.filter((m) => m.id !== item.id));\n      onForget?.(item);\n    }, 300);\n    timers.current.push(t);\n  }\n\n  function save(item: MemoryItem) {\n    const text = draft.trim();\n    setEditing(null);\n    if (!text || text === item.text) return;\n    const updated = { ...item, text, source: \"you\", confidence: 1 };\n    commit(listRef.current.map((m) => (m.id === item.id ? updated : m)));\n    onEdit?.(updated);\n  }\n\n  const count = list.length - leaving.length;\n\n  return (\n    <>\n      <style href=\"hb-agent-memory-panel\" precedence=\"default\">{css}</style>\n      <div\n        className={`hb-yf3 ${className}`}\n        style={{ \"--hb-yf3-a\": accent, ...style } as React.CSSProperties}\n        {...rest}\n      >\n        <div className=\"hb-yf3-head\">\n          <h3 className=\"hb-yf3-title\">\n            <svg className=\"hb-yf3-brain\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n              <path d=\"M6 2.6a2.2 2.2 0 0 0-2.2 2.2 2.2 2.2 0 0 0-1.4 3.8 2.3 2.3 0 0 0 1.6 3.6A2.1 2.1 0 0 0 6 13.4V2.6zM10 2.6a2.2 2.2 0 0 1 2.2 2.2 2.2 2.2 0 0 1 1.4 3.8 2.3 2.3 0 0 1-1.6 3.6 2.1 2.1 0 0 1-2 1.2V2.6z\" stroke=\"currentColor\" strokeWidth=\"1.3\" strokeLinejoin=\"round\" />\n            </svg>\n            {title}\n          </h3>\n          <span className=\"hb-yf3-count\" aria-live=\"polite\">\n            {count} {count === 1 ? \"fact\" : \"facts\"}\n          </span>\n        </div>\n        {list.length === 0 ? (\n          <div className=\"hb-yf3-empty\">\n            <svg viewBox=\"0 0 24 24\" fill=\"none\" aria-hidden=\"true\">\n              <circle cx=\"12\" cy=\"12\" r=\"9\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeDasharray=\"3 3\" />\n            </svg>\n            <p>Nothing remembered yet</p>\n          </div>\n        ) : (\n          <ul className=\"hb-yf3-list\">\n            {list.map((m, i) => {\n              const isEditing = editing === m.id;\n              const pct = Math.round(Math.min(1, Math.max(0, m.confidence)) * 100);\n              return (\n                <li\n                  key={m.id}\n                  className=\"hb-yf3-item\"\n                  data-leaving={leaving.includes(m.id)}\n                  style={{ \"--hb-yf3-i\": i } as React.CSSProperties}\n                >\n                  <div className=\"hb-yf3-clip\">\n                    <div className=\"hb-yf3-card\">\n                      <div className=\"hb-yf3-body\">\n                        {isEditing ? (\n                          <input\n                            className=\"hb-yf3-input\"\n                            aria-label=\"Edit memory\"\n                            value={draft}\n                            autoFocus\n                            onChange={(e) => setDraft(e.target.value)}\n                            onKeyDown={(e) => {\n                              if (e.key === \"Enter\") save(m);\n                              if (e.key === \"Escape\") {\n                                e.stopPropagation();\n                                setEditing(null);\n                              }\n                            }}\n                          />\n                        ) : (\n                          <p className=\"hb-yf3-text\" title={m.text}>{m.text}</p>\n                        )}\n                        <div className=\"hb-yf3-meta\">\n                          <span className=\"hb-yf3-chip\" style={{ \"--hb-yf3-h\": `hsl(${hueOf(m.source)} 70% 66%)` } as React.CSSProperties}>\n                            <span className=\"hb-yf3-dot\" />\n                            {m.source}\n                          </span>\n                          <span className=\"hb-yf3-conf\" role=\"img\" aria-label={`Confidence ${pct}%`}>\n                            <span className=\"hb-yf3-track\">\n                              <span\n                                className=\"hb-yf3-bar\"\n                                style={{ width: `${pct}%`, \"--hb-yf3-c\": confColor(m.confidence) } as React.CSSProperties}\n                              />\n                            </span>\n                            {pct}%\n                          </span>\n                        </div>\n                      </div>\n                      <div className=\"hb-yf3-actions\">\n                        {isEditing ? (\n                          <>\n                            <button type=\"button\" className=\"hb-yf3-btn\" data-kind=\"save\" aria-label=\"Save memory\" onClick={() => save(m)}>\n                              <svg viewBox=\"0 0 14 14\" fill=\"none\"><path d=\"M2.6 7.4l2.8 2.8 5.6-6\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" /></svg>\n                            </button>\n                            <button type=\"button\" className=\"hb-yf3-btn\" aria-label=\"Cancel edit\" onClick={() => setEditing(null)}>\n                              <svg viewBox=\"0 0 14 14\" fill=\"none\"><path d=\"M3.5 3.5l7 7M10.5 3.5l-7 7\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" /></svg>\n                            </button>\n                          </>\n                        ) : (\n                          <>\n                            <button\n                              type=\"button\"\n                              className=\"hb-yf3-btn\"\n                              aria-label={`Edit: ${m.text}`}\n                              onClick={() => {\n                                setDraft(m.text);\n                                setEditing(m.id);\n                              }}\n                            >\n                              <svg viewBox=\"0 0 14 14\" fill=\"none\"><path d=\"M2.2 11.8l.7-3 6.4-6.4a1.3 1.3 0 0 1 1.9 1.9L4.8 10.7l-2.6 1.1z\" stroke=\"currentColor\" strokeWidth=\"1.3\" strokeLinejoin=\"round\" /></svg>\n                            </button>\n                            <button type=\"button\" className=\"hb-yf3-btn\" data-kind=\"forget\" aria-label={`Forget: ${m.text}`} onClick={() => forget(m)}>\n                              <svg viewBox=\"0 0 14 14\" fill=\"none\"><path d=\"M2.5 3.8h9M5.4 3.8V2.5h3.2v1.3M3.6 3.8l.6 7.7h5.6l.6-7.7M5.8 6v3.6M8.2 6v3.6\" stroke=\"currentColor\" strokeWidth=\"1.3\" strokeLinecap=\"round\" strokeLinejoin=\"round\" /></svg>\n                            </button>\n                          </>\n                        )}\n                      </div>\n                    </div>\n                  </div>\n                </li>\n              );\n            })}\n          </ul>\n        )}\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}