agentleFS
statelyaistatelyai/xstate/docs/agents.md

xstate

AGENTS.md30k starsChanged 21 months agoMITView on GitHub

Author, inspect and test XState with the installed version's contracts.

Trending

Less talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 1 mentionApr 2026: 1 mentionMay 2026: 0 mentionsJun 2026: 2 mentionsJul 2026: 8 mentionsAug 2026: 1 mentionSep 2026: 4 mentionsOct 2026: 4 mentionsNov 2026: 1 mention
Dec 2025Jun 2026Nov 2026
Mentions a month of the statelyai/xstate repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about statelyai/xstate

The biggest 5 of 68 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 68

Talked about on GitHub, YouTube, Hacker News, Bluesky and Stack Overflow (68 times).

On GitHub · 38

33 more on GitHub

On YouTube · 24

19 more on YouTube

On Hacker News · 2

On Bluesky · 2

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 31,843 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

We split this agents.md into the rules it gives an agent

9 rules. About 0 are common, 2 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read this page from the installed package, usually node_modules/xstate/docs/agents.md.

    line 6
  2. Very specific:

    Use { target: 'next' } for a static transition.

    line 16
  3. Distinctive:

    Put transient data in state input when it belongs to the active state.

    line 23
  4. Very specific:

    Keep target literals visible when visual inspection matters.

    line 28
  5. Very specific:

    Before exporting code-authored definitions, inspect getMachineSerializationDiagnostics(machine).

    line 31
  6. Very specific:

    Use machineToJSON, machineConfigToJSON and machineFromJSON for definitions.

    line 36
  7. Very specific:

    Use getPersistedSnapshot and the persistence guide for running state.

    line 37
  8. Very specific:

    No command installs packages, imports application modules, executes code expressions or runs external effects.

    line 46
  9. Distinctive:

    Keep sampled tests, bounded exploration and proof distinct.

    line 138

≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
agents.md

Read this page from the installed package, usually node_modules/xstate/docs/agents.md. docs/index.md identifies the exact version. docs/api-stability.json classifies exports from that source tree. Prefer these files over examples for another major version. Install framework and integration packages from the same release family.

Author v6 machines

  • Declare contracts under schemas, using types<T>() for TypeScript-only inference or Standard Schema for runtime schemas. Inference alone does not validate input. See runtime validation.
  • Use { target: 'next' } for a static transition. Use one synchronous function for a conditional transition; return undefined before any enqueue call to refuse the event. String transitions and transition arrays are not v6 authoring syntax. See transitions.
  • Return a shallow { context: { field: value } } patch. Keep I/O, time reads, randomness and external mutation outside transition calculation. Queue effects with enq, or invoke actor logic for asynchronous work.
  • Put transient data in state input when it belongs to the active state. Use typestates to refine root context. State input is removed on exit; root context survives state changes.
  • Invoke for work owned by a state's lifetime; spawn for actors with an explicit longer lifetime. Stop, cancellation and service failure need tests.
  • Keep target literals visible when visual inspection matters. A graph is not complete when analysis.transitionTargetsComplete is false. Read its diagnostics rather than guessing the missing destinations.
  • Before exporting code-authored definitions, inspect getMachineSerializationDiagnostics(machine). Serialization can omit inline actors and runtime schemas. Code expressions need explicit evaluators and dependencies; JSON conversion does not preserve arbitrary closures.

Use machineToJSON, machineConfigToJSON and machineFromJSON for definitions. Use getPersistedSnapshot and the persistence guide for running state. A definition and a checkpoint are different artifacts. Do not restore old snapshots without checking their version and migration requirements.

Local JSON operations

The core CLI's agent commands return one JSON object with schemaVersion, xstateVersion, command, ok and either result or error. Failures exit with status 1. --json is accepted; JSON is also the default for these commands. No command installs packages, imports application modules, executes code expressions or runs external effects. migrate remains a separate source transformation command that delegates to the codemod package.

To migrate a v5 machine file, use the @xstate/codemod loop. Run xstate-codemod baseline <file> before editing, then xstate-codemod migrate <file> --json. Exit code 2 means the report's manualSites need manual changes. Then run xstate-codemod verify --baseline <baseline.json> <file> --json. It exits with 0 when the v6 behavior matches the v5 trace, 3 when a diff is unclassified, 4 when a module fails to load or run, and 1 on a usage error. See the migration guide.

CommandContract
xstate docsLocate installed documentation and read export stability.
xstate inspect machine.jsonInspect a data-only definition and static graph completeness.
xstate validate machine.jsonCheck definition structure. This does not validate runtime event payloads.
xstate simulate machine.json events.jsonCalculate stable snapshots and describe effects without executing them.
xstate test machine.json checks.jsonExplore supplied event representatives and check stable-state safety and reachability assertions.
xstate replay machine.json fixture.jsonReplay a counterexample against the same definition and XState version.
xstate diff before.json after.jsonReport structural JSON changes. Compatibility is explicitly notChecked.

These commands accept JSON definitions, not TypeScript source files. Definitions with @code expressions return EVALUATOR_REQUIRED and their JSON Pointer paths. Definitions requiring custom runtime implementations must use the library with explicit sources instead. The CLI never fills missing implementations with stubs.

For example, save this as machine.json:

{
  "id": "review",
  "initial": "pending",
  "states": {
    "pending": {
      "on": {
        "APPROVE": { "target": "approved" },
        "REJECT": { "target": "rejected" }
      }
    },
    "approved": { "type": "final" },
    "rejected": { "type": "final" }
  }
}

An events file is an array such as [{ "type": "APPROVE" }], or an object { "events": [...], "input": ... } when startup input is required.

A checks file supplies event representatives and at least one assertion:

{
  "events": [{ "type": "APPROVE" }],
  "never": ["#review.rejected"],
  "reachable": ["#review.approved"],
  "limit": 1000
}

never and reachable use existing state IDs prefixed with #. Coverage is relative to the supplied event representatives and stable macrostep snapshots. The example's event array excludes REJECT; it makes no assertion about runs that send it. An event map instead augments the machine's default cases, including unconfigured payload-free events and synthetic actor/timer events; see event cases. The default traversal limit is 10,000. Exceeding a bound fails instead of reporting success. A reachability failure means no supplied representative witnessed the state, not that the state is proven unreachable.

A forbidden-state failure contains error.details.fixture. Save that object and pass it to replay. Its definition hash and XState version prevent accidental replay against another model. Replay reports a property violation again while the same assertion still fails. These CLI fixtures are separate from @xstate/test fixtures. Use model-based testing for PBT, payload shrinking, service outcomes, concurrency testing and comparison with an actual system under test.

Repair and verify

Preserve the failing event sequence before editing. Reproduce it, make the smallest behavior change, then replay it and run relevant tests. Check forbidden behavior and resource cleanup as well as successful outcomes. A corrected type error must also compile without suppressions or broad casts.

For a running agent, expose public event schemas and descriptions through a host adapter. Type-only schemas do not describe runtime parameters. Recheck state revision and host authorization when accepting a command. snapshot.can(event) is advisory, and sending an event does not establish durable commit or completion. Actor completion capability is distinct from idleness or waiting for input.

Keep sampled tests, bounded exploration and proof distinct. State the event representatives, state abstraction, time and schedule assumptions, and limits with the result. Experimental APIs may still change independently of the public beta surface.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.