# Role matrix

What each role can do, as a matrix. It explains the app's roles rather than editing them. A qualified yes says its condition in words; a missing cell reads as no.

- Registry name: `role-matrix` (`@candor/role-matrix`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/role-matrix

## Install

```bash
npx candor-ui add role-matrix
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/role-matrix`.
It brings in: locale, utils.
npm packages: lucide-react@^1.67.0.

## Example

```tsx
"use client"

import { RoleMatrix, type RoleColumn, type RoleRow } from "@/components/role-matrix"

const columns: RoleColumn[] = [
  { id: "viewer", label: "Viewer" },
  { id: "member", label: "Member" },
  { id: "approver", label: "Approver" },
  { id: "admin", label: "Admin" },
]

const rows: RoleRow[] = [
  { capability: "Read threads and run logs", cells: { viewer: true, member: true, approver: true, admin: true } },
  { capability: "Ask agents to change Staging", cells: { member: true, approver: true, admin: true } },
  { capability: "Approve a migration to Production", cells: { approver: "Not their own request", admin: "Not their own request" } },
  { capability: "Connect repositories", cells: { admin: true } },
  { capability: "Manage members and roles", cells: { admin: true } },
]

export default function Example() {
  return <RoleMatrix className="max-w-2xl" columns={columns} rows={rows} />
}
```

## <RoleMatrix>

Props:

- `columns: RoleColumn[]`: The roles, one column each.
- `rows: RoleRow[]`: One capability per row, with a cell per role id; a missing cell reads as no.
- `className?: string | undefined`

## Strings (`roleMatrix`)

The fixed words, English by default. Override any of them under `roleMatrix` in `<LocaleProvider strings={{ roleMatrix: { … } }}>`; the table is exported as `roleMatrixStrings`.

- `can`: Can…
- `yes`: Yes
- `no`: No

## Types

### RoleCell

```ts
boolean | string
```

### RoleColumn

```ts
{ id: string; label: string }
```

### RoleRow

One capability; each cell is yes, no, or a condition in words.

```ts
{ capability: string; cells: Record<string, RoleCell> }
```

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
