formalmethods.dev

§ 5.4 · TypeScript · this lab

TypeScript

the same engine you are reading, imported as a library.

The whole lab is plain TypeScript with zero dependencies beyond the site itself: the parser, both evaluators, the checker, and the fuzzer are importable functions — this page runs them in your browser.

The property you write in a test can be the same string you hand the MCP server, which is the same formula the UI highlights. One engine, many faces — nothing to translate, nothing to drift.

in TypeScript

modelCheck(parseLtl('G (coin -> F dispense)'), model)

as LTL · expected holdsG (coin -> F dispense)
vend.test.ts
import { parseLtl } from "@/lib/formal/ltl";
import { modelCheck, parseKripke } from "@/lib/formal/model";

const vending = {
  atoms: ["ready", "coin", "dispense"],
  initial: ["idle"],
  states: [
    { id: "idle", atoms: ["ready"],    next: ["paid"] },
    { id: "paid", atoms: ["coin"],     next: ["vend"] },
    { id: "vend", atoms: ["dispense"], next: ["idle"] },
  ],
};

test("every coin is eventually dispensed", () => {
  const { model } = parseKripke(vending);
  const r = modelCheck(parseLtl("G (coin -> F dispense)"), model);
  expect(r.verdict).toBe("holds");   // exhaustive: depth = all states
});
the artifact · The same JSON as above, checked exhaustively: every lasso of the structure, depth = all states, no truncation — so the verdict is allowed to say `holds`.
idle · readypaid · coinvend · dispense
◎ start = initial state · dashed loops stutter (the system freezes)
exposed over mcpmodel_check
view the JSON-RPC body · POST to /api/mcp
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "model_check",
    "arguments": {
      "formula": "G (coin -> F dispense)",
      "model": {
        "atoms": [
          "ready",
          "coin",
          "dispense"
        ],
        "initial": [
          "idle"
        ],
        "states": [
          {
            "id": "idle",
            "atoms": [
              "ready"
            ],
            "next": [
              "paid"
            ]
          },
          {
            "id": "paid",
            "atoms": [
              "coin"
            ],
            "next": [
              "vend"
            ]
          },
          {
            "id": "vend",
            "atoms": [
              "dispense"
            ],
            "next": [
              "idle"
            ]
          }
        ]
      }
    }
  }
}
how the lab helps · skills guide + mcp against TypeScript
read_skills_guide

Zero translation here: the guide's grammar is this engine's parser. An agent writing a TypeScript property reads Step 1 and is already writing valid input — the strings are interchangeable.

check_ltl

CI runs are traces: agents feed a request/response log straight into check_ltl — runtime verification with the same formula the model checker proves and the fuzzer attacks.

model_check

The property that passes CI on today's runs gets its exhaustive answer here: hand the same artifact JSON to model_check and holds means every behaviour, not every logged one.

Seeds and verdicts are the CI contract: falsify returns the seed it used, so a failing campaign is one number in a bug report.

The MCP server is the same functions behind a route — agents and tests share one oracle.

field guide · Runtime verification · Specification as the test oracle