# Groups and relations

> Organize individual residents with several group tags and define relationships within each group through CLI and MCP.

Groups tag *individual residents on the desk*, not Field Guide assets or saved sets. One resident can belong to multiple groups. Each relation definition belongs to one group, and its links connect two distinct members of that group (there are no group-to-group links).

Groups and relations are local metadata only. They never grant control permissions or make residents move or act on their own.

```text title="Data model"
Desk Resident ──M:N── Group (max 256)
                        │ 1:N
                        ▼
                    Relation (max 1,024) ──1:N── Link: from → to (max 16,384)
```

## See memberships

Residents in at least one group show a group mark and count at the right end of their nameplate. Residents with no groups keep the single-line nameplate.

- **Inspect on the desk:** Click the group mark to view all group names. Press `Esc`, click `×`, or click outside to return to the desk. Reading groups works even without a session, while the name row keeps its usual conversation action for session-bound residents.
- **Inspect in Studio:** Studio's desk shelf and selected resident inspector show the same memberships.
- **Identical names:** Residents with identical names can belong to different groups and stay distinct entries. Membership edits and group renames appear once the scene is saved.

## Create a group and a relation

Address residents by individual ID or singular selector from `pixling residents`. Bound residents must be addressed via their own `client:namespace/key` selector.

#### CLI

```sh title="Terminal"
GROUP_ID=$(uuidgen)
RELATION_ID=$(uuidgen)
pixling call group.create "{\"groupID\":\"$GROUP_ID\",\"name\":\"Development\"}"
pixling call group.add "{\"groupID\":\"$GROUP_ID\",\"to\":\"client:codex/lead\"}"
pixling call group.add "{\"groupID\":\"$GROUP_ID\",\"to\":\"client:codex/member\"}"
pixling call relation.define "{\"groupID\":\"$GROUP_ID\",\"relationID\":\"$RELATION_ID\",\"name\":\"Leads\"}"
pixling call relation.link "{\"relationID\":\"$RELATION_ID\",\"from\":\"client:codex/lead\",\"to\":\"client:codex/member\"}"
pixling call relation.links "{\"relationID\":\"$RELATION_ID\"}"
```

#### MCP

MCP exposes the same operations using flat argument objects:
```json title="Create a group (pixling_group_create)"
{
  "name": "pixling_group_create",
  "arguments": {
    "groupID": "11111111-1111-4111-8111-111111111111",
    "name": "Development"
  }
}
```
```json title="Define a relation (pixling_relation_define)"
{
  "name": "pixling_relation_define",
  "arguments": {
    "groupID": "11111111-1111-4111-8111-111111111111",
    "relationID": "22222222-2222-4222-8222-222222222222",
    "name": "Leads"
  }
}
```

