# Memory

What an agent remembers, grouped and editable, and the ring that draws what it knows and what it can reach.

Live variants: https://design.arcadia.is/components/memory-panel

```tsx
import { MemoryPanel, MemoryGraph } from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import { MemoryPanel, Button } from "@arcadia/ui";

function Live() {
  const [items, setItems] = useState<MemoryItem[]>(MEMORIES);
  const [on, setOn] = useState(true);
  const [recalling, setRecalling] = useState<readonly string[]>([]);
  const [learning, setLearning] = useState<readonly string[]>([]);
  const [using, setUsing] = useState<readonly string[]>([]);
  const calm = () => {
    setRecalling([]);
    setLearning([]);
    setUsing([]);
  };
  return (
    <MemoryPanel
      memories={items}
      agent={MemoryPanelAGENT}
      sources={MemoryPanelSOURCES}
      now={MemoryPanelNOW}
      enabled={on}
      onEnabledChange={setOn}
      recalling={recalling}
      learning={learning}
      using={using}
      controls={
        <>
          <Button size="sm" variant="ghost" icon="search" onClick={() => { calm(); setRecalling(["budget"]); }}>Recall the budget</Button>
          <Button size="sm" variant="ghost" icon="sprout" onClick={() => { calm(); setLearning(["migration"]); }}>Learn the migration</Button>
          <Button size="sm" variant="ghost" icon="folder" onClick={() => { calm(); setUsing(["mail"]); }}>Use Mail</Button>
          <Button size="sm" variant="ghost" onClick={calm}>Calm</Button>
        </>
      }
      onEdit={(id, text) => setItems((current) => current.map((memory) => (memory.id === id ? { ...memory, text } : memory)))}
      onPause={(id, paused) => setItems((current) => current.map((memory) => (memory.id === id ? { ...memory, paused } : memory)))}
      onForget={(id) => setItems((current) => current.filter((memory) => memory.id !== id))}
      onRestore={(memory) => setItems((current) => [memory, ...current])}
      onAdd={() => setItems((current) => [{ id: "added-" + current.length, text: "A memory to write", category: "Preferences", source: "From chat" }, ...current])}
    />
  );
}
```

## Accessibility

The ring is one group with a spoken hint. Arrow keys move between what the agent remembers, the agent itself and its sources; the up and down keys walk a side, Home and End reach its ends, and Enter opens the node with focus. Escape closes a detail and hands focus back to the node that opened it. The connectors are decoration and are hidden from a reader, and the status line is polite, so a retrieval is heard without interrupting.

The category chips are a radiogroup of one Tab stop: the arrow keys move within it, and the chip the filter rests on is the one Tab reaches. A memory's actions sit in its menu, so they are reached by the keyboard the menu is, and an action its host forbids is absent rather than dimmed.

The search glyph is a button named Search memories, with aria-expanded while its field stands; opening moves the focus into the field, where Escape clears it, closes it and hands the focus back. In the compact form the field carries its name on the input itself, so it is still Search memories with no visible label. The footer count is a line of text, and New memory is the same button wherever it stands.

## API reference

### MemoryPanel

