# Agent permissions matrix

What each agent may do with each tool, as one grid: allow, ask or deny per cell, set by row, column or brush.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Agent permissions matrix. Four agents and eight tools from three connectors. Paint across cells, set a row or column from its header, then save. Preview: https://chatcn.dev/preview/agent-permissions-matrix-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/agent-permissions-matrix
```

## Usage

```tsx
import { AgentPermissionsMatrix } from "@/components/ui/chatcn/pro/agent-permissions-matrix"

<AgentPermissionsMatrix
  tools={[
    { id: "gh-merge", group: "GitHub", name: "merge_pull_request", label: "Merge pull requests", risk: "destructive" },
    { id: "sl-read", group: "Slack", name: "search_messages", label: "Search messages", risk: "read" },
  ]}
  columns={[
    { id: "support", label: "Support", description: "Replies to customers" },
    { id: "coding", label: "Coding", description: "Works in the repo" },
  ]}
  value={saved}                       // { [toolId]: { [columnId]: "allow" | "ask" | "deny" } }
  onSave={(draft) => savePolicy(draft)}
/>
```

Rows are tools, grouped by the connector they come from; columns are whatever you grant to: agents, surfaces or environments. A click cycles a cell through allow, ask and deny. Every header is a menu that sets its whole row, column or connector at once, and the brush in the toolbar paints: pick allow, ask or deny, then click or drag across cells. Edits stay a draft: changed cells carry a dot, the footer counts them, Discard puts everything back and nothing applies until Save. Tools marked `destructive` (they delete, send or spend) are outlined in amber and counted in the toolbar whenever they are allowed to run without asking. A missing cell reads as ask. On narrow screens the grid scrolls inside its frame with the tool names pinned.

## Examples

### States

Example: States. Tools without connector groups, and a narrow frame where the grid scrolls with the tool names pinned. Preview: https://chatcn.dev/preview/agent-permissions-matrix-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `tools` | `MatrixTool[]` | `{ id, name, label?, group?, risk? }`; rows, grouped by `group` |
| `columns` | `MatrixColumn[]` | `{ id, label, description? }` |
| `value` | `PermissionMatrix` | The saved permissions; edits are a draft on top |
| `onDraftChange` | `(draft) => void` | Every edit |
| `onSave` | `(draft) => void | Promise<void>` | Throw to keep the draft |
| `labels` | `Partial<AgentPermissionsMatrixLabels>` | Every string, for translation |

## Keyboard

| Key | Action |
| --- | --- |
| Tab | Enters the grid at the last cell used; one tab stop |
| Arrow keys | Move between cells (reversed right to left) |
| Home, End | First or last cell in the row; with Ctrl or Cmd, in the grid |
| Space, Enter | Cycle allow, ask, deny |
| Y, A, N | Allow, ask, deny |

## Accessibility

- A real table with row and column headers; each cell is a button named by tool, column and value.
- The header menus name what they set: Set all for Coding.
- The change count is a polite live region.
- Values carry an icon and a word, never color alone.

## Motion

Cells change color over 150 ms. Nothing else moves.

Source: https://chatcn.dev/docs/components/agent-permissions-matrix