- **Preconditions:** Both residents must already exist on the desk. Adding memberships does not create links automatically.
- **Join at creation:** A new resident can join a group immediately using `resident ensure --group-id` or `resident summon --group-id`. This saves the membership with the new resident and spawns it on the desktop where a member was last seen ([Resident binding](/docs/reference/resident-binding/#groupid)).
- **Multiple relations:** The same pair of residents can hold multiple relation types or separate relationships in different groups.
- **Idempotent creation IDs:** Creation accepts optional `groupID`, `relationID`, or `linkID`. Repeating the same explicit ID with identical content is a no-op; reusing it with different content is rejected. Omitting the ID generates a new group or definition on every call.
- **Safe link retries:** Links are keyed by their endpoint pair. Linking an already linked pair (with or without `linkID`) changes nothing and returns the saved link, making lost `relation.link` responses safe to retry.

## Operations

CLI calls use `pixling call <operation> '<json>'` (or `pixling rpc`). MCP tools use `pixling_group_<verb>` and `pixling_relation_<verb>`.

| Operation | Arguments |
| --- | --- |
| `group.list` | `limit?`, `offset?` |
| `group.create` | `name`, `groupID?` |
| `group.rename` | `groupID`, `name` |
| `group.delete` | `groupID`, `clients?` |
| `group.members` | `groupID`, `limit?`, `offset?` |
| `group.add` | `groupID`, `to` |
| `group.remove` | `groupID`, `to`, `clients?` |
| `relation.list` | `groupID`, `limit?`, `offset?` |
| `relation.define` | `groupID`, `name`, `relationID?`, definition fields below |
| `relation.update` | `relationID`, `name`, definition fields below, `clients?` |
| `relation.delete` | `relationID`, `clients?` |
| `relation.links` | `relationID`, `limit?`, `offset?` |
| `relation.link` | `relationID`, `from`, `to`, `linkID?` |
| `relation.unlink` | `relationID`, `from`, `to` |
| `relation.fire` | `relationID`, `from`, exactly one of `to` or `all: true`, `clients?` |

`to` and `from` must resolve to exactly one existing individual (`auto` and `everyone` are rejected). Group and relation IDs are UUIDs from their list operations; names are display labels and need not be unique.

## Definition fields

| Field | Default | Meaning |
| --- | --- | --- |
| `name` | Required | Label for the relationship (nonblank single line, at most 60 graphemes and 240 UTF-8 bytes). |
| `symmetric` | `false` | Whether both endpoint orders represent the same relationship. |
| `color` | None | `#RRGGBB` for the cord and its pulse; omitted renders a neutral cord and white pulse. |
| `width` | `normal` | Cord width: `thin`, `normal`, `thick`, or `heavy`. |
| `glow` | `normal` | Pulse size: `small`, `normal`, or `large`. |

A directed relation preserves `from` and `to`: `A→B` and `B→A` are distinct links, and the cord draws an arrow. A symmetric relation treats `A—B` and `B—A` as one link with no arrow. Individuals have no per-resident link count cap and need not participate in any link. Relations carry no rank or roles.

> [!CAUTION]
> **`relation.update` replaces the entire definition**
> Omitted fields reset to the defaults above. For example, renaming a colored relation without re-sending `color` resets it to neutral. Switching a relation to `symmetric: true` while both `A→B` and `B→A` exist fails with `duplicateLink`; no links are silently merged or dropped.

## Bound residents and cascades

Direct endpoint writes require matching `client:` selectors. Listing a key in `clients` never bypasses a direct selector's binding check.

Cascades and definition edits can touch multiple bound residents. Pass up to 32 `namespace/key` strings in `clients` to authorize all affected bound endpoints before anything changes. Results never expose binding keys.

For example, removing a lead's membership also removes its links to bound members:

```sh title="Terminal"
pixling call group.remove "{\"groupID\":\"$GROUP_ID\",\"to\":\"client:codex/lead\",\"clients\":[\"codex/member\"]}"
```

Deleting a group affects all of its members; updating or deleting a relation affects both endpoints of all its links. Memberships and relations never authorize unrelated resident operations.

## Lifetime and persistence

- **Removing a membership:** Drops only that resident's incident links within that group; other groups stay intact.
- **Deleting a relation or group:** Deleting a relation drops its links. Deleting a group drops its memberships, definitions, and links while leaving the residents untouched.
- **Stowing a resident:** Drops its memberships and incident links while keeping existing client-binding tombstones and empty groups or definitions. Stowing keeps its normal target authorization, and incident links disappear without requiring counterpart keys because the endpoint is gone.
- **Visibility and display changes:** Hiding, minimizing, switching displays or Spaces, disconnecting displays, and unavailable asset packs all preserve memberships and links.
- **Duplicating, summoning, and overlays:** Duplicating a resident copies its memberships and *no links or bindings*. Newly summoned residents and residents added via set overlay start with no memberships.
- **Set replacement:** Retains the graph for retained resident IDs. One-step undo restores residents and the graph together, including links to residents outside the replacement target; any subsequent graph edit invalidates that undo.

Storage and atomicity guarantees:

- **Single transaction:** Graph edits validate, save, and publish the scene atomically. Failed validation or saving leaves the previous valid snapshot intact.
- **Shared revision:** Graph edits share the scene's revision with position saves, so an in-flight position save cannot overwrite a newer relation edit.
- **Local and fail-safe:** No polling, background reconciliation, or network activity occurs. The scene requires the graph field; a malformed document is preserved without resetting.

## Results, limits and refusals

Responses include `revision`, `changed`, and `total`, plus only the collection relevant to the call: reads return one bounded page (`groups`, `memberships`, `relations`, or `links`, empty if none); mutations return touched records; deletes and `relation.unlink` return no collection with `changed: true`.

```json title="group.list response (result)"
{
  "revision": 3,
  "changed": false,
  "total": 1,
  "groups": [
    {
      "id": "11111111-1111-4111-8111-111111111111",
      "name": "Reviewers",
      "memberCount": 2
    }
  ]
}
```

```json title="relation.links response (result)"
{
  "revision": 5,
  "changed": false,
  "total": 1,
  "links": [
    {
      "id": "33333333-3333-4333-8333-333333333333",
      "relationID": "22222222-2222-4222-8222-222222222222",
      "from": "0194e1a2-7b3c-7000-8000-000000000001",
      "to": "0194e1a2-7b3c-7000-8000-000000000002"
    }
  ]
}
```

- **Row shapes:**
  - Group row: `id`, `name`, `memberCount` (empty groups are visible without querying members).
  - Membership row: `groupID`, `entityID`.
  - Relation row: `id`, `groupID`, `name`, `symmetric`, `width`, `glow`, and optional `color`.
  - Link row: `id`, `relationID`, `from`, `to`.
- **`relation.unlink`:** Fails with `linkNotFound` if no saved link joins the pair in that order; directed links must match their saved `from` and `to`.
- **Pagination:** List pages sort by stable UUID, default to `100` records (`limit` `1`–`200`, `offset` default `0`), and return `nextOffset` when more records follow. Compare `revision` across pages if concurrent edits matter, because pages are not a locked snapshot.

| Resource | Limit |
| --- | --- |
| Groups | 256 |
| Memberships | 8,192 |
| Relation definitions | 1,024 |
| Links | 16,384 |
| Entire scene document | 16 MiB |

Limits reject changes before publication; a failed save is never reported as success.

Domain refusals return `rejected` with a closed `detail` code and recovery hint:

| `detail` | Cause |
| --- | --- |
| `groupNotFound` | No group exists with `groupID`. |
| `relationNotFound` | No relation exists with `relationID`. |
| `entityNotFound` | Target resident does not exist on the desk. |
| `notGroupMember` | Resident is not a member of the relation's group. |
| `selfLink` | `from` and `to` resolve to the same resident. |
| `duplicateID` | Explicit `groupID`, `relationID`, or `linkID` was reused with different content. |
| `duplicateLink` | Conflict with an existing link (such as switching to `symmetric: true` with both directions present). |
| `linkNotFound` | No saved link connects the given endpoints in that order. |
| `limitExceeded` | Operation would exceed one of the resource limits above. |
| `boundToAnotherClient` | Caller lacks `client:` or `clients` authorization for a bound resident. |

Malformed arguments return `invalidArguments`. Unavailable graph storage disables graph capabilities.

## Pulse a saved relation

`relation.fire` sends a short train of transient lights along saved links: `count` lights (`1`–`10`, default `3`) depart one after another. Each light renders as a glow in `color` (`#RRGGBB`, defaulting to the relation's color or white) around a thin white core that stays legible on any wallpaper.

Pulsing never mutates scene data or revision, sends no message, wakes no agent, and does not propagate past direct links. Directed links fire from `from` to `to`; symmetric links accept either endpoint as origin.

#### CLI

```sh title="Terminal"
pixling call relation.fire "{\"relationID\":\"$RELATION_ID\",\"from\":\"client:codex/lead\",\"to\":\"client:codex/member\",\"color\":\"#7FD4FF\",\"count\":5}"
pixling call relation.fire "{\"relationID\":\"$RELATION_ID\",\"from\":\"client:codex/lead\",\"all\":true,\"clients\":[\"codex/member\"]}"
```

#### MCP

```json title="MCP tool call (pixling_relation_fire)"
{
  "name": "pixling_relation_fire",
  "arguments": {
    "relationID": "22222222-2222-4222-8222-222222222222",
    "from": "client:codex/lead",
    "to": "client:codex/member",
    "color": "#7FD4FF",
    "count": 5
  }
}
```

### Arguments and authorization

`pixling_relation_fire` arguments:

| Argument | Meaning |
| --- | --- |
| `relationID` | UUID of the saved relation. |
| `from` | Origin resident selector. |
| `to` or `all: true` | Exactly one: a target selector or `all: true` for all outgoing links (up to 32). |
| `clients` | Optional list of up to 32 `namespace/key` strings for bound indirect targets. |
| `color` | Optional strict `#RRGGBB` glow color; any other format fails with `invalidArguments`. |
| `count` | Optional light count: `1`–`10` (default `3`). |

- **Strict target rules:** Omitting both targets, combining `to` and `all`, `all: false`, unknown fields, `auto`, and `everyone` are rejected. `--all` selects every direct outgoing link in that relation; requests exceeding 32 links are rejected in full.
- **Direct endpoint bindings:** Direct bound endpoints require matching `client:` selectors. Passing UUIDs plus `clients` never bypasses direct binding protection.
- **Indirect targets (`all`):** `clients` authorizes bound targets reached indirectly via `all`. Every target (including hidden or filtered targets) is checked before any pulse begins; one missing authorization rejects the entire request with `boundToAnotherClient`.

### Pulse result and refusals

The response returns `relationID`, `graphRevision`, `startedCount`, `suppressedCount`, `remainingMilliseconds`, and `results`. Each row contains `linkID`, individual UUIDs `from` and `to`, and `state: started|suppressed`.

```json title="relation.fire response (result)"
{
  "relationID": "22222222-2222-4222-8222-222222222222",
  "graphRevision": 5,
  "startedCount": 1,
  "suppressedCount": 0,
  "remainingMilliseconds": 1800,
  "results": [
    {
      "linkID": "33333333-3333-4333-8333-333333333333",
      "from": "0194e1a2-7b3c-7000-8000-000000000001",
      "to": "0194e1a2-7b3c-7000-8000-000000000002",
      "state": "started"
    }
  ]
}
```

- An all-suppressed request still succeeds with `startedCount: 0`.
- Binding keys never appear in results.
- `started` confirms the effect was installed and its native owners passed immediate checks, not that anyone saw it or that it finished. Residents are never summoned, moved, or brought forward for a pulse.

Suppressed rows include `reason`:

| `reason` | Cause |
| --- | --- |
| `displayDisabled` | Relation cords or pulses are off on the target display. |
| `filtered` | Relation is excluded by the current display filter. |
| `displayLimit` | Display's static relation display capacity is full. |
| `notVisible` | Resident or endpoint is not currently visible on screen. |
| `ownerUnavailable` | Native desk presentation owner is not available. |
| `lifecycleSuspended` | Desk presentation lifecycle is suspended (for example, paused or inactive). |
| `carried` | An endpoint resident is currently being dragged or carried. |
| `editing` | An endpoint is in an editing state that suppresses pulses. |

Request-level refusals:

| Code | Cause |
| --- | --- |
| `relationNotFound` | No relation exists with `relationID`. |
| `notGroupMember` | `from` or `to` is not a member of the relation's group. |
| `selfLink` | `from` and `to` resolve to the same resident. |
| `linkNotFound` | No saved link connects `from` and `to` in this relation. |
| `invalidDirection` | Directed link exists only in the opposite direction. |
| `noLinks` | `all: true` found no direct outgoing links from `from`. |
| `boundToAnotherClient` | Caller lacks authorization for a direct or indirect bound endpoint. |
| `tooManyLinks` | `all: true` matched more than 32 outgoing links. |
| `busy` | Presentation layer is temporarily busy; may include `retryAfterMilliseconds`. |
| `capacityExceeded` | Active-effect capacity reached; may include `retryAfterMilliseconds`. |
| `rateLimited` | Pulse rate limit reached; may include `retryAfterMilliseconds`. |

Static display capacity has no retry time; narrow the display selection in Studio instead. Hidden or filtered targets never retry automatically.

> [!CAUTION]
> **Do not auto-retry a lost pulse response**
> Every call starts a fresh pulse. There is no deduplication, queue, delayed receipt, or replay when a Space becomes active again. The capability is advertised only when graph, binding, selector, and presentation services are installed, and unavailable graph or binding reads fail closed.

## Related

- [Resident binding](/docs/reference/resident-binding/): Join a group at creation time with groupID and manage client: selectors.
- [Light (glow)](/docs/reference/light/): Play standalone pixel lights directly on an individual resident.