- `memories` (`readonly MemoryItem[]`, required): What it remembers, in the product's order; the panel groups them by category.
- `title` (`string`, default `"Memory"`): The panel's name.
- `variant` (`"default" | "compact"`, default `"default"`): `compact`: the Profile's denser form, with no filters, no bar and no count, and the view toggle in the header.
- `agent` (`MemoryAgentNode`): The agent whose memory it is: with it the panel offers the graph, and the graph draws it.
- `sources` (`readonly MemorySourceNode[]`): The tools and sources the agent can reach: the graph's right arc.
- `recalling` (`readonly string[]`): Real events: the ids of the memories it is recalling now.
- `learning` (`readonly string[]`): Real events: the ids of the memories it is learning now.
- `using` (`readonly string[]`): Real events: the ids of the sources it is using now.
- `enabled` (`boolean`): The master switch, controlled.
- `defaultEnabled` (`boolean`, default `true`): Its state when uncontrolled.
- `onEnabledChange` (`(enabled: boolean) => void`)
- `showEnabledSwitch` (`boolean`, default `true`): `false`: no master switch, so a host draws its own scope controls. One shows when the panel is told the state or what to do with a change.
- `view` (`"list" | "graph"`): The view, controlled.
- `defaultView` (`"list" | "graph"`, default `"list"`): The view it opens on when uncontrolled.
- `onViewChange` (`(view: MemoryViewMode) => void`)
- `views` (`readonly MemoryViewMode[]`): The views the toggle offers. Default: the list, and the graph when `agent` is given.
- `loading` (`boolean`, default `false`): The memories are still being read.
- `error` (`ReactNode`): Why they could not be read.
- `onEdit` (`(id: string, text: string) => void`): A memory's text was edited in place and kept.
- `onRequestEdit` (`(memory: MemoryItem) => void`): Edit runs the host's own flow (a dialog with a scope choice) instead of the field in the row.
- `onPause` (`(id: string, paused: boolean) => void`)
- `onForget` (`(id: string) => void`)
- `onRestore` (`(memory: MemoryItem) => void`): Undo puts a forgotten memory back.
- `undoFor` (`number`, default `5000`): How long the undo stands, in ms.
- `onAdd` (`() => void`)
- `onRequestAdd` (`() => void`): New memory runs the host's own flow instead of a plain add.
- `headerExtra` (`ReactNode`): One control at the header's end, beside the master switch.
- `controls` (`ReactNode`): Controls in the panel's bar, beside the view toggle.
- `readOnly` (`boolean`, default `false`): No edit, pause, forget or add: a reader's view.
- `now` (`number`): The clock relative dates count from. A server-rendered surface must pass a fixed value, so its markup matches the browser's first render.
- `filters` (`boolean`, default `true`): The category filters, shown when there are two categories or more. And false in a compact panel unless a host asks for them.
- `search` (`"field" | "icon"`, default `"field"`): The search: the field under the filters, or a glyph in the bar that opens it.
- `footer` (`boolean`, default `false`): The count in a quiet footer under the list, instead of beside the title.
- `addPlacement` (`"bar" | "list-end"`, default `"bar"`): Where New memory stands: in the bar, or as the list's last row.
- `fit` (`boolean`, default `false`): The ring as tall as what it holds, under its maximum.
- `rootStyle` (`MemoryPanelStyle`)

### MemoryGraph

- `agent` (`MemoryAgentNode`, required): The agent in the middle: its mark, its name, and what it is doing where no real event says.
- `memories` (`readonly MemoryItem[]`, required): What it remembers, on the left arc; six slots, filled from the middle out, the rest behind +N more.
- `sources` (`readonly MemorySourceNode[]`, default `NO_SOURCES`): The tools and sources it can reach, on the right arc.
- `recalling` (`readonly string[]`, default `NO_IDS`): Memories it is recalling now: only their connectors light.
- `learning` (`readonly string[]`, default `NO_IDS`): Memories it is learning now: only their connectors light.
- `using` (`readonly string[]`, default `NO_IDS`): Sources it is using now: only their connectors light.
- `now` (`number`): The clock relative dates count from. A server-rendered surface must pass a fixed value, so its markup matches the browser's first render.
- `onEdit` (`(id: string, text: string) => void`)
- `onRequestEdit` (`(memory: MemoryItem) => void`)
- `onPause` (`(id: string, paused: boolean) => void`)
- `onForget` (`(id: string) => void`)
- `onToggleSource` (`(id: string, enabled: boolean) => void`)
- `readOnly` (`boolean`, default `false`): No Edit, Pause, Forget or source toggle: a reader's view.
- `fit` (`boolean`, default `false`): As tall as what it holds, under its maximum: the used slots and the agent, without the empty ring.
- `rootStyle` (`MemoryGraphStyle`): Typed StyleX override: where it sits and its height.
