Skip to content
Back to search

state-machine

Model UI component behavior as FSMs before writing code. Verbs: `model` (FSM from description → auto-prompt for code generation), `audit` (detect impossible states in existing code). Framework-agnostic, XState v5 compatible. Eliminates impossible states at design time.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/pauloriveross--state-machine-skill/badge.svg)](/listings/pauloriveross--state-machine-skill)

HTML

<a href="/listings/pauloriveross--state-machine-skill"><img src="/api/listings/pauloriveross--state-machine-skill/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

| Agent | Command | |-------|---------| | **Any agent** | `npx skills add pauloriveross/state-machine-skill` | | **Claude Code** | `npx skills add pauloriveross/state-machine-skill` | | **Cursor** | Copy `SKILL.md` → `.cursor/rules/state-machine.mdc`, `references/` → `.cursor/rules/state-machine/` | | **Windsurf** | `cp SKILL.md .windsurf/rules/state-machine.md` + `cp -r references/ .windsurf/rules/state-machine-references/` | | **OpenCode** | `cp -r * .agent/skills/state-machine/` (or just open the repo — auto-detected) | | **Manual** | Copy `SKILL.md` + `references/` into your agent's skill directory |

---

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 106 lines
  1. ---
  2. name: state-machine
  3. description: >
  4. Model UI component behavior as FSMs before writing code. Verbs:
  5. `model` (FSM from description → auto-prompt for code generation),
  6. `audit` (detect impossible states in existing code). Framework-agnostic,
  7. XState v5 compatible. Eliminates impossible states at design time.
  8. version: 1.3.0
  9. ---
  10. # state-machine Skill
  11. Model before you build. Every UI bug is a state you never modeled.
  12. ## Verbs
  13. | Verb | Input → Output | When |
  14. |------|---------------|------|
  15. | `model` | NL description → 3-section FSM blueprint, then auto-prompt: ask user if they want to implement, discover project folders, generate code + tests | Before writing any code |
  16. | `audit` | File path → reconstructed model + impossible state analysis + punch list | Debugging or inheriting existing code |
  17. ## Mandatory Execution Protocol for the Agent (AI)
  18. You MUST strictly follow this algorithmic workflow for any user command:
  19. ### `model` Verb Execution
  20. 1. **Generate Structure**: Translate the user's description into a structured JSON that strictly conforms to `schemas/fsm.schema.json`. Save temporarily to `.state-machine/temp-model.json`.
  21. 2. **Self-Validation**: Immediately run `node scripts/validate-model.js .state-machine/temp-model.json`.
  22. 3. **Error Handling**:
  23. - If the command fails (Exit code 1), read the script output, re-model the JSON fixing the broken gate, and repeat step 2.
  24. - Do NOT ask the user for help or show intermediate code until the script returns Exit code 0.
  25. 4. **Final Output**: Return a markdown block with exactly **3 sections** in order:
  26. **Section 1 — Behavior Specification**: Rephrase the user's description as a concise specification in English.
  27. **Section 2 — Structural Contract**: Present the validated JSON inside a `json` code block. This is the exact JSON that passed validation.
  28. **Section 3 — Transition Diagram**: Run `node scripts/ascii-viz.js .state-machine/temp-model.json` and include its output inside a code block.
  29. Format:
  30. ````
  31. ## 1. Behavior Specification
  32. ...
  33. ## 2. Structural Contract (`model.json`)
  34. ```json
  35. { ... }
  36. ```
  37. ## 3. Transition Diagram (ASCII)
  38. ```
  39. ...
  40. ```
  41. ````
  42. Do NOT include any text before or after these 3 sections.
  43. 5. **Post-model prompt**: After outputting the 3 sections, ask the user:
  44. - "Do you want me to generate the component code from this model?"
  45. - If yes, scan the workspace for existing project directories (look for `package.json`, `src/`, `components/`, etc.) and present the viable folders to the user.
  46. - Ask which folder the component should be placed in.
  47. - Execute the **Implementation sub-flow** (see below).
  48. ### Implementation sub-flow (agent-initiated, not a user verb)
  49. 1. **Read Contract**: Take the JSON validated in the prior step.
  50. 2. **Inject Runtime**: Copy the base code from `src/core/fsm.ts` into the user's chosen directory as `fsm.ts` if it does not exist.
  51. 3. **Generate Component**: Generate the UI component coupling state exclusively through the `createLightMachine` hook/function.
  52. 4. **Compile Tests**: Write a unit test file (`.test.ts` / `.test.js`) that sequentially simulates 100% of the JSON transitions and verifies the resulting state.
  53. ### `audit` Verb Execution
  54. 1. **Scan Code**: Search the user's file for reactive variables (`useState`, `ref`, boolean fields).
  55. 2. **Generate Matrix**: Run an internal bit-combinatorics simulation ($2^n$) over those booleans.
  56. 3. **Write Punch List**: Identify which combinations have no visual representation or coherent logic.
  57. ## Reference Library
  58. | File | Contents |
  59. |------|----------|
  60. | `references/verb-dispatch.md` | Exact output format for each verb |
  61. | `references/component-patterns.md` | 12 reusable patterns (modal, form, toggle, auth, etc.) |
  62. | `references/impossible-states.md` | 35 anti-patterns with elimination strategies |
  63. | `references/slop-gates.md` | 38 validation gates (model 1–13, code 14–23, audit 24–38) |
  64. | `references/framework-adapters.md` | useMachine(config, implementations) for React/Vue/Svelte/Vanilla |
  65. | `references/xstate-compat.md` | XState v5 mapping |
  66. | `schemas/fsm.schema.json` | Canonical JSON Schema for FSM models (hierarchical format) |
  67. | `references/state-theory.md` | FSM/HFSM theory applied to UI |
  68. | `examples/` | modal.md, toggle-async.md, multistep-form.md, auth-flow.md |
  69. ## Validation
  70. ```bash
  71. node scripts/validate-model.js path/to/model.json # full check + ASCII diagram
  72. node scripts/validate-model.js path/to/model.json --light # fast-track (compact)
  73. node scripts/ascii-viz.js path/to/model.json # diagram only
  74. ```
  75. ## Output Formats (see `references/verb-dispatch.md`)
  76. - **model**: Behavior Specification, Structural Contract (JSON), ASCII Diagram, ✅ Gates 1–13; then auto-prompt → component code + tests, ✅ Gates 1–23
  77. - **audit**: Reconstructed model, impossible states, unhandled transitions, severity punch list, ✅ Gates 24–38
  78. ---
  79. *state-machine — model before you build.*
README.md · README · 488 lines
  1. <div align="center">
  2. # 🔄 state-machine
  3. **Model UI behavior before you code it. Eliminate impossible states before they exist.**
  4. [![npm version](https://img.shields.io/npm/v/state-machine-skill?label=1.3.0)](https://www.npmjs.com/package/state-machine-skill)
  5. [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
  6. [![Works with Claude Code](https://img.shields.io/badge/Claude%20Code-ready-7C3AED)](https://claude.ai)
  7. [![Works with Cursor](https://img.shields.io/badge/Cursor-ready-000000)](https://cursor.com)
  8. [![Works with Windsurf](https://img.shields.io/badge/Windsurf-ready-2563EB)](https://codeium.com/windsurf)
  9. [![Works with OpenCode](https://img.shields.io/badge/OpenCode-ready-22C55E)](https://opencode.ai)
  10. Compatible with **Claude Code** · **Cursor** · **Windsurf** · **OpenCode** · Any AI coding agent
  11. </div>
  12. ---
  13. ## Why state machines for UI?
  14. Three booleans. Eight possible states. Five of them impossible.
  15. ```tsx
  16. const [isLoading, setIsLoading] = useState(false);
  17. const [isError, setIsError] = useState(false);
  18. const [isSuccess, setIsSuccess] = useState(false);
  19. ```
  20. | isLoading | isError | isSuccess | Result |
  21. |-----------|---------|-----------|--------|
  22. | ❌ | ❌ | ❌ | `Idle` — valid |
  23. | ✅ | ❌ | ❌ | `Loading` — valid |
  24. | ❌ | ✅ | ❌ | `Error` — valid |
  25. | ❌ | ❌ | ✅ | `Success` — valid |
  26. | ✅ | ✅ | ❌ | **IMPOSSIBLE** — loading and erroring at once |
  27. | ✅ | ❌ | ✅ | **IMPOSSIBLE** — loading and succeeded at once |
  28. | ❌ | ✅ | ✅ | **IMPOSSIBLE** — error and success at once |
  29. | ✅ | ✅ | ✅ | **IMPOSSIBLE** — all three at once |
  30. Every impossible state is a bug waiting to happen. A race condition, a missed reset, a late network response — and your UI shows a spinner over content, or an error over a success view.
  31. **A state machine replaces N booleans with one state variable.** Instead of 2^N combinations (most invalid), you get exactly N states — all valid. If a state isn't in the alphabet, the component cannot enter it.
  32. ---
  33. ## How it works: single-command workflow
  34. ```
  35. ┌──────────┐ ┌──────────────┐ ┌──────────────────┐ ┌──────────┐
  36. │ Describe │────>│ model verb │────>│ Agent asks: │────>│ Ready │
  37. │ behavior │ │ (blueprint) │ │ "Implement now?" │ │ component│
  38. │ in NL │ │ 3 sections │ │ → picks folder │ │ shipped │
  39. └──────────┘ └──────────────┘ │ → generates │ └──────────┘
  40. │ code + tests │
  41. └──────────────────┘
  42. ```
  43. **`model` command**: You describe the component behavior in natural language. The agent produces 3 sections: Behavior Specification, validated JSON contract, and ASCII diagram. Then it asks if you want to generate the component code now.
  44. **Implementation**: If you accept, the agent scans your project directories, confirms the target folder with you, injects the micro-runtime (`createLightMachine`), generates the component code wired to the state machine, and writes unit tests covering every transition.
  45. ---
  46. ## Install
  47. | Agent | Command |
  48. |-------|---------|
  49. | **Any agent** | `npx skills add pauloriveross/state-machine-skill` |
  50. | **Claude Code** | `npx skills add pauloriveross/state-machine-skill` |
  51. | **Cursor** | Copy `SKILL.md` → `.cursor/rules/state-machine.mdc`, `references/` → `.cursor/rules/state-machine/` |
  52. | **Windsurf** | `cp SKILL.md .windsurf/rules/state-machine.md` + `cp -r references/ .windsurf/rules/state-machine-references/` |
  53. | **OpenCode** | `cp -r * .agent/skills/state-machine/` (or just open the repo — auto-detected) |
  54. | **Manual** | Copy `SKILL.md` + `references/` into your agent's skill directory |
  55. ---
  56. ## Two verbs. One guarantee.
  57. ### `model` — From natural language to validated blueprint (with optional implementation)
  58. **Input:** A natural language description of component behavior.
  59. **Output:** 3 sections (Behavior Specification, validated JSON contract, ASCII diagram), then an auto-prompt to implement.
  60. **How the agent executes it:**
  61. 1. Translates your description into a hierarchical JSON conforming to `schemas/fsm.schema.json`
  62. 2. Saves to `.state-machine/temp-model.json`
  63. 3. Runs `node scripts/validate-model.js .state-machine/temp-model.json`
  64. 4. If validation fails, fixes the JSON and re-runs — **no intermediate output, no asking for help**
  65. 5. On success, outputs the 3-section markdown block
  66. 6. Asks: "Do you want me to generate the component code from this model?"
  67. 7. If yes, scans your project directories, asks which folder, generates code + tests
  68. **Example:**
  69. ```
  70. > state-machine model a toggle that switches on and off
  71. ```
  72. The agent returns:
  73. `````markdown
  74. ## 1. Behavior Specification
  75. A simple toggle switch with two states — On and Off. Clicking the toggle flips between the two states.
  76. ## 2. Structural Contract (`model.json`)
  77. ```json
  78. {
  79. "id": "toggle",
  80. "initial": "Off",
  81. "states": {
  82. "Off": { "type": "atomic", "on": { "TOGGLE": { "target": "On" } } },
  83. "On": { "type": "atomic", "on": { "TOGGLE": { "target": "Off" } } }
  84. }
  85. }
  86. ```
  87. ## 3. Transition Diagram (ASCII)
  88. ```
  89. ┌────────┐ TOGGLE ┌────────┐
  90. │ Off │─────────>│ On │
  91. └────────┘<─────────└────────┘
  92. TOGGLE
  93. ```
  94. ✅ All 13 gates passed.
  95. `````
  96. Then the agent asks: *"Do you want me to generate the component code from this model? I can place it in your project."*
  97. If you accept, it scans for project folders, confirms the target directory, and generates the implementation.
  98. ---
  99. ### Implementation (auto-prompted after `model`)
  100. When you accept the post-model prompt, the agent:
  101. 1. Scans your project for `package.json`, `src/`, `components/`, `app/` directories
  102. 2. Asks you to confirm the target folder
  103. 3. Copies `src/core/fsm.ts` into that folder as `fsm.ts` (if not already present)
  104. 4. Generates the UI component wired to `createLightMachine`
  105. 5. Writes unit tests that simulate 100% of transitions
  106. **Every component carries a guarantee:**
  107. ```tsx
  108. /* state-machine: Closed|Loading|Success|Error : TRIGGER|FETCH_SUCCESS|FETCH_ERROR|CLOSE|RETRY */
  109. ```
  110. This component **cannot** enter a state that was not explicitly modeled.
  111. ---
  112. ### `audit` — Detect impossible states in legacy code
  113. **Input:** A file path to an existing component using boolean flags (`useState`, `ref`, boolean fields).
  114. **Output:** A structured JSON report with detected flags, combinatorial complexity, and impossible state analysis.
  115. **How the agent executes it:**
  116. 1. Scans the file for reactive boolean variables (`const [isXxx, ...]`, `const [hasXxx, ...]`)
  117. 2. Runs `node scripts/audit-processor.js file.tsx`
  118. 3. Computes the 2^n combinatorial matrix
  119. 4. Identifies which combinations have no visual representation or coherent logic
  120. 5. Outputs a ranked punch list
  121. **Example:**
  122. ```
  123. > state-machine audit components/ui/OldModal.tsx
  124. ```
  125. Output:
  126. ```json
  127. {
  128. "detectedFlags": ["isLoading", "isError", "isSuccess"],
  129. "complexity": "3 flags = 8 combinaciones posibles",
  130. "impossibleStatesDetected": [
  131. {
  132. "combination": { "isLoading": true, "isError": true },
  133. "severity": "CRITICAL",
  134. "description": "Loading spinner and error message simultaneously"
  135. }
  136. ]
  137. }
  138. ```
  139. ---
  140. ## Model format: two ways to write your JSON
  141. The linter auto-detects which format you're using.
  142. ### Flat format (simple)
  143. ```json
  144. {
  145. "states": ["Closed*", "Loading", "Success", "Error"],
  146. "transitions": [
  147. { "From": "Closed", "Event": "TRIGGER", "To": "Loading" },
  148. { "From": "Loading", "Event": "FETCH_SUCCESS", "To": "Success" },
  149. { "From": "Loading", "Event": "FETCH_ERROR", "To": "Error" }
  150. ]
  151. }
  152. ```
  153. ### Hierarchical format (schema — per `schemas/fsm.schema.json`)
  154. Supports compound states, guards, actions, lifecycle hooks, and cross-hierarchy targets.
  155. ```json
  156. {
  157. "id": "async-modal",
  158. "initial": "Closed",
  159. "states": {
  160. "Closed": {
  161. "type": "atomic",
  162. "on": {
  163. "TRIGGER": { "target": "Loading" }
  164. }
  165. },
  166. "Loading": {
  167. "type": "atomic",
  168. "onEnter": ["fetchData"],
  169. "on": {
  170. "FETCH_SUCCESS": { "target": "Success", "actions": ["storeData"] },
  171. "FETCH_ERROR": { "target": "Error", "actions": ["logError"] }
  172. }
  173. },
  174. "Success": {
  175. "type": "atomic",
  176. "on": {
  177. "CLOSE": { "target": "Closed", "actions": ["clearData"] }
  178. }
  179. },
  180. "Error": {
  181. "type": "atomic",
  182. "on": {
  183. "RETRY": { "target": "Loading" },
  184. "CLOSE": { "target": "Closed" }
  185. }
  186. }
  187. }
  188. }
  189. ```
  190. For compound (nested) states with cross-hierarchy targets:
  191. ```json
  192. {
  193. "id": "auth-flow",
  194. "initial": "Unauthenticated",
  195. "states": {
  196. "Unauthenticated": {
  197. "type": "compound",
  198. "initial": "Idle",
  199. "states": {
  200. "Idle": { "type": "atomic", "on": { "LOGIN": { "target": "Authenticating" } } },
  201. "Authenticating": { "type": "atomic" },
  202. "MfaRequired": { "type": "atomic" }
  203. }
  204. },
  205. "Authenticated": {
  206. "type": "compound",
  207. "initial": "Active",
  208. "states": {
  209. "Active": {
  210. "type": "atomic",
  211. "on": {
  212. "LOGOUT": { "target": "#auth-flow.Unauthenticated.Idle", "actions": ["clearSession"] }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. }
  219. ```
  220. ---
  221. ## 4 worked examples
  222. Each example demonstrates the model output in the unified 3-section format: behavior specification → structural JSON contract → ASCII diagram.
  223. <details>
  224. <summary><b>📋 Modal with async loading</b> — 4 states, 5 events, 7 transitions</summary>
  225. ```
  226. ┌────────┐ TRIGGER ┌─────────┐ FETCH_SUCCESS ┌─────────┐
  227. │ Closed │─────────>│ Loading │──────────────>│ Success │
  228. └────────┘ └────┬────┘ └────┬────┘
  229. │ │ CLOSE
  230. CLOSE │ v
  231. │ ┌─────────┐
  232. └───────────────────>│ Closed │
  233. └─────────┘
  234. ```
  235. File: [`examples/modal.md`](examples/modal.md)
  236. </details>
  237. <details>
  238. <summary><b>📋 Multi-step registration form</b> — 7 states, 8 events, 11 transitions</summary>
  239. ```
  240. ┌────────┐ NEXT ┌────────┐ NEXT ┌────────┐ SUBMIT
  241. │ Step1 │────────>│ Step2 │────────>│ Step3 │────────────┐
  242. └───┬────┘ └───┬────┘ └────────┘ │
  243. │ PREV │ PREV │
  244. └───────────────────┘ │
  245. ┌────────────┐ │
  246. │ Submitting │◄────────────────┘
  247. └──────┬─────┘
  248. ┌───────────┼──────────┐
  249. v v │
  250. ┌─────────┐ ┌─────────┐ │
  251. │ Success │ │ Error │─────┘
  252. └─────────┘ └────┬────┘
  253. │ RETRY
  254. v
  255. ┌────────────┐
  256. │ Submitting │
  257. └────────────┘
  258. ```
  259. File: [`examples/multistep-form.md`](examples/multistep-form.md)
  260. </details>
  261. <details>
  262. <summary><b>📋 Async toggle with optimistic update</b> — 5 states, 5 events, 8 transitions</summary>
  263. ```
  264. ┌────────┐ ┌────────────┐ CONFIRM ┌────────┐
  265. │ Off │─────>│ PendingOn │───────>│ On │
  266. └───┬────┘ └──────┬─────┘ └───┬────┘
  267. │ │ REJECT │
  268. │ v │
  269. │ ┌───────┐ │
  270. └─────────────>│ Error │<──────────────┘
  271. └───┬───┘
  272. RETRY │ DISMISS
  273. v
  274. ┌────────┐
  275. │Pending │
  276. └────────┘
  277. ```
  278. File: [`examples/toggle-async.md`](examples/toggle-async.md)
  279. </details>
  280. <details>
  281. <summary><b>📋 Auth flow with MFA</b> — HFSM, compound states, 13 events, 16 transitions</summary>
  282. ```
  283. ┌──────────────────────────────────────────┐
  284. │ Unauthenticated │
  285. │ ┌────────┐ LOGIN ┌──────────────┐ │
  286. │ │ Idle │───────────>│ Authenticating│ │
  287. │ └────────┘<────────────│ │ │
  288. │ ^ LOGIN_ERR └──────┬───────┘ │
  289. │ │ MFA_CANCEL LOGIN_MFA│ │
  290. │ │ ┌──────v───────┐ │
  291. │ └─────────────────│ MfaRequired │ │
  292. │ MFA_SUBMIT(hasMfaCode) │ │
  293. └──────────────────────────────────────────┘
  294. │ LOGIN_SUCCESS
  295. v
  296. ┌──────────────────────────────────────────┐
  297. │ Authenticated │
  298. │ ┌────────┐ REFRESH_TOKEN ┌────────────┐│
  299. │ │ Active │───────────────>│ Refreshing ││
  300. │ └───┬────┘<───────────────│ ││
  301. │ │ REFRESH_SUCCESS └──────┬─────┘│
  302. │ │ REFRESH_FAIL │
  303. │ └──────────────────────────────┘ │
  304. │ LOGOUT → Unauthenticated.Idle │
  305. │ SESSION_EXPIRED → Unauthenticated.Idle │
  306. └──────────────────────────────────────────┘
  307. ```
  308. File: [`examples/auth-flow.md`](examples/auth-flow.md)
  309. </details>
  310. ---
  311. ## Scripts
  312. | Script | Purpose |
  313. |--------|---------|
  314. | `node scripts/validate-model.js model.json` | Validate model against gates 01–13 + structural pre-check |
  315. | `node scripts/validate-model.js model.json --light` | Fast-track: skip warnings, compact diagram |
  316. | `node scripts/ascii-viz.js model.json` | Render ASCII transition diagram only |
  317. | `node scripts/audit-processor.js file.tsx` | Analyze boolean flags in legacy code |
  318. All scripts are zero-dependency. Exit code 0 = valid, 1 = invalid with gate report.
  319. ---
  320. ## Project structure
  321. | File | Purpose |
  322. |------|---------|
  323. | [`SKILL.md`](SKILL.md) | Mandatory execution protocol — tells the AI agent exactly how to handle each verb |
  324. | [`src/core/fsm.ts`](src/core/fsm.ts) | Injectable micro-runtime (`createLightMachine`) — copied into your project during implementation |
  325. | [`schemas/fsm.schema.json`](schemas/fsm.schema.json) | Canonical JSON Schema for hierarchical FSM models |
  326. | [`scripts/validate-model.js`](scripts/validate-model.js) | Model validator — 13 gates + graph structural check, auto-detects flat/hierarchical format |
  327. | [`scripts/ascii-viz.js`](scripts/ascii-viz.js) | Terminal ASCII transition diagram renderer |
  328. | [`scripts/audit-processor.js`](scripts/audit-processor.js) | Boolean flag analyzer — detects impossible state combinations in legacy code |
  329. | [`references/verb-dispatch.md`](references/verb-dispatch.md) | Exact output format specification for `model` and `audit` verbs |
  330. | [`references/slop-gates.md`](references/slop-gates.md) | 38 validation gates (model 1–13, code 14–23, audit 24–38) |
  331. | [`references/state-theory.md`](references/state-theory.md) | FSM/HFSM fundamentals applied to UI components |
  332. | [`references/component-patterns.md`](references/component-patterns.md) | 12 canonical UI patterns with pre-built models and invariants |
  333. | [`references/impossible-states.md`](references/impossible-states.md) | 35 anti-patterns with elimination strategies |
  334. | [`references/xstate-compat.md`](references/xstate-compat.md) | Full mapping to XState v5 for every pattern |
  335. | [`references/framework-adapters.md`](references/framework-adapters.md) | `useMachine` adapter for React, Vue, Svelte, Vanilla JS |
  336. | [`examples/`](examples/) | 4 worked examples in unified format (modal, toggle, form, auth) |
  337. ---
  338. ## XState v5 compatible
  339. Every generated model maps directly to XState v5. Use the machine in any framework via `@xstate/react`, `@xstate/vue`, or `@xstate/svelte`.
  340. ```ts
  341. import { setup } from 'xstate';
  342. export const modalMachine = setup({
  343. types: { /* ... */ },
  344. actions: { fetchData: () => fetch('/api/data') },
  345. }).createMachine({
  346. id: 'modal',
  347. initial: 'Closed',
  348. states: {
  349. Closed: { on: { TRIGGER: 'Loading' } },
  350. Loading: {
  351. on: {
  352. FETCH_SUCCESS: 'Success',
  353. FETCH_ERROR: 'Error',
  354. CLOSE: 'Closed',
  355. },
  356. },
  357. Success: { on: { CLOSE: 'Closed' } },
  358. Error: { on: { CLOSE: 'Closed', RETRY: 'Loading' } },
  359. },
  360. });
  361. ```
  362. See [`references/xstate-compat.md`](references/xstate-compat.md).
  363. ---
  364. ## Framework support
  365. | Framework | Mechanism |
  366. |-----------|----------|
  367. | React | `useMachine(config, impl)` via `useState` + `useRef` |
  368. | Vue | `useMachine(config, impl)` via `ref` + `readonly` |
  369. | Svelte | `useMachine(config, impl)` via `writable` store |
  370. | Vanilla JS | `createMachine(config, impl)` closure factory |
  371. | XState v5 | `setup()` + `createMachine()` |
  372. ---
  373. ## Contributing
  374. 1. Add a new component pattern to `references/component-patterns.md`
  375. 2. Add corresponding anti-patterns to `references/impossible-states.md`
  376. 3. Add validation gates to `references/slop-gates.md`
  377. 4. Run `node scripts/validate-model.js` on the example models
  378. ---
  379. ## License
  380. MIT © 2026
  381. ---
  382. <div align="center">
  383. <strong>state-machine</strong> — model before you build.
  384. </div>

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.