# Motion Mesh — AI-Driven Skeletal Animation Toolchain (WoW-style → Bevy)

A toolchain for creating bone-rigged, animated character models in a
"World of Warcraft"-like stylized artstyle, built for a Rust/Bevy target game.
The development itself is driven by AI agents running under the **pi coding
harness**, using three extensions that are all kept **local to this directory**.

---

## 1. Core Loop (the three extensions)

| Role | Extension | What it does here |
|---|---|---|
| **/goal** — set the current development target | [`pi-goal-x`](https://github.com/tmonk/pi-goal-x) | `/goal "Rig and skin the base humanoid so it imports into Bevy with 4 walk anims"` — persistent goal with progress tracking and an *independent completion auditor*, so the agent keeps iterating until the target is verifiably met. Supports ordered sub-goals, which maps well to the pipeline stages (mesh → rig → skin → animate → export). |
| **Subagents** — delegate subtasks | [`pi-subagents`](https://github.com/nicobailon/pi-subagents) | Delegates isolated tasks to specialized agents (see §4) with their own context windows: mesh cleanup, bone naming audit, animation export validation, Bevy integration test. |
| **Memories** — persist art/pipeline knowledge | [`pi-memory`](https://github.com/jayzeng/pi-memory) | Semantic search over long-term memory: artstyle rules (chunky proportions, hand-keyed 30 fps look), bone naming conventions, glTF/Bevy export quirks discovered along the way, model decisions. |

### Why these picks

- **pi-goal-x** (v0.35.x, most mature of the ~20 goal packages on npm):
  conversational goal drafting, flexible *or* ordered goals, persistent
  progress, and an independent completion auditor (the executor can't
  self-certify "done" — important for asset pipelines where "done" means
  "validates in Bevy").
  *Alternatives:* `pi-goal` (budget-limited loops), `@narumitw/pi-goal`,
  `pi-goal-with-auditor`. Only install **one** — goal extensions conflict.
- **pi-subagents** (v0.90.x): single-agent delegation *and* scripted
  multi-agent workflows (prompt templates like scout → plan → implement),
  parallel streaming, per-task usage display. Agent definitions are just
  Markdown files (`.pi/agents/*.md`) — perfect for role-specialized art
  agents. *Alternative:* copy pi's built-in `examples/extensions/subagent/`.
- **pi-memory** (v0.4.x): qmd-powered semantic search across daily logs,
  long-term memory and scratchpad — so lessons like "Bevy 0.16 needs
  `GltfPlugin` custom skinning flags" are recallable, not re-discovered.
  *Alternatives (simpler, no qmd binary):* `@amaster.ai/pi-memory`
  (MEMORY.md/USER.md frozen snapshot), `@tylerho/pi-memory`
  (Claude-Code-style + idle "dream" consolidation), `pi-memory-md`
  (Letta-like structured markdown in git).

---

## 2. "All local" strategy

`pi install <local-path> --local` registers a package **by path, without
copying** — the declaration is written to `.pi/settings.json` (loaded after
project trust). We vendor each extension's source as a **git submodule pinned
to a commit**, so everything lives in this repo, works offline, and is
reviewable/auditable:

```text
motion-mesh/
├── .pi/
│   ├── settings.json        # package declarations (pi install --local)
│   ├── agents/              # pi-subagents agent definitions (markdown)
│   │   ├── sculptor.md      #   high/low-poly modeling, retopo
│   │   ├── rigger.md        #   skeleton creation, bone naming audit
│   │   ├── animator.md      #   hand-keyed WoW-style animation clips
│   │   ├── exporter.md      #   glTF validation, Bevy import checks
│   │   └── reviewer.md      #   style-guide & pipeline review
│   ├── extensions/          # our own project-local extensions (hot-reloadable)
│   └── prompts/             # workflow templates (subagent orchestration)
├── vendor/                  # git submodules, pinned to commits
│   ├── pi-goal-x/           # ← /goal
│   ├── pi-subagents/        # ← delegation
│   └── pi-memory/           # ← memories
├── extensions/              # our own pi package resources (see §3)
│   ├── extensions/          #   asset-pipeline tools exposed to the agent
│   ├── skills/              #   artstyle guide, rigging rules, bevy-export
│   └── prompts/
├── assets/                  # source art (Blender files, meshes, rigs)
├── pipeline/                # validation scripts, glTF→Bevy export checks
└── PLAN.md
```

> **Local package caveat:** pi does not install/modify local path packages, so
> each vendored package's dependency tree is our responsibility — run
> `npm install` inside each `vendor/*` checkout after cloning/updating.
> Declare host-provided packages (`@earendil-works/pi-*`, `typebox`) only in
> `peerDependencies` — never bundle them.

---

## 3. Motion Mesh itself is also a pi package

`extensions/` (root) is our own package so the agent gets domain tools and
knowledge, loaded alongside the vendored ones:

- **`extensions/extensions/`** — TypeScript pi extensions registering tools:
  - `validate_rig` — check bone hierarchy, naming, weights, poly budget
  - `export_gltf` — run the Blender/glTF export with pipeline presets
  - `check_bevy_import` — load the glTF with the Bevy asset loader (headless
    `cargo` test in the target game) and report errors
- **`extensions/skills/`** — `wow-artstyle.md`, `rigging-conventions.md`,
  `bevy-asset-integration.md`
- **`extensions/prompts/`** — reusable workflows, e.g.
  `new-character.md`: sculptor → rigger → animator → exporter → reviewer

---

## 4. How the loop works end-to-end

1. **You** type `/goal "Create orc-grunt: rigged, 5 anims, validated in Bevy"`.
   *pi-goal-x* drafts an ordered goal plan (mesh → rig → skin → animate →
   export → validate) and keeps the agent on it across sessions.
2. The **orchestrator** delegates each stage via *pi-subagents*:
   `sculptor` produces the mesh → `rigger` builds/audits the skeleton →
   `animator` hand-keys the clips → `exporter` runs glTF export +
   `check_bevy_import` → `reviewer` checks against the artstyle skill.
3. *pi-goal-x's* independent auditor verifies the goal against evidence
   (validation tool results), not the workers' claims.
4. *pi-memory* records durable findings (artstyle rules, exporter gotchas,
   Bevy version notes) and recalls them semantically in future sessions.

---

## 5. Setup (concrete steps)

```bash
cd ~/motion-mesh

# 1. Vendor the three pre-made extensions, pinned to commits
mkdir -p vendor
git submodule add https://github.com/tmonk/pi-goal-x       vendor/pi-goal-x
git submodule add https://github.com/nicobailon/pi-subagents vendor/pi-subagents
git submodule add https://github.com/jayzeng/pi-memory     vendor/pi-memory
git submodule update --init --recursive
for d in vendor/*/; do (cd "$d" && npm install); done   # local pkgs: our responsibility

# 2. Register them as project-local packages (writes .pi/settings.json)
pi install ./vendor/pi-goal-x --local
pi install ./vendor/pi-subagents --local
pi install ./vendor/pi-memory --local

# 3. Trust the project when pi prompts (loads .pi/* resources)

# 4. Add our own agent + subagent definitions and skills
#    .pi/agents/*.md, .pi/prompts/*.md, extensions/{extensions,skills,prompts}/

# 5. Smoke test
pi   # → /goal "import a test cube with 2 bones and one animation into bevy"
```

---

## 6. Milestones

1. **M1 — Harness online:** vendored packages load (`pi list`), goal/subagent
   smoke test on a throwaway cube asset.
2. **M2 — Pipeline tools:** `validate_rig`, `export_gltf`,
   `check_bevy_import` extensions working against the Bevy game repo.
   ✅ **Done (2026-11-30):** implemented in `.pi/extensions/pipeline.ts` +
   `pipeline/` (Blender script + bevy-check crate, Bevy 0.20). validate_rig
   and check_bevy_import verified against test assets; export_gltf awaits a
   Blender binary on this machine.
3. **M3 — Artstyle skills:** WoW-style guide + rigging conventions encoded as
   skills and memories; first real character end-to-end.
4. **M4 — Full loop:** `/goal`-driven character production with subagent
   delegation and auditor sign-off, zero manual pipeline steps.

## 7. Risks / notes

- **Goal-extension conflicts:** install exactly one goal package.
- **pi-memory needs the `qmd` binary** for semantic search — ✅ installed
  (`~/.local/bin/qmd`, v2.9.0). Embedding model upgraded from the default
  `embeddinggemma-300M` to **Qwen3-Embedding-0.6B** via `QMD_EMBED_MODEL`
  (exported in `~/.bashrc`/`~/.profile`). If the model is changed again,
  re-index with `qmd embed -f`. The `pi-memory` collection lives in
  `~/.pi/agent/memory` (global, not per-project).
- **Version pinning:** submodules pin commits; bump deliberately and re-run
  `npm install` inside the vendor dir.
- **Project trust:** `.pi/settings.json` declarations and `.pi/extensions`
  only load after trust is granted — expected on first launch.
- Blender/`blender --background` must be on PATH for export/validation tools.
