# Roles and permissions

> Which commands your end users may trigger, and how you as the customer change that.

## The roles

| Role | Who | Typical commands |
|---|---|---|
| **User** | your end user: visitor of your web page, person clicking the HTML UI or talking to the digital human | volume, fullscreen, language, microphone, character, room, transparency, chat |
| **Customer** | you and your tools or agents | designing the UI, personality, loading texts, screenshots, the user policy, guided processes |
| Avataris | Aimigo's own host integration and tooling | not available to customers or users |

The roles are ordered: Customer may do everything User may do. Every command declares the lowest role that may use it ([command reference](https://aimigo.live/docs/mcp-reference.md), column *Role*).

**Not permitted means invisible:** a command or skill you may not use is missing from `aimigo.commands.list`, `aimigo.commands.search` and `aimigo.skills.list`; `aimigo.commands.get` answers `CommandNotFound`, and calling it answers `PermissionDenied`.

## Which role a caller has

| Where the call comes from | Role |
|---|---|
| Your web page (`dh.call`, the player protocol) | User — page scripts are under the visitor's control (developer tools) |
| HTML UI inside the app | User — a click must not do more than the person clicking may |
| The digital human's own AI acting for the person it talks to | User |
| A program on the same computer calling the app's local HTTP port | set by the app build: Customer in customer builds |
| A web page calling the app's local HTTP port | User, and only from origins the access policy lists; all others are rejected |

## What end users may do: the user policy

As the customer you decide which commands your end users may trigger — through the UI, through the digital human, and from the web page.

- **Take away** user commands, for example forbid switching the room: `userDeny: ["aimigo.scene.set"]`.
- **Grant** customer commands to users, for example let users restyle the UI: `userAllow: ["aimigo.ui.*"]`.

Patterns:

| Pattern | Matches |
|---|---|
| `aimigo.scene.set` | exactly this command |
| `aimigo.ui.*` | every command starting with `aimigo.ui.` |
| `category:Personality` | every command of a category (categories: see the [reference](https://aimigo.live/docs/mcp-reference.md)) |
| `skill:html-ui-design-binding` | one skill |
| `skill:*` | every skill |

Rules: case does not matter; **deny wins over allow**; commands reserved for Avataris can never be granted.

### Setting it in the app

```js
await call('aimigo.permissions.setUserPolicy', {
  userDeny:  ['aimigo.scene.set', 'category:Personality'],
  userAllow: ['aimigo.ui.setGlass'],
  persist: true            // keep it on this device (default true)
});
await call('aimigo.permissions.getUserPolicy', {});   // shows the effective user commands and skills
await call('aimigo.permissions.setUserPolicy', { reset: true });   // back to the policy shipped with the build
```

Both commands need the role Customer. `getUserPolicy` also lists `grantableToUsers`: the customer commands you may grant.

A customer build can also ship its policy as a file (`AccessPolicy.json`):

```json
{
  "userAllow": [],
  "userDeny": ["aimigo.scene.set"]
}
```

### On web pages

> [!PLANNED]
> **Per-customer policy from your Aimigo account.** Web pages run with the role User and cannot call `setUserPolicy` (a visitor could do the same). The policy for your web pages will be set in your Aimigo account and delivered to the player with a token signed by the Aimigo server. Until then web pages use the default user policy shown in the [reference](https://aimigo.live/docs/mcp-reference.md).

Your page can always offer *less* than the policy allows: it simply does not call a command or show a button for it.

## Testing what a user sees

- `aimigo.permissions.getCaller {}` tells every caller its role and how many commands it may use.
- On the app's local HTTP port, send `X-Aimigo-Role: user` to see the app exactly as an end user (a caller can lower its role, never raise it).
