Plugins
Extend Motion SDK with opt-in packages that add agent skills, typed scene helpers, CLI commands and verify checks, starting with img2scene, which rebuilds a prop from a photo.
A plugin is a separate package you install when you need it. It can add four things:
- Skills.
SKILL.mdfiles that teach an agent a workflow. - Helpers. Typed functions that build
@motion-sdk/sceneobjects. - CLI commands.
motion-sdk <plugin> ...runs a nativemotion-sdk-<plugin>binary. - Checks. Custom checks for
motion-sdk verify.
The engine doesn't change. Plugins add no new primitives, and the player, authoring and WebGL2 bundles stay the same size whether you use plugins or not.
The Contract
import { definePlugin } from "@motion-sdk/scene/plugin";
import { expect } from "@motion-sdk/scene";
export default definePlugin({
name: "spin", // lowercase, digits, dashes
version: "0.1.0",
description: "Spin props on a turntable.",
package: "@acme/motion-plugin-spin",
skills: [{ name: "motion-sdk-spin", path: "skills/motion-sdk-spin/SKILL.md", description: "Load to show a prop off." }],
helpers: { turns: (n: number) => n * 360 },
cli: {
bin: "motion-sdk-spin",
commands: [{ name: "go", usage: "motion-sdk spin go scene.json", description: "Add a turntable track." }],
},
checks: { inFrame: (node: string) => expect(node).staysInFrame() },
});definePlugin checks the manifest when the plugin loads and throws a PluginError with a fix. These are the rules:
- The
namemust be lowercase letters, digits and dashes, andversionmust be semver. - Skills are named
motion-sdk-*, and their paths are relative. cli.binmust bemotion-sdk-<name>, and every command's usage must start withmotion-sdk <name>.- Helpers and checks must be functions.
The literal types survive, so plugin.helpers.turns is typed.
Your app registers the plugins it uses:
import { registerPlugins } from "@motion-sdk/scene/plugin";
import img2scene from "@motion-sdk/plugin-img2scene";
export const motion = registerPlugins(img2scene);
motion.helpers.img2scene.referenceCamera({ distance: 9, elevation: 10 });
motion.checks.img2scene.propInFrame("mug");
motion.skills(); // every skill with its plugin and package
motion.commands(); // every CLI command
motion.agentsNote(); // a Markdown block for AGENTS.mdHelpers and checks are namespaced by plugin. registerPlugins refuses two plugins with the same name or the same skill name.
Commands
The CLI finds plugins the way cargo and git find subcommands. An executable named motion-sdk-<name>, either next to motion-sdk or on PATH, runs as motion-sdk <name> .... It gets the same arguments, stdio and exit code, and MOTION_SDK_BIN is set so it can call back into motion-sdk.
motion-sdk plugins # name and path of each one
motion-sdk plugins --json
motion-sdk img2scene info # runs motion-sdk-img2scene infoA plugin binary can be written in any language. A Rust one can link the engine crates, the way motion-sdk-img2scene links the render and export crates to render stills.
Skills for Agents
Ship skills in the package under skills/<name>/SKILL.md, in the same format as the core skills. Paste motion.agentsNote() into your project's AGENTS.md. It lists each skill's path under node_modules and each command, so an agent knows they exist. In this repo, skills.sh.json also lists the plugin skill folders, so npx skills add installs them.
img2scene
@motion-sdk/plugin-img2scene is the first plugin. It takes one photo of a hard-surface prop and turns it into a typed scene file.
The skill walks the agent through three passes: a grey-clay blockout, then form, then materials. Each pass is validated, rendered and compared with the photo, then patched.
cargo build --release -p motion-sdk-cli -p motion-sdk-img2scene
motion-sdk img2scene compare scene.json reference.png --sheet pass-1.pngcompare renders a still at the photo's size through the normal headless render path, with no browser. It prints a JSON report:
silhouette.iouas framed.iou_alignedwith both subjects centred and scaled the same, which measures shape alone.missingandextrashares, the offset and the scale.palette. Weighted CIEDE2000 between the two k-means palettes, with each colour pair.phash. A 63-bit DCT perceptual hash and its similarity.scoreandhints. A rough 0 to 1 score, and the biggest differences written as edits, such as "subject is 19% too small: move the camera closer".
It also writes a sheet showing the photo, the render and an overlay. In the overlay, green is both, red is missing and blue is extra. Palette strips sit underneath. The agent reads the hints, looks at the sheet, and decides what to fix.
From TypeScript, compare(scene, "reference.png") in @motion-sdk/plugin-img2scene/node returns the typed report. The helpers are:
propSceneframes a scene like its photo: the photo's canvas size, a flat backdrop, no vignette or bloom, and a studio light rig.referenceCameraplaces the camera by distance, elevation and azimuth.frameHeightturns photo fractions into world units.turntableadds a turntable track.- The checks
propInFrameandmatchesFramingneed no GPU.
Demos
Two original objects, each rebuilt in three passes. The photo, every pass's TS and JSON, the sheets and metrics.json are in packages/plugin-img2scene/demos.
| Demo | Pass | Score | IoU | Palette ΔE |
|---|---|---|---|---|
| Ceramic mug | 1 blockout | 0.653 | 0.596 | 26.6 |
| 2 form | 0.766 | 0.848 | 26.4 | |
| 3 materials | 0.89 | 0.895 | 3.5 | |
| Desk lamp | 1 blockout | 0.431 | 0.291 | 8.9 |
| 2 form | 0.658 | 0.631 | 7.5 | |
| 3 materials | 0.687 | 0.721 | 6.4 |


Comparing a silhouette, a palette and a perceptual hash between a photo and a render follows ideas from the img2threejs project (Apache 2.0). img2scene is a separate implementation for Motion SDK's renderer.
Publishing a plugin
Plugin packages live under packages/plugin-* and publish as @motion-sdk/<dir>. The first one is @motion-sdk/plugin-img2scene. They are public, and a publish from GitHub Actions includes npm provenance.
The publish plugin workflow packs every plugin on a PR that touches one. The same pack step also runs in the ts sdk CI job. Neither job publishes. A real publish happens only from a version tag, or from a manual run of the workflow with dry_run left unchecked.
The native CLI (motion-sdk-<name>) is a Rust crate, not part of the npm tarball. Install it from the repo (cargo build --release -p motion-sdk-img2scene) and leave it next to motion-sdk or on PATH. The tarball carries the TypeScript helpers, the checks and the skills/*/SKILL.md files. Demos and tests stay in the repo.
Package manifest
Each plugin's package.json must be public and provenance-ready:
- no
"private": true "license","files": ["src", "skills", ...]"repository.url"set tohttps://github.com/brainfish-ai/motion.git(npm provenance checks this)"publishConfig": { "access": "public", "provenance": true }
scripts/pack-plugin.mjs checks all of that, plus the tarball contents. Run it locally with node scripts/pack-plugin.mjs or node scripts/pack-plugin.mjs plugin-img2scene.
First-time npm setup
The repo has no NPM_TOKEN secret and the workflow does not use one. Later publishes use npm trusted publishing over OIDC. A trusted publisher can only be added on a package that already exists, so the very first version of a new name is a one-time bootstrap.
-
Create the
@motion-sdkorganization on npmjs.com if it is not there yet, with 2FA on the owner account, and make sure you can publish under that scope. -
@motion-sdk/sceneis a peer of every plugin and is not on npm yet. Publishing a plugin first is fine, but people who install it from npm will need@motion-sdk/scenefrom this repo until that package is published too. -
From a clean checkout of the commit you want to release (do this on a machine where you are logged in, not from this workflow):
npm login cd packages/plugin-img2scene npm publish --access public --provenanceOr stage it, then approve, which also creates the package:
npm stage publishandnpm stage approve. -
On the package's settings → Trusted Publisher → GitHub Actions, add:
Field Value Organization or user brainfish-aiRepository motionWorkflow filename publish-plugin.ymlLeave the environment name blank (the workflow does not use a GitHub Environment). Allow
npm publish. The first successful publish through this connection must happen within 2 days, or the configuration expires and you will need to add it again. -
You do not need an
NPM_TOKENrepository secret. After trusted publishing works, you can turn on "Require two-factor authentication and disallow tokens" on the package.
Later releases
Bump the version in that plugin's package.json (and in any tag you cut) and merge to main. Then, on the release commit:
git tag plugin-img2scene-v0.1.1
git push origin plugin-img2scene-v0.1.1The tag must be plugin-<name>-v<semver> and the version must match package.json. The workflow typechecks, tests, packs, refuses to overwrite a version that is already on npm, and runs npm publish --access public --provenance.
To pack without publishing, open Actions → publish plugin → Run workflow, set the package to plugin-img2scene, and leave dry_run checked. Uncheck it only when you mean to publish, and only after the trusted publisher is in place.