Code-to-flow — the sim_code_to_flow tool on sim.pflow.xyz's MCP server — takes source code and returns, as a Petri net, the state machine an LLM reads in it: the one that otherwise sits in switch statements, handler chains and early returns.
Hand it source code — Go, Python, JavaScript, Rust, Solidity, or anything else; the language is only a hint — and the LLM reads it, picks out states and actions, and returns a Petri net as JSON: places, transitions and arcs that can be fired, simulated, checked for deadlocks and replayed against a log of the running program, which is what a flowchart can't do.
The extraction is a single LLM call at temperature 0.2 under a fixed system prompt (pkg/generator/codetoflow.go in sim's source). Which model answers is a deployment setting, not part of the tool: sim's LLM client defaults to Gemini 2.5 Flash on Vertex and can be pointed at Claude, directly or on Vertex, or at any OpenAI-compatible endpoint (internal/llm/factory.go). This post doesn't say which one sim.pflow.xyz runs, because the source doesn't. The prompt asks for the structural rules — every place on at least one arc, every transition with an input and an output arc, the model kept minimal, essence over implementation detail — but a prompt only asks. What checks the answer is the validator (pkg/validator/validator.go): it rejects a model with no places or no transitions, an unconnected place or transition, an arc naming something undefined, or a guard that doesn't compile or names a place the net lacks, then walks the reachability graph (capped at 10,000 states) and, if it finds deadlocks, attaches one warning with their count. A deadlock is a warning rather than a failure, because a workflow that has finished is a deadlock too. The validator also computes boundedness and liveness, but the code-to-flow reply carries none of this. A model that validates is stored, and the reply gives its id plus whatever authoring warnings sim_create_model would give — transitions left to the default rate, a net where nothing can fire at its initial marking, a guard no simulation will enforce — but not the deadlock warning, boundedness or liveness. For those, run sim_verify on the stored model (bounded and deadlock-free are its defaults).
The same code looks different through different lenses:
Leave the focus unset and the tool asks for control flow; set another and we see the same code from a different angle. We call these lenses loosely. A focus mode is one line in a prompt and has no put. The lens in the categorical sense — a get/put pair between a state space and a view of it — is the analysis net in The Incidence Reduction, and whether extractions of the same code under two focus modes are related by anything like that is untested.
A simple order handler:
func processOrder(order Order) error {
if err := validate(order); err != nil {
return err
}
charge(order.Payment)
ship(order.Address)
notify(order.Customer)
return nil
}
We have no saved run of this example — no golden output, no test — so what follows is the shape of the answer, not a recorded result, and two runs need not agree. The answer this post first reported had six places (pending, validated, charged, shipped, completed, failed) and four transitions (validate, charge, ship, notify). As stated, that can't be quite right: with four transitions, failed either has no arc, which the validator rejects as an unconnected place, or validate writes to validated and failed at once. The early return needs a transition of its own (a reject from pending to failed, say). The code says nothing at all about a failed charge — its result is never checked — so a faithful extraction has no branch there either; the net shows that gap as an absence, and no deadlock check will flag it. Store the result and a scenario run shows flow through the pipeline.
pflow.xyz is for drawing nets from scratch. Code-to-flow solves the opposite problem: there's already a codebase and we want to see what state machine it encodes.
The LLM does the pattern recognition — identifying states, transition triggers, resource consumption — and produces a model of what it takes the implicit structure to be. That makes it a way to read unfamiliar code as well: paste it in, get back a net of its flow. Whether the net is easier to reason about than the source, and whether it is the source's net at all, we haven't measured; the second is the open question below.
sim_code_to_flow is on sim.pflow.xyz's MCP server (https://sim.pflow.xyz/mcp), reachable from Claude Desktop, Claude Code, Cursor or any other MCP client. It takes code, an optional language hint, a focus and a name. The answer first goes through the same decode as sim_create_model, which refuses a misspelt field by path instead of dropping it, then through the validator. When it passes both, it is stored as a new model you own and the tool returns its id; when it doesn't, the tool returns the raw JSON with the decode error or the validator's errors, so you can fix the model and store it by hand with sim_create_model. The tool needs sign-in.
The tool is the only surface: sim.pflow.xyz mounts no code-to-flow page or HTTP endpoint, and a deployment with no LLM provider configured refuses the tool.
Previously the pflow pipeline ran one direction:
design model → generate code → deploy
Code-to-flow reverses it:
existing code → extract model → analyze → improve → regenerate
Take a legacy system, extract the state machine as a Petri net, check its properties (bounded? live? deadlock-free?) with sim_verify — a proof only when it reports the search exhaustive; a partial search can only refute — then generate a clean implementation from the checked model. From there the model is the source of truth, and the LLM is the bridge between informal code and formal net. We have not yet run that loop end to end on a real legacy codebase.
Try it: connect an MCP client to https://sim.pflow.xyz/mcp and call sim_code_to_flow.
The step nothing checks yet is the first one. The validator says the net is well formed; it can't say the net is this code's net. The LLM's reading of the source is the only link, and we have not compared an extraction against what the program actually does. sim has three instruments for it. sim_conformance replays an event log against a stored model and reports fitness and precision, naming the activities that could not fire. sim_sequences runs the other direction: from one stored model it generates a deterministic suite of firing sequences — every transition fired once, a refusal probe for each, every conflict it finds fired then probed — to replay against an implementation outside sim, and its description names the code a sim_code_to_flow model came from as the case it is for. sim_distinguish compares two stored nets of one process, typically one formalized from a document and one read out of code, and answers proved, refuted with the shortest separating firing sequence, or unknown. So the test is buildable two ways: log the running code and replay the log against the extracted net, or drive the code with the net's own sequences and count where it disagrees. The only real code sim's tests replay a suite against is the vet-clinic example, and that Go was generated from its model by a since-removed code generator, not read by an LLM, so it shows the replay works, not that an extraction is faithful. Until one runs on an extraction, an extracted model is a well-formed reading of the code, and "source of truth" starts only at the point where we decide to treat it as one.
For readers of the March version (revised 2026-10-16, against the source; nothing re-run):
sim_verify does).failed needs a transition of its own. It is now presented as the shape of an answer, not a result, and the "what if charge fails" check is gone: the source has no failure branch for charge, so there is nothing for a deadlock check to find.sim_code_to_flow MCP tool on sim.pflow.xyz. The web page and HTTP endpoint this post described are gone; the tool stores a model that validates instead of returning it, and its focus defaults to control flow rather than auto-detect.sim_create_model's authoring warnings. The closing loop's proof condition is now sim_verify's own exhaustive/partial report rather than the validator's 10,000-state cap, and the open question names sim_sequences and sim_distinguish beside sim_conformance.Related: Introducing sim.pflow.xyz · Declarative Differential Models for the ODE theory · Small Models > LLMs, where code-to-flow is one stage of the pipeline · The Model Is the App