verify-statechart
Check a TLA+ model of a system that moves between states, such as a product flow, a protocol, or a service, and draw it as a Mermaid statechart. The report gives the shortest path to each state that breaks a rule. Use to show a bug as a path through states.
- License 许可
- MIT
- 最近更新
- 2026-11-05
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- verify-statechart
- description
- Check a TLA+ model of a system that moves between states, such as a product flow, a protocol, or a service, and draw it as a Mermaid statechart. The report gives the shortest path to each state that breaks a rule. Use to show a bug as a path through states.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档agents/openai.yaml139 B
- 参考文档CREDITS.md765 B
- 其他fixture/Toggle.cfg38 B
- 其他fixture/Toggle.tla540 B
- 参考文档references/render.md3.6 KB
03 SKILL.md 正文
Statechart
The chart shows how a system moves between states, in the words of the person who reads it. That person, the reader, decides whether the behavior is right.
This skill ships the judgment (words, chart shape, report reading) but not the runner: the upstream TypeScript runner plus its test corpus is too large to port, so this skill tells you how to install the toolchain and verify it with fixture/Toggle.tla before you model real code.
Install the toolchain
You need three things: a Java runtime, the TLC model checker jar, and a TypeScript-capable runtime for the chart runner.
- Java 11 or later. Check with
java -version. Any vendor build works; the install proof below ran on OpenJDK 21. - tla2tools.jar. Download the pinned release and verify the checksum:
If you use mise, the upstream runner can install both Java and TLC itself on first run (curl -sSL -o tla2tools.jar https://github.com/tlaplus/tlaplus/releases/download/v1.7.4/tla2tools.jar sha256sum tla2tools.jar # expect 936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88mise install java@temurin-25plus the pinnedtla2toolstool, network required). Without mise, setTLA2TOOLSto the jar path andJAVAto your java binary; the runner honors both. - A runner for the chart step. The full statechart runner is TypeScript and needs Node 22.18 to 22.x, Node 23.6 or later, Bun 1.1.5 or later, or Deno 2.0 or later. Plain TLC proving (step 2 alone) needs only Java plus the jar.
No network at install time means no TLC download and no mise install; say so and stop instead of faking a check.
Prove TLC runs
Before modeling, copy fixture/Toggle.tla and fixture/Toggle.cfg to a scratch folder outside the repo and run TLC directly:
java -cp "$TLA2TOOLS" tlc2.TLC -workers 1 -fp 0 -lncheck final Toggle.tla
Expect exit 0 with 2 distinct states found and No error has been found. That exact run is the install proof for this skill: a 2-state switch model, checked on OpenJDK 21 with tla2tools 1.7.4. If the jar is missing or Java is too old, fix the install; do not continue to a real model on an unverified toolchain.
Run
Work in a scratch folder outside the repo. Write a TLA+ spec and its config. Then run the chart command from your checkout of the upstream runner:
<runner dir>/scripts/statechart SPEC.tla [--config FILE] [--view FILE] [--out DIR]
scripts/statechart.ts is TypeScript, so run it with a runtime that can execute TypeScript (see step 3 above).
Write the spec
- Write each rule that the reader agrees to as an INVARIANT. A rule can be about a screen, a result, a stored value, or a message. If the model has no variable for a rule, add the variable. Never weaken a rule to make it hold.
- Write
Nextas a disjunction of the actions, such asYouPressPlay \/ YouPressStop. If you do not, TLC names every stepNext. - A state with no step out breaks
NoDeadlock, also when it is a correct end state. When an INVARIANT or a PROPERTY already has that name, the rule isCHECK_DEADLOCK. Add toNextan action that is true only in the end states and changes nothing, such asDone == phase \in {"paid", "failed"} /\ UNCHANGED vars, and give it a label instep().
Pick the chart
You do the work that needs judgment: the words on each state and arrow, the phases and their colors, the title, and the report to the reader. Put your work in a view module, and give it with --view.
To show the reader's words, the view exports state(vars). The value that state() returns picks the form:
- A string gives a flat chart:
export const state = (v) => (v.paid ? "Paid" : "Paying"); - An array gives parent states:
export const state = (v) => v.main.split("."); - An object gives one parallel region for each key:
export const state = (v) => ({ Playback: v.playback, Volume: v.volume });
Label each state with what the reader can see or cares about, such as "Paying" or "Lease held, write pending". Keep variable names out of labels. In vars, a TLA+ sequence is an object with keys from 1, so v.pc[1] is pc[1]. A set is an array.
The view can also export step(action, from, to). It gets the TLC action name and the values before and after the step, and it returns the label of the arrow. Write each step label as the user sees it happen, such as "you press play" or "the connect fails". Do not name the code or the TLA+ action. Two actions that end the same in the chart get the same label, so that they share one arrow.
When a step can occur only in some conditions, end its label with the condition in brackets, in the reader's words, such as you press play [while the file loads]. In a regions chart, the command writes the condition on the other regions on the arrow, in the words of their labels, such as [when Offline]. Your brackets replace it, and two arrows from one state can then look the same. So in a regions chart, do not write brackets for a condition on another region. When a value that no label shows decides where a step goes, name the result in the label, such as "the roster read fails".
The view can also export these:
group(vars)returns the name of a phase. Each chart state gets the color of its group. When the model states behind one chart state are in different groups, that state gets no color.colorsgives each group name a color class.titleis a string that the chart shows at the top.
The command calls state() and group() at most once for each model state, and step() at most once for each step. The chart and the report both use those answers. So make each function depend only on its arguments.
The chart does not draw a step that stays in one label. Split a label when the reader must see such a step.
Aim for about 20 arrows or fewer, because a busier chart is hard to read. First return coarser labels from state(). Give one label to values that act the same, and leave out a detail that the reader does not need, such as a call in flight whose return changes nothing. Keep each state of a bug path, and keep each mark. When a merge changes a breaks state to mayBreak, it hides where a rule breaks. Do not merge two states that break different rules, because the reader then cannot see which rule breaks where. If the chart is still too busy, return null from step() for the steps that the reader does not need, such as a reset that every state has, or a step whose arrow repeats what other arrows show. Obey these rules when you hide steps:
- Keep each chart state reachable by arrows from a start state.
- Keep at least one arrow out of each chart state that has a step out in the model.
- Hide all the steps of an arrow, or none of them. When you hide only some, its condition gets narrower.
- In the hand-off, say which steps the chart hides.
Read the report
- In the chart, a state that breaks a rule has the class
breaks. When only some model states behind it break the rule, it has the classmayBreak. The Legend names the rules of each mark. When two rules break, it names both on one mark, so say in the hand-off which state breaks which rule. In a regions chart, a state gets a mark when each combination of region states that includes it can break a rule. When a combination can break a rule and none of its states has a mark, each state in that combination gets a mark. - TLC goes past a state that breaks a rule, so the chart shows the states after a bug.
- Because TLC goes past bugs, a model with no limit on its states can run without end. Keep the constants small, or add a CONSTRAINT.
- With a VIEW or a SYMMETRY, TLC counts states that it treats as the same as one state, and the chart draws that one state. An arrow can lead to it rather than to the state that the step reaches, and the report says so.
- TLC checks the rules in each state past a CONSTRAINT or an ACTION_CONSTRAINT, but it does not explore that state or check it for deadlock. When TLC's shortest path for a rule ends in such a state, the chart draws that state, and the report gives that path. The chart does not draw the other states past the bound. A deadlock in such a state does not show. TLC also checks the rules after each step that an ACTION_CONSTRAINT excludes, also when it reaches the next state another way. When TLC's shortest path for a rule ends with such a step, the chart draws that step.
- The command checks the rules with TLC on the config as written, with one worker. When a rule breaks, the command removes that rule and runs TLC again, until no rule breaks. After the first break, each run stops at 100,000 distinct states, so that a large model does not run without end. When a run reaches that bound or stops on an error, the report lists the rules that it did not check under "Rules not checked", and the chart does not mark them. A rule that is not checked can hold or break. To check it, remove the rules that break from the config, or make the model smaller. The bound adds a module that changes TLC's order of the variables, so for a property TLC can find a different counterexample than a run without the bound.
tlc.outis what TLC printed on the config as written. When the chart does not show the bug path of a rule that breaks,tlc-RULE.outis what TLC printed for the run that found it.
Show the chart
Show chart.mmd to the user as a mermaid code block. The chart has a budget of 500 states, counted by TLC on the config as written. Above that, the chart draws only the paths to the rules that break, and when no rule breaks, the command writes no chart.mmd. It still checks each rule, and the report gives the state count and each bug path. To see the whole graph, make the model smaller.
When the user asks for an image, or a chart is too large to read as text, render with references/render.md. Do not use a different renderer unless the user asks for it.
Hand off
Give each chart and its Mermaid text to the person who must decide. Add one line for each bug: the rule, the reader's sentence for that rule, and the path as the report numbers it. Say what the model leaves out. Give the command that makes the files again, with a new --out folder.
When the model describes code, replay each bug path against the real code, as a test or a live repro, one step for each action. If a bug does not occur, think that the model is wrong until you show that it is not.
04 同仓库更多 Skills
whips
Route any non-trivial task through one entry: match a playbook, drive HIT skills plus subagents, open a reviewed ready PR with ship-pr-shaped evidence.
verify-upkeep
Periodic upkeep for a project's verification skill: source wave plus live pass per feature, at most one PR of proven corrections. Use to audit the verify skill.
verify-new
Generate a project-local skill that drives the app like a user (launch, doctor, drive, evidence, feature map), proven once. Use when a project has no scripted proof.
ship-triage
Move issues and external PRs through a state machine of triage roles, categorise, verify, interview if needed, and write agent-ready briefs.
ship-runner
Run ready-for-agent issue queues on any schedule through /whips intake, one fresh worktree each, landing per risk tier, with the agent and model you pick at setup.
setup-ts-modules
Wire dependency-cruiser into a TypeScript repo so each package is a deep module, with implementation hidden in subfolders and reachable only through its entry-point files. User-invoked.