# Build expression

> Say something, ask, show a state, signal, and plan motion with your resident.

Pixling does not decide what "working", "waiting", or "done" look like. You choose, per resident, from the motions and settings it reports. The examples below target `client:my-agent/conversation-1`, the resident bound in [Give your agent a resident](/docs/connect/own-a-resident/).

## Choose the right channel

| Channel | Best for | Persists? | Key requirement |
| --- | --- | --- | --- |
| **Message / Question** (`message.send`, `question.ask`) | Updates, saved letters, and choices | Kept in conversation until stowed | Needs visible or queued bubble (refused on wallpaper) |
| **Status** (`resident.status`, `status.define`) | Ongoing mode (`loading`, `waiting`) | Temporary (10 min default; definitions saved) | Requires `motionEnabled: true` (newly ensured residents start stopped) |
| **One-off signal** (`emote`, `bounce`, `glow`, `throw`) | Quick visual reaction or physical nudge | Forgotten on finish (`throw` saves landing spot) | Skips when hidden or on wallpaper |
| **Sequence** (`sequence.start`) | Choreographed multi-step timing, cuts, speech, light | `commit: restore` reverts; `onSuccess` saves | Max 32 steps (128 expanded), 30 s total |

```sh title="Try it in 10 seconds (CLI)"
pixling resident set --to client:my-agent/conversation-1 --motion true
pixling resident emote --to client:my-agent/conversation-1 --text "♪"
```

## Say something

```json title="pixling_message_send"
{
  "to": "client:my-agent/conversation-1",
  "text": "Tests pass. Opening the PR.",
  "author": "My Agent"
}
```

`pixling_message_send` returns a receipt with an `outcome`:

| `outcome` | Meaning |
| --- | --- |
| `spoke` | In the visible part of the resident's window when accepted. |
| `queued` | Accepted, not yet seen (below scroll, or waiting on keyboard or VoiceOver focus). Do not resend. |
| `held` | Kept until the resident can show it; `heldBecause` says why. |

`notVisible`, `notOnDesk`, and `rejected` explain why a message was not shown; see [receipts](/docs/reference/messages-and-questions/#receipts-and-several-targets).

- **History stays until trimmed**: Every message stays in the window, oldest at the top, and nothing expires on a timer. The window keeps the newest 200 cards, letters included.
- **Mark important reports as letters**: Add `"keep": true` for a report the user should find later; it becomes a letter marked `✉` in the window.
- **Accepted is not read**: A receipt confirms acceptance, not that someone read it. `waiting` counts unseen messages and letters ahead of this one (excluding this message and questions).

## Ask

```json title="pixling_question_ask"
{
  "to": "client:my-agent/conversation-1",
  "requestID": "deploy-1",
  "question": "Deploy to staging now?",
  "choices": [
    {"id": "yes", "label": "Deploy"},
    {"id": "later", "label": "Not now"}
  ]
}
```

`pixling_question_ask` shows a card with 2–6 choices plus a row where the user can type their own answer, and waits for the reply.

- **On timeout**: Returns `pending` with a `promptID`. Wait again using `pixling_question_result` with that `promptID`.
- **Answered while nobody is waiting**: For a bound resident, the answer goes to its inbox as `kind: answer`. Otherwise it waits for the next `pixling_question_result`.

Limits and every field: [Messages and questions](/docs/reference/messages-and-questions/).

## Show a state

```json title="1. Define once — pixling_status_define"
{
  "to": "client:my-agent/conversation-1",
  "name": "loading",
  "hold": {"animation": "sequence:typing"}
}
```

```json title="2. Activate or extend — pixling_resident_status"
{
  "to": "client:my-agent/conversation-1",
  "name": "loading"
}
```

Define each state name once per asset with `pixling_status_define`: `enter` plays a saved sequence once on start, and `hold` sets the idle motion or pose that stays. Activate it with `pixling_resident_status` without saving anything, and resend the call to extend it. You can also pass `animation` or `pose` directly instead of `name`.

- **Attach to messages or questions**: `message.send` and `question.ask` also accept `"status": "<name>"`. A question's state lasts while the question is open and restores the previous state when it ends.
- **Automatic cleanup**: A new call replaces the state; `clear` or expiry (10 minutes by default) restores the resident's usual look.
- **When a state yields**: An undefined name shows nothing (`yieldsTo: unbound`) until you define it. If the user pinned a pose or turned Motion off, nothing changes and `yieldsTo` names why.

> [!CAUTION]
> **Bound residents start with Motion off**
> A resident created by `resident.ensure` starts with **Motion** off. Turn it on with [`pixling_resident_set`](/docs/reference/resident-settings/) (`motionEnabled: true`) so states can show.

See [status](/docs/reference/residents/#pixling_resident_status).

## Give a one-off signal

```json title="pixling_resident_glow"
{
  "to": "client:my-agent/conversation-1",
  "select": "all",
  "shape": "pulse",
  "durationMs": 800
}
```

```json title="pixling_resident_emote"
{
  "to": "client:my-agent/conversation-1",
  "text": "♪"
}
```

```json title="pixling_resident_bounce"
{
  "to": "client:my-agent/conversation-1",
  "strength": 0.6,
  "direction": "down"
}
```

- `pixling_resident_glow` lights the resident once ([Light (glow)](/docs/reference/light/)).
- `pixling_resident_emote` pops a short emote above it ([Emotes](/docs/reference/residents/#pixling_resident_emote-and-pixling_resident_throw)).
- `pixling_resident_bounce` squashes its body against a side and springs it back, like hitting a wall ([Bounce](/docs/reference/residents/#pixling_resident_bounce)).

Every one-off signal is forgotten as soon as it finishes.

## Plan motion

```json title="pixling_sequence_start"
{
  "schemaVersion": 2,
  "requestID": "greeting-1",
  "to": "client:my-agent/conversation-1",
  "commit": "restore",
  "dryRun": true,
  "steps": [
    {
      "kind": "repeat",
      "times": 2,
      "steps": [
        {
          "kind": "cut",
          "holdMs": 1200,
          "say": {"text": "Hello", "author": "My Agent"},
          "glow": [{"select": "all", "shape": "pulse", "durationMs": 334}]
        }
      ]
    }
  ]
}
```

Send the whole plan at once and let Pixling keep time. The plan above says hello and pulses twice, totaling 2400 ms.

- **Inspect the body first**: Call [`pixling_resident_describe`](/docs/reference/resident-settings/) with `"sections":["sequence"]` for available motions, frame counts, and color groups, and `pixling_resident_sketch` for an ASCII sketch.
- **Validate before playing**: `dryRun: true` validates the plan without running it; resend with `dryRun: false` to play. With `commit: restore`, the resident returns to its starting state when the sequence ends or is canceled.
- **Plan limits**: Up to 32 steps (128 after `repeat`), at most 30 seconds total, and at most 10 seconds per cut. See [Sequences](/docs/reference/sequences/).

## Target several residents

Pass an array of 1–32 selectors in `to`:

```json title="pixling_message_send (multiple targets)"
{
  "to": ["client:my-agent/moku", "client:my-agent/piko"],
  "text": "Check finished",
  "author": "My Agent"
}
```

- **All-or-nothing lookup**: Every selector resolves before anything sends; if any selector is invalid or missing, nobody receives the message.
- **Per-resident bindings**: Each resident enforces its own binding, so a resident you cannot write to gets a `rejected` receipt.
- **Check every outcome**: `summary` counts outcomes across targets; inspect `receipts` for each resident.
- **Disallowed selectors**: `auto` and `everyone` cannot appear inside an array.

Full rules: [several targets](/docs/reference/messages-and-questions/#receipts-and-several-targets).

## Restore exact size and position

Before resizing a resident, read its `scale` from [`pixling_resident_describe`](/docs/reference/resident-settings/) with `"sections":["resident"]`, then pass it back to `pixling_resident_place`:

```json title="pixling_resident_place"
{"to": "client:my-agent/conversation-1", "scale": 2.5396825396825395}
```

- **Use `scale`, not `size`**: `size` snaps to the pixel grid (asking for `size: 160` again can produce `157.5`), while `scale` is applied as read.
- **Position and direction**: Restore position from `footprint.x` and `footprint.y`, and facing direction from `mirrored`.
- **Display changes**: If the screen changed in between, identical size and position are not guaranteed.

Details: [restoring an exact size](/docs/reference/residents/#restoring-an-exact-size).

## Next steps

- [Messages and questions](/docs/reference/messages-and-questions/): Receipts, multi-target rules, letters, and question limits.
- [Residents reference](/docs/reference/residents/): Status, emotes, bounce, placement, and exact size restoration.
- [Resident settings reference](/docs/reference/resident-settings/): Describe, set, speech paper styling, and gravity options.
- [Sequences reference](/docs/reference/sequences/): Full schema for timed multi-step motion plans.
