Skip to content

ritsu

Write the rules a system must follow in small languages, and check that every input gets exactly one answer and that no two rules disagree. From the checked rules, ritsu generates code, pages for people to read, and the inputs, answers and scenarios to test with.

Coding agents now write code faster, and more of it, than anyone can read line by line. That makes one question sharper: what is the code there to carry out, whoever — or whatever — writes it? The contracts between services and inside them. The business rules. The calendars and the deadlines. The ledgers and the bounds on them. The skeleton of a workflow. Who may do what. Where each requirement came from, and what still satisfies it.

ritsu gives each of those a small language of its own, in a file people can read. Each language checks what it says as far as it can be checked — over every input, every day, every path, not a sample — generates code where code is needed, and draws pages for whoever needs to understand it. Because the ten share one toolchain, a proof does not stop at a language's edge: a workflow knows the preconditions of the rules it calls, a rule knows the days a calendar can come to, a ledger knows the amounts a rule can return.

Agents write the glue. ritsu holds what it all has to carry out.

Try it in the browser Try it full screen GitHub

The ten languages

File What it is for Read more
rulec .rule business rules: tariffs, fees, eligibility, tax the rulec site
dandori .flow the skeleton of a workflow the dandori site
koyomi .cal dates: closing and payment days, business days, legal periods README
chobo .book ledgers: accounts, their bounds, transfers, holds the chobo site
geas .geas claims about the code an agent wrote README
yuen .req where requirements come from, and what satisfies them README
sakai .ctx the map of bounded contexts README
sekisho .gate who may do what: roles, attributes, relations, with rules and dates as conditions the sekisho page
kaname .kn a small general-purpose language for a functional core: code with no input or output in ritsu's types, which calls rules, dates and books too the kaname pages
ringi .ringi the requests a company's departments make and approve: the form, the route and who answers each stage, the deadlines, what happens when a request ends the ringi pages

Each language stands on its own: you can use rulec without writing a .flow. A file never mixes two languages, because a tariff, a calendar, a ledger and a workflow are read by different people.

  • rulec writes a rule as a set of tables, with the calculations, the exceptions and the provisos around them. rulec check proves that every input in the declared domain gets exactly one answer, checks units and money, and writes a certificate that a proof in Lean rechecks. Only a rule that passes compiles, into plain functions in twelve languages.
  • dandori says what a workflow calls, in what order, with which retries and timeouts, and what each call does to a case outside — an order, a payment, a booking. dandori check shows that on every path each case is left untouched or finished, never halfway, and the same file becomes Temporal, Step Functions, Argo Workflows, Lambda durable functions or pydantic-graph.
  • koyomi writes a date as a contract or a law says it: thirty days after the invoice, moved to the next business day. koyomi check computes it on every day of the declared range and checks each claim on every one of them; only a file that passes compiles, into TypeScript, Python, Go, Rust and SQL, and into a Wasm module that any host calls with one JSON object.
  • chobo declares accounts, the bounds each must keep, and the transfers between them, checks that no sequence of transfers, holds and expiries can take an account past a bound, and generates clients for PostgreSQL, TigerBeetle and the MySQL family (MySQL, TiDB and Vitess).
  • geas runs each claim about a program against it — a command line, an HTTP service, a page in a browser — and, given a diff, tells which claims it touches. Given an OpenSpec spec, it lists the scenarios that no claim of the same name checks.
  • yuen says where each requirement came from, who owns it, and what satisfies and verifies it, with every link pinned by hashes at both ends. It pins the requirements of an OpenSpec spec the same way.
  • sakai maps which context owns which files and who may depend on whom, and checks the references that cross contexts, in the files of every language here, in the OpenAPI and AsyncAPI documents services keep as their contracts, and in the code. It does not count a use book, since another context reaches a book through the service in front of it.
  • sekisho says, in a gate (a .gate file), which principal may do which action on which resource, with roles, attributes and relations, and with the answers of a rule and of dates as conditions. sekisho check walks every combination that can happen and decides each as Cedar does; only a gate that passes compiles, into Cedar's schema and policies, and into TypeScript, Python and Go that compute the conditions from the service's own data and ask Cedar. The sekisho page follows the answer of a rule from a gate to Cedar.
  • kaname is a small general-purpose language for the functional core of a program, the part with no input or output: a module (a .kn file) moves a state by events, checks and normalizes input, keeps counts in dicts and sets, reshapes trees, and puts a rule's inputs together, carries one answer into the next call and hands an amount to a book, in ritsu's types. kaname check holds it to units, money, rounding and int64 and to the range of every value it passes, and shows that a function marked total answers every input of its ranges; ritsu gen writes it as TypeScript, Python, Go and Rust for the host to call, beside the code it calls, and the Rust builds to a Wasm module that any host calls with one JSON object. The kaname pages show how a module is written, four functional cores called from TypeScript, Python and Go, what the check guarantees, how a module calls rules, dates and books and how a claim about every input is proved in Lean.
  • ringi writes one kind of request a company's departments make and approve (an expense, leave, a purchase, a contract, access to a system) as a .ringi file: its form, the route it takes and who answers each stage as a relation in the organization, its deadlines, and what it holds in a book or starts in a workflow when it ends. ritsu ringi check finds who answers each stage for every person who may submit it, in every version of the organization's data, lowers its tables, conditions and deadlines to rulec and koyomi to be checked, and runs its scenarios on the reference interpreter; ritsu gen writes each request's ticket as TypeScript, Python, Go and Rust, with the screens, the OpenAPI document and the vectors a server of requests is tested with. ringi-server, a framework in Go, is that server, with the pages people use in a browser. The ringi pages show how a request type is written, what the check guarantees, how a person reads one, how it reads the other languages and what is generated, and what the server does.

Where the languages meet

The languages share one toolchain so that what one has checked, another can take as given. Here a refund rule takes for granted that nobody asks for more than they paid:

rule refund_check v1
description "Whether a refund is paid at once or reviewed. A refund never asks for more than was paid, which the rule takes for granted"

enum path = at_once | review

inputs
  paid  : number  range >=0 <=10000
  asked : number  range >=0 <=10000

constraint asked <= paid

outputs
  route : path

table pick
policy unique
| asked | -> route : path |
| <=100 | at_once         |
| >100  | review          |

A workflow calls it with whatever the customer asked for:

workflow refund v1
description "Pays a refund back at once or sends it to review, as the rule decides"

use rule check from "refund_check.rule"
  lambda "arn:aws:lambda:us-east-1:123456789012:function:refund-check"

inputs
  order : string
  paid  : int  range >=0 <=10000

task ask_amount(order: string) -> int range >=0 <=10000
  lambda "arn:aws:lambda:us-east-1:123456789012:function:ask-amount"
  idempotent

task pay_back(order: string, amount: int range >=0 <=10000)
  lambda "arn:aws:lambda:us-east-1:123456789012:function:pay-back"
  key

flow
  let asked = ask_amount(order: order)
  let decision = check(paid: paid, asked: asked)
  match decision.route
    at_once => pay_back(order: order, amount: asked)
    review => pass

Each file passes its own language's check. Together they do not (the two files are from the reproduction that ritsu explain E201 prints, which calls the rule from a module of kaname too):

$ ritsu check .
ok refund_check.rule
refund.flow: ok
error[ritsu E201]: refund.flow:21:1: The call of the rule check can give it values that break its precondition `asked <= paid`
    21 |   let decision = check(paid: paid, asked: asked)
  = `asked` is `>=0 <=10_000` and `paid` is `>=0 <=10_000`, and at asked = 10_000, paid = 0 `asked <= paid` does not hold
  = The rule's generated code refuses a call that breaks a precondition at its door, so this call fails only when the workflow runs. The ranges are dandori's, from what the runs that reach this call last put in the values.
  = Branch so that the precondition holds before the call, or narrow the ranges (the `range` of an input or a task's result).
ritsu check: 2 files (rulec 1, dandori 1): 1 fail (1 error); borders between the languages: 1 checked, 0 undecided

Every check that crosses languages comes to one of three answers: it holds, here is a case where it does not, or it cannot be decided — and then it says why. Nothing passes in silence. Among them:

  • a rule's preconditions, at every call a workflow makes;
  • the days a koyomi date can come to, as the range of a rule's input (range from koyomi), and against the range the rule declares;
  • the day a workflow gives a koyomi date, against the range of its input: a day of another date, a date or a time the workflow holds to a range, or now in the period the workflow runs in;
  • a rule's output as the amount of a chobo transfer, and the refusals that transfer can come to;
  • a chobo hold's expiry, against the wait a workflow counts in business days;
  • the value hand-written code carries from one language to another, named with fed by where it is taken: what the source can come to against what the place takes (the code that carries it is not checked);
  • every value a kaname module passes to a rule, a date or a transfer, against the range that one declares;
  • money and units, one type across rulec, dandori, chobo and kaname;
  • every operation a context of sakai's map opens, held to the action of a gate that guards it, and every operation a workflow calls, to what its gate allows the workflow;
  • yuen pins each table, date, claim, task and function one by one, and sakai checks each reference that crosses contexts, with its line.

With --format json, ritsu check says the same to a program. Each file in files has check, what its own language's check writes about it with --format json, without the path and the diagnostics, which ritsu gives outside it: for a kaname module, its summary and the effect of each function; for a book, its report; for a spec, its claims; for a date file, a gate or a map, ok and summary, and for the requirements of a module, the same on each of its .req files. A rule's is null, as rulec writes no object for a file; a flow's is {}, as dandori writes nothing more of it than its path and its diagnostics. borders keeps the three counts, and lists each border under records:

$ ritsu check . --format json
{
…
  "files": [
    {
      "tool": "rulec",
      "file": "refund_check.rule",
      "ok": true,
      "check": null
    },
    {
      "tool": "dandori",
      "file": "refund.flow",
      "ok": false,
      "check": {}
    }
  ],
…
  "borders": {
    "held": 0,
    "failed": 1,
    "undecided": 0,
    "records": [
      {
        "check": "precondition",
        "about": "asked <= paid",
        "at": {
          "tool": "dandori",
          "file": "refund.flow",
          "line": 21
        },
        "to": {
          "tool": "rulec",
          "file": "refund_check.rule",
          "line": null
        },
        "result": "failed",
        "code": "E201"
      }
    ]
  }
}

A record says which check it is, what it is about, and its two sides: at, where ritsu gives the diagnostic, and to, the other side, each with its tool, file and line. Then come its result and the code of the diagnostic ritsu gave, null when it holds. A side's line is null where its language does not say one, as for the rule that declares a precondition, and to is null where there is no other side, as for an operation no gate guards. In a module, each side says its dependency, as a file does. There are as many records as the three counts add up to, in the order of this table, then by the file and the line of at, so the same files give the same JSON. A check keeps its name, and a new one is added at the end.

check What it checks Fails / undecided
precondition a precondition of a rule, at a call from a workflow or a kaname module E201 / W201
rule_date_input the day a call gives a rule's date input, against the range the rule declares E202 / W202
range_from_koyomi a rule's input whose range is the days of a koyomi date (range from koyomi), which rulec's check holds the rule to rulec's own
transfer_amount the amount a call gives a chobo transfer, against what chobo takes E203 / W203
transfer_refusals the refusals a transfer's do or hold can come to, against those the task handles E204 / W204
hold_expiry a hold's expiry, against the time to the call that settles or voids it E206 / W206
koyomi_date_input the day a call gives a koyomi date's input, against its range E205 / W205
secret_destination where a task sends a value its contract marks secret, by the map E905 / W905
operation_guard an operation a context opens, held to the action of a gate that guards it E907 / W907
workflow_permission an operation a workflow calls, against what its gate allows the workflow E908 / E909 / W909
fed_by a place with fed by, against what its source can come to E207 (E208 for a source that is not there) / W207
ticket_gate what a request's route decides (the operations of a ticket, the approvers of a stage, self approval), against the gate the request reads E911 / W911
ticket_hold a hold a request makes when it is submitted: its expiry against how long a round can take, and whether every requester has a value for its arguments E209 / W209
ticket_flow what a request gives a workflow it starts or asks, against the workflow's inputs, and what an agent's or a summary's workflow answers E210 / W210

Where a value comes from

Hand-written code carries values from one language's world to another's: the output of a rule to the input of the next, the balance of a book to a workflow, a field of a request to a gate. No check could see them. fed by at the end of the line that takes the value says where it comes from, on an input of a rule, a workflow or a dates file, a field of a workflow's or a module's record, an attribute or an input of a gate, and a parameter of a function:

food : number  range >=0 <=60  fed by rulec "province_income.rule" output food

What follows is a naming, in the form the whole toolchain names things, from the directory of the file it is written in. Each language says on its own only whether the form reads and stands where it can. ritsu check asks the two languages:

The value comes from Named as
an output of a rule rulec "<file>" output <name>
an account of a book chobo "<file>" account <name>
a date of a dates file koyomi "<file>" date <name>
a field of a .proto message proto "<file>" message <name> field <name>
a property of an OpenAPI schema openapi "<file>" schema <name> property <name>
what an operation of OpenAPI writes in place (a request body, a parameter) openapi "<file>" pointer "<pointer>"
a property of a JSON Schema jsonschema "<file>" def <name> property <name>, or jsonschema "<file>" pointer <pointer>
an output of a workflow, or a field of its record dandori "<file>" output <name>, dandori "<file>" record <name> field <name>
a field of a kaname record kaname "<file>" record <name> field <name>
a place that took the value first rulec "<file>" input <name>, koyomi "<file>" input <name>, dandori "<file>" input <name>, sekisho "<file>" resource <name> attribute <name> (or principal), sekisho "<file>" action <name> input <name>

A contract often leaves a bound to the code, which checks it by hand and then gives the value to a gate and to a workflow. The second can name the first: what comes from a place is what its own line writes. Two places that name each other say they take the same values, so whichever of the two moves, one of them stops.

ritsu check asks the language on each side, and comes to one of three answers:

  • It holds. The place takes everything the source can come to. A place wider than its source is fine.
  • E207. The source can come to a value the place refuses. The message gives the value, and the input that gives it when the source can say.
  • W207. It cannot be decided, and the message says why: rulec counts an end of a rule's output that none of the rule's vectors reaches, or a contract carries a date (a string, or a .proto's google.type.Date) and lists no days.

E208 says the source is not there: its file, or the name in it.

Numbers are compared in one unit and one step, and another unit does not hold. The values of two enums are the same when they share a name, as a file writes it or as its public name, since the code that carries one turns one spelling into the other; a date by its days, a bool or a string by its type alone. A string an OpenAPI document or a JSON Schema marks format: date-time is a moment, a day with a time of day: no date takes it, and a workflow's timestamp does, as it does another workflow's timestamp and a .proto's google.protobuf.Timestamp. A .proto's google.type.Date is a date, known by its name as dandori knows it. A field of a .proto that may be left unset (optional, in a oneof, or a message, unless a rule or proto2 marks it required) can come as no value, which a place that is not T? refuses. An end the place does not write is not compared. A contract with no upper or no lower bound lets through a value beyond what the place takes, as with a rule's from (E122), and does not hold. So does an account of a book with no at most, which goes as far as chobo's limit (2⁶³ − 1).

sakai counts a fed by as a reference, so one that crosses a boundary needs a relationship. Nothing generated changes, and neither does the meaning hash or a version yuen pins.

It does not check the code that carries the value. It says where the value should come from, and holds the range of its values; whether the hand-written code really carries that value, nothing checks. Each page for people says so where it shows the source.

Pages for people

The same files give pages, in English or Japanese, for the people who need to understand what the code is to carry out — those who run the business, finance and legal, operators, the developers reviewing the code — so they can read what was written and check it against what they know.

  • rulec doc — a rule's tables, provisos and what was proved of them, in Markdown or HTML;
  • dandori doc — a workflow drawn with every scenario it runs;
  • koyomi doc — a calendar, month by month;
  • chobo doc — a ledger, its bounds and its transfers;
  • sekisho doc — who may do what, action by action, beside the Cedar it compiles to;
  • kaname doc — a module: the decisions in its tables, its functions by their effects and where each can fail, and the decisions written in its code;
  • ringi doc — a request type: its form, who answers each stage and by when, and what a ticket does; ringi simulate says who answers a given person's request;
  • yuen trace — a requirement back to its source and on to what satisfies it.

Install

From source, with a recent stable Rust:

cargo install --git https://github.com/i2y/ritsu --locked ritsu

ritsu check <dir> runs every language's check, then the checks across them, and ritsu <language> … a language's own commands, as in ritsu rulec doc fee.rule. Every release, from 0.23.0 on (continuing rulec's numbering), carries archives for macOS and Linux and .deb and .rpm packages, on the releases page; an archive holds ritsu and a link to it named for each language, which runs as that language. With Homebrew it is brew install i2y/tap/ritsu, and in GitHub Actions uses: i2y/ritsu@v0.56.0. From 0.26.0, a release also carries the npm package @i2y/ritsu, ritsu built for WebAssembly, which Node runs with no native binary: ritsu in Node.

A project can require other modules, from a directory or from an OCI registry, and read their files by @<name>/… paths: Modules. ritsu gen writes a project's code as a package for each language. The comments of the code, and the text the code returns, are in the language of --lang, and in English without it; RITSU_LANG changes only the text the command prints. With --library, it writes a module as libraries that npm, PyPI and Go take, which import their dependencies' libraries by name: Publishing libraries.

ritsu impact says whether a change moved any answer and who it concerns, and a rule of your own says where the change goes: Where a change goes.

The design of the whole is in DESIGN.md, in Japanese. ritsu is MIT OR Apache-2.0.

For AI agents

ritsu and its languages are made to be used by AI agents, and the repository holds eleven Agent Skills for them: one for ritsu, for a project of more than one language, and one for each of the ten languages (skills/README.md lists them). There are four ways to install them:

  • Claude Code: this site publishes a plugin marketplace whose plugin ritsu holds the eleven. Run /plugin marketplace add https://i2y.github.io/ritsu/marketplace.json, then /plugin install ritsu@ritsu; Claude Code fetches the folder skills/ alone, not the whole repository.
  • Any agent, from the binary: ritsu skills install writes them into the project's .claude/skills/; with --user, into ~/.claude/skills/; with --dir <dir>, where another agent reads skills. Names after it (ritsu skills install rulec dandori) write only those, and ritsu skills list lists them.
  • By hand: copy the folders you need from skills/ into ~/.claude/skills/, or into a project's .claude/skills/.
  • From a release: ritsu-skills-v<version>.zip holds the eleven folders; unzip it where your agent reads skills.