uxspec
Installation
SKILL.md
UXSpec Builder
Interactive workflow for creating UXSpec files — the JSON format that unifies state machines and visual specifications for AI agents.
Trigger
Use when the user wants to create, build, or scaffold a .uxspec.json file, or asks "help me write a uxspec".
Workflow
Follow these phases in order. Each phase produces a concrete artifact before moving on.
Phase 1 — Gather Requirements
Ask the user:
- What is this component/page? (e.g., "login form", "toast notifications", "media player")
- What are the key states? (e.g., "idle, loading, error, success")
- What events drive transitions? (e.g., "SUBMIT, INPUT_CHANGED, HTTP_OK, HTTP_ERROR")
- What context data is needed? (e.g., "email: string, password: string, error: string | null")
- Any reusable elements? (e.g., "input field with label, action button")
Summarize back to the user as a bullet list before proceeding.
Phase 2 — Design the State Machine
Build the $machine section:
- Define compound states (parents) and leaf states (children)
- Every compound state needs an
initialchild - Map events to transitions with optional guards and actions
- Add
entry/exitactions where needed (e.g., set loading flag, clear errors) - Add
invokefor long-running effects (HTTP calls, timers)
Present the state graph as a text diagram:
idle --SUBMIT--> loading
loading --HTTP_OK--> success
loading --HTTP_ERROR--> error
error --RETRY--> loading
Phase 3 — Define Tokens and Visuals
- Define
$tokens— colors, spacing, radius, font, timing (follow W3C Design Tokens format) - Define
$elements— reusable element templates withparams - Add
$visualto each leaf state — container layout, slots with elements - Add
testIdto interactive elements for assertions - Add
arialabels for accessibility
Read references/format-reference.md for token syntax, element types, and visual structure.
Phase 4 — Add Runtime Semantics
- Define
$context— typed fields with defaults - Define
$events— with source and payload types - Define
$actions— assign, emit, log - Define
$effects— http, timer, navigate, focus - Wire
binding,visibleWhen,enabledWhen,onPress,onChangeon elements
Read references/runtime-semantics.md for expression syntax and action/effect kinds.
Phase 5 — Generate and Verify
- Write the spec to
examples/<name>.uxspec.json - Validate:
bun run src/compiler/cli.ts validate examples/<name>.uxspec.json - If validation fails, fix reported issues (the compiler returns structured issue codes)
- Compile:
bun run src/compiler/cli.ts compile examples/<name>.uxspec.json - Inspect:
bun run src/compiler/cli.ts inspect examples/<name>.uxspec.json - Report to the user:
- Number of states and assertions
- Whether initial resolves to a leaf state
- Any unresolved refs or token aliases
- The compiled output path
Issue Resolution
If the compiler reports issues, map codes to fixes:
| Code | Fix |
|---|---|
UNDECLARED_CONTEXT_VAR |
Add missing field to $context |
UNDECLARED_EVENT |
Add missing event to $events |
UNDECLARED_TARGET |
Fix transition target to match a valid state path |
UNSUPPORTED_EXPR_OP |
Replace with a supported operator (see spec) |
INVALID_ASSIGN_PATH |
Ensure path starts with context. |
UNKNOWN_TOKEN_REFERENCE |
Add missing token to $tokens or fix the path |
UNKNOWN_ELEMENT_REFERENCE |
Add missing element to $elements or fix the name |
INVALID_MACHINE_INITIAL |
Set $machine.initial to a valid top-level state |
INVALID_COMPOUND_INITIAL |
Set compound state initial to a valid child name |
Key Rules
- File extension:
.uxspec.json - Schema:
https://uxspec.dev/0.2/schema.json - Required top-level:
$schema,$description,$machine $machinerequires:id,initial,states- Leaf elements (
text,button,input,icon,shape,badge,bar) MUST NOT havechildren - Container elements (
group,layer,grid,stack-h,stack-v) MAY havechildren - Token references:
"{path.to.token}"— curly braces inside a string - Element references:
{ "$ref": "name", ...params } - Expressions: S-expression arrays like
["==", ["var", "context.x"], true] - All
$-prefixed properties are reserved
Reference Files
references/format-reference.md— Token syntax, element types, visual structure, layout primitivesreferences/runtime-semantics.md— Context, events, actions, effects, expressions, transitionsreferences/minimal-example.md— Complete minimal spec you can use as a starting template
Weekly Installs
2
Repository
johnlindquist/uxspecGitHub Stars
2
First Seen
Mar 19, 2026
Security Audits
Installed on
amp2
cline2
pi2
opencode2
cursor2
kimi-cli2