---
name: gujizai-motion
description: Create and revise editable posture-and-expression action chains for the Gujizai (咕機仔) workbench using its versioned JSON motion format. Use for simulated choreography, timing, and code-to-block editing; not for firmware or hardware control.
---

# Gujizai motion

Generate motion code that the [Gujizai workbench](https://kehan.foo/gujizai/workbench/) interprets as editable blocks. This is a JSON data format, not executable JavaScript. The workbench has no embedded model API; users can bring code from any AI.

## Read the active contract

- Read [protocol.md](protocol.md) for fields, defaults, inheritance, and expression timing. Online: [protocol](https://kehan.foo/gujizai/workbench/ai/protocol.md).
- Read [capabilities.json](capabilities.json) for published module versions, joint ranges, and available expression IDs. Online: [current public capabilities](https://kehan.foo/gujizai/workbench/ai/capabilities.json).
- Use [motion.schema.json](motion.schema.json) to check structure and [examples.json](examples.json) for complete working examples. Online: [schema](https://kehan.foo/gujizai/workbench/ai/motion.schema.json), [examples](https://kehan.foo/gujizai/workbench/ai/examples.json).

When the user provides context copied from the workbench, use its loaded module versions, limits, expressions, and current motion code in preference to public capabilities. A saved project can be pinned to older modules or use different simulation limits. Public capabilities describe the current published modules; they do not override that project. Without copied context, fetch public capabilities for this request. If neither is available, obtain the workbench context before choosing angles or expressions; do not invent IDs or claim freshness.

## Produce an action chain

Output one complete JSON object with `format: "gujizai-motion"`, `version: 1`, a nonempty `name` of at most 80 characters, and 1–64 `blocks`. Add `playback` only when needed. When the user asks for importable code, return the JSON without surrounding explanation. Do not output a schema, full project file, patch, function, or pseudocode in its place.

- Use only `head`, `arms`, `expression`, `wait`, `home`, and `pose`. Joint IDs and expression IDs are stable identifiers, not translated display names. Use exact IDs from the active context.
- Angles are absolute model-relative degrees; all times are milliseconds. Provide both controlled axes for `head` or `arms`, and all four for `pose`. Stay inside the active simulation limits. These ranges do not establish real hardware safety.
- A chain starts at four-axis zero with `calm`. A block inherits joints it does not control. `head`, `arms`, `home`, and `wait` normally keep the current expression and its clock. `expression` and a normal `pose` restart the selected expression at the block's start, even when its ID is unchanged. Use the documented `keepExpression` rules when an edit must preserve continuity.
- Use `minjerk` unless the requested style suggests another supported easing. Distinguish moving time from the subsequent `holdMs`. Leave enough time before the next expression reset if its animation should finish; use duration metadata from the active capabilities.
- Omitted `playback` means one pass. For a loop, use `{"loop":true,"returnMs":800}` or another requested return duration. The return brings all joints to zero while the expression clock continues, then the next pass starts anew.

This short example demonstrates inheritance; verify `curious` and these angles against the active context before reusing it:

```json
{
  "format": "gujizai-motion",
  "version": 1,
  "name": "好奇地看过来",
  "blocks": [
    {"kind": "expression", "expressionId": "curious", "holdMs": 100},
    {"kind": "head", "pose": {"head_yaw": 8, "head_pitch": 3}, "moveMs": 900, "holdMs": 600},
    {"kind": "home", "moveMs": 1000}
  ]
}
```

## Edit and iterate

For a revision, start from the user's current motion code and change only the requested behavior. Preserve unrelated block order, labels, absolute targets, expression resets or continuity, timing, easing, and playback. Changing block order also changes inherited poses and expression timing; check the resulting chain rather than treating each block as an isolated snapshot.

Check the result against the schema **and** the active limits and expression IDs. Structural schema validation alone cannot establish compatibility with a loaded project. If an interpreter is available, use its `importMotionJSON` with that project's context. Otherwise have the user use the workbench's code check before applying it, and do not claim the result was executed.

The user can apply valid code as blocks, preview or edit those blocks, then retrieve the current code for the next AI revision. If validation reports an error, use the exact block number and message to correct the complete JSON. Motion code carries choreography and playback; the workbench applies it to its current project without replacing model pins or limits. Use the workbench's full project export separately when those settings must travel with the file.
