Coding prompts · Prompt
Model a statechart and its shortest bug path (prompt)
model-statechart-bug-path-prompt
Writes a TLA+ model of a product flow, protocol or service, checks each rule with TLC, and reports the shortest path to every state that breaks a rule, plus a Mermaid statechart. Use when you want a statechart of a failing path, and you can run TLC, Java and mise.
Works with: Any AI Not yet model-tested; testing Jan 2027
Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works
Install in Claude Code, Cursor or Codex (optional)
Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.
Claude Code (all your projects)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/model-statechart-bug-path-prompt/raw' -o ~/'.claude/skills/model-statechart-bug-path-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/model-statechart-bug-path-prompt/files/LICENSE.txt' -o ~/'.claude/skills/model-statechart-bug-path-prompt/LICENSE.txt'Cursor (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/model-statechart-bug-path-prompt/raw' -o '.cursor/skills/model-statechart-bug-path-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/model-statechart-bug-path-prompt/files/LICENSE.txt' -o '.cursor/skills/model-statechart-bug-path-prompt/LICENSE.txt'Codex and other Agent Skills tools (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/model-statechart-bug-path-prompt/raw' -o '.agents/skills/model-statechart-bug-path-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/model-statechart-bug-path-prompt/files/LICENSE.txt' -o '.agents/skills/model-statechart-bug-path-prompt/LICENSE.txt'
Or connect the whole library over MCP
Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):
{
"mcpServers": {
"theskillvault": {
"url": "https://theskillvault.ai/mcp"
}
}
}Some bugs are a path, not a bad line. This prompt writes a small TLA+ model, asks TLC which rule breaks, and draws that path as a statechart. The reader decides if the behaviour is right.
Requirements
You need all three before the first check. Say which are missing and stop. Do not guess.
- TLC, the TLA+ model checker.
- Java, which TLC runs on.
- mise, which installs TLC and Java on the first run. That install needs the network. Ask before it downloads anything.
When to use
- A product flow, protocol or service moves through states, and you want the shortest path that breaks a rule.
- You can run TLC, Java and mise, or you are willing to install them when asked.
- You want a statechart of those states, with the broken ones marked.
When not to use
- You only want a flowchart, sequence diagram or architecture sketch. Use draw-mermaid-diagram-prompt.
- You want tests of visible behaviour. Use test-behaviour-not-implementation.
- You cannot install Java or TLC. Write the states in prose and stop. Do not pretend TLC ran.
Steps
- Confirm TLC, Java and mise. Ask before mise downloads them.
- Make a new empty folder for this run. Never replace or delete an output folder that already has files.
- Paste the prompt below with the flow and the rules the reader agrees to.
- Run TLC yourself with the absolute paths from the prompt. Read the error trace.
- Show the Mermaid statechart and one numbered path per broken rule.
- If the model describes real code, replay each path against that code.
Prompt
Model the flow below in TLA+. Check it with TLC. Draw a Mermaid stateDiagram-v2 of the states the reader cares about.
Flow: <WHAT MOVES THROUGH STATES>
Rules the reader agrees to: <ONE SENTENCE PER RULE>
Requirements for this run: TLC, Java and mise. If one is missing, stop and name it. The first mise install needs the network. Ask before you install.
1. Put each agreed rule in its own INVARIANT. If the model has no variable for a rule, add the variable. Never weaken a rule so the check passes.
2. Write Next as a disjunction of named actions, such as PressPay or PressCancel. Otherwise every step is just called Next.
3. A state with no way out fails a deadlock check, even when it is a correct ending. Add an action that is true only in those end states and changes nothing.
4. Keep constants small, or add a constraint, so TLC cannot run forever.
5. Write the spec and config with LF line endings. CRLF on Windows makes TLC miss the file.
6. Use absolute paths for JAVA and for the TLA+ tools jar (TLA2TOOLS). A relative path breaks because TLC's working directory is the folder it was given, not the folder you started in.
7. If you compare temp paths, resolve TMPDIR with realpath first. On macOS TMPDIR is a symlink, and a string compare against /tmp is wrong.
8. Run TLC in a brand-new empty output directory. Do not point it at a folder that already contains other files. Replacing such a folder can delete nested files you did not mean to touch.
9. When a rule breaks, record TLC's shortest error trace. Remove that one rule and run again, until no rule breaks or you hit a bound you state (100,000 distinct states is enough). List any rule you did not check.
10. Draw a stateDiagram-v2. Labels are what the reader sees, such as "Paying", not variable names. Aim for about 20 arrows. You may merge states that act the same, but keep every state that sits on a failing path. Do not merge two states that break different rules.
11. Report, for each broken rule: the rule, the reader's sentence, and the shortest path as numbered steps. Say what the model leaves out. Give the exact command that regenerates the files.
Do not claim TLC passed unless you ran it and the output says so.
How to adapt
- No mise? Install TLC and Java some other way you already trust, still with absolute paths, and say what you used.
- The chart is too busy? Coarsen labels, but keep the failing path.
- The model is of real code? Replay each path as a test or a live repro. If the bug does not happen, treat the model as wrong until you show it is not.
Gotchas
- Replacing an existing output folder can delete unrelated nested files. Use a new directory every time.
- A relative JAVA or TLA2TOOLS path fails once TLC runs inside the snapshot folder. Use absolute paths.
- A symlink TMPDIR (the macOS default) makes path checks lie if you do not realpath it first. CI on a default Ubuntu /tmp will not show this.
- CRLF in the spec or config is a Windows failure mode. Write LF.
- TLC keeps going after a broken rule, so later states still appear. A model with no bound can run without end.
- With a view or a symmetry, TLC may treat several states as one. The report should say so.
- Do not put secrets, tokens or private customer data in the spec. It will be copied into the report.
Portability
The spec is plain TLA+ and works with any TLC build. mise is the installer named here. Another installer is fine if Java and TLC still end up on absolute paths. The chart is Mermaid, so it renders on GitHub or any Mermaid tool. The model checker needs Java. It does not need a particular AI.
Done when
- TLC, Java and mise were present, or you stopped and named the missing one.
- Each agreed rule is an invariant, and the report gives the shortest path for each rule that breaks.
- The statechart keeps those failing states, and the output folder is a new directory you created.
- You did not claim a rule holds unless that TLC run checked it.
Example prompt
"Model this checkout flow in TLA+. Rules: payment starts only from the cart, and a paid order never returns to the cart. Run TLC with Java and mise, and give me the shortest path that breaks a rule plus a statechart."
---
Modified from the original "statechart" skill in cursor/plugins (pstack) (Copyright (c) 2026 Lauren Tan, MIT). Original: https://github.com/cursor/plugins/tree/2f87c854fe3e2fcda44ca86b46ede35aad3c46b7/pstack/skills/statechart. Changes by TheSkillVault are listed in the metadata above. See LICENSE.txt.
Bundled files
Licence
Adapted from Lauren Tan (poteto), pstack plugin in cursor/plugins (Copyright (c) 2026 Lauren Tan), MIT License. Modified from the original by TheSkillVault on 2026-11-17. Rewritten as a house-style prompt that runs TLC directly. The bundled statechart toolchain was not copied. Requirements are TLC, Java and mise. The output folder is always new, JAVA and TLA tool paths are absolute, TMPDIR is realpathed, and specs use LF. Not the original file.
Licence: MIT License. Attribution when you reuse it: Based on work by Lauren Tan (poteto), pstack plugin in cursor/plugins (Copyright (c) 2026 Lauren Tan, MIT License), https://github.com/cursor/plugins/tree/2f87c854fe3e2fcda44ca86b46ede35aad3c46b7/pstack/skills/statechart; adapted by TheSkillVault, https://theskillvault.ai