Build and contribute
rego4k builds with Gradle and JDK 21. The first release will publish the modules to Maven Central in the group
dev.rego4k.
The parser uses parser4k
The parser uses parser4k combinators, not a parser generator such as ANTLR. The grammar is Kotlin code that we can read, debug and step through.
If parser4k does not have a feature that we need, we add the feature to parser4k and do not work around the gap.
The file system shows the domain
A reader must see the concepts of rego4k from the names of its files and packages, before they read a line of code.
ast/,ast/term/andast/exprkind/have one file for each AST class. Each class has KDoc with Rego examples and the AST that each example gives.parser/has the same structure asast/: the parser for an AST class is in the file with the same name.compiler/has the parts of the compiler:compiled/: its output;resolution/: names, with the same structure as the AST;safety/: the order of the expressions in a body.
evaluator/has one file for each part of the evaluator: bodies, terms, documents, rules, calls and unification.
The code must be obviously correct
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies." — C. A. R. Hoare
Much of rego4k was written by coding agents. This rule applies to them as much as to people.
The build enforces part of it:
- The compiler treats all warnings as errors.
verification/unused-codereads the bytecode of the whole build. It fails the build if a declaration has no use in main code, tests or the benchmark. The Kotlin compiler does not report such declarations.- A refactor of the parser or the compiler must give the same results as the old code. We compare the two on thousands of inputs, and include inputs that fail.
Prose (KDoc, comments, Markdown, commit messages) is in Simplified Technical English. See AGENTS.md.
Build
./gradlew check # the tests (with the conformance suite), the warnings, and the unused-code check
./gradlew bench # the benchmark; then build/bench/report.html
./gradlew benchGate # the benchmark thresholds on every 10th case (about 6 minutes)
./gradlew pitest # the mutation testing (slow); -Pmutate=rego4k.values.* for one packageThe build needs JDK 21. settings.gradle.kts finds the modules: each directory with a build.gradle.kts is a
module.
The convention plugins in gradle/plugins hold all the configuration that two or more modules share. Thus most
module build files hold only dependencies. Configuration that only one module needs is in the build file of that
module.
just
The justfile at the root holds the commands that we use most. Install just,
for example with brew install just, and run just to see the list. Each recipe runs ./gradlew and needs only
JDK 21.
just demo # the demo server with 5 policies and their examples: http://localhost:8181
just demo-image # the image of the demo for Heroku, with Jib
just demo-debugger # the debugger with its example policy, in your browser
just server ./bundle # rego4k run --server on a bundle, with the debugger and without signed decisions
just lsp # install the language server, and print the path of its start script
just cli # build rego4k's command line, and print the path of its start script
just test-rego ./policies # the Rego tests of the policies, as `opa test ./policies` runs them
just check # ./gradlew check
just fuzz # the fuzz gate; it downloads opa if .bench-tools has none
just bench # the benchmarkPublishing
Nothing is on Maven Central yet. The first release will put the modules there.
Coordinates. Each module in modules has the coordinates dev.rego4k:rego4k-<module>:<version>. The demo
(demo/) is an application, not a library, so it is not published.
gradle.properties holds the group (group) and the version (version). The group is the domain rego4k.dev,
in reverse order.
A module publishes these files:
- its jar;
- a sources jar;
- an empty Javadoc jar. Maven Central accepts an empty Javadoc jar;
- a POM;
- the Gradle module metadata.
The BOM rego4k-bom names each module. The convention plugin published makes the
publications.
To make the artifacts in a local Maven repository, run this command:
./gradlew publishToMavenLocal -Dmaven.repo.local=/path/to/repositorySigning. The build signs the publications only if the Gradle property signingInMemoryKey is set. The value is
an ASCII-armored PGP secret key. signingInMemoryKeyPassword is the password of the key.
A CI job gives them as the environment variables ORG_GRADLE_PROJECT_signingInMemoryKey and
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword. Without a key, the build does not sign.
The upload to the Central Portal
The Gradle plugin nmcp uploads the modules to the Central Portal
(central.sonatype.com) with its Publisher API. published applies com.gradleup.nmcp to each module and to the BOM.
The BOM applies com.gradleup.nmcp.aggregation. It collects the BOM and each module that it names into one
deployment:
./gradlew :bom:nmcpZipAggregationwrites the deployment tonmcp/zip/aggregation.zipin the build directory of the BOM. It does not upload it../gradlew :bom:nmcpPublishAggregationToCentralPortaluploads the deployment. It reads the user token of the Portal from the environment variablesMAVEN_CENTRAL_USERNAMEandMAVEN_CENTRAL_PASSWORD. The other tasks need no token.
The Portal validates the deployment, but it does not publish it (USER_MANAGED). A person examines the
deployment in the Portal and publishes it. If nobody publishes a deployment, a person can drop it in the Portal.
The version of a release
Each release has a tag v<major>.<minor>.<patch>, for example v0.1.0. The workflow release finds the highest
tag and increments the part that you choose: patch, minor or major. Without a tag, the first release is 0.1.0.
The build gets the version on the command line, for example -Pversion=0.1.0. The other builds use
0.1.0-SNAPSHOT from gradle.properties, and nobody changes it after a release.
Release
The workflow release (.github/workflows/release.yml) runs only by hand, on main. It runs
./gradlew check fuzzGate. Then it builds, signs and uploads the modules with the new version. If the upload succeeds,
it pushes the tag of the version.
It needs these secrets of the repository:
MAVEN_CENTRAL_USERNAMEandMAVEN_CENTRAL_PASSWORD: a user token of the Central Portal.SIGNING_KEY: the ASCII-armored PGP secret key. Its public key is onkeys.openpgp.org, because Maven Central verifies the signatures with it.SIGNING_KEY_PASSWORD: the password of the key.
If a secret is missing, the job fails before the checks. To release, do these steps:
- In GitHub, open Actions > release > Run workflow. Choose
patch,minorormajor, and click "Run workflow". - Wait for the workflow
release. The upload task waits until the Portal validates the deployment. The summary of the run gives the version. - In the Central Portal, open "Publish" (the deployments). Examine the files and the checks of the new deployment.
- Click "Publish". The files are on Maven Central after approximately 10 to 30 minutes.
- Change the text that says that nothing is on Maven Central:
site/content/home/release.md, "Get started" in the rootREADME.md,modules/bom/README.mdand the start of this section. Give the real version. Do this only after the first release.
If you drop a deployment in the Portal, its tag stays. The next release then increments that tag.
Licence
rego4k is under the Apache License, Version 2.0. See LICENSE.
Ideas to specify
These ideas are not designed yet. They are not part of the current work. The next step for each is a specification.
Lazy input and data, with a record of the reads
The idea. Define an InputSource<T>, similar to a JSON converter of Kondor. A property of the source names a
property of the input. The source reads the value from a Kotlin object only when the policy reads it.
An InputSource is a special kind of Value. rego4k records each path into an InputSource that an evaluation
actually reads.
The record is the base for a dirty check of a decision, as in a signals library such as alien-signals. A decision must be evaluated again only when a value that the policy actually read changes, not when any value in the scope of the input changes.
Questions to answer first:
- how the record works with the rule cache,
with, the rule index and builtins that read a whole value (for examplejson.marshalorwalk); - how the record works with data as well as input.
The language server over a WebSocket, for an editor in the browser
Now. The language server runs only on the standard input and output, because a desktop editor starts it as a process.
The idea. An editor in the browser, for example Monaco (the editor of VS Code), cannot start a process. It connects to a language server over a WebSocket, and lsp4j has a module for this.
A WebSocket route in the server would give the debugger's editor completion, go-to-definition and diagnostics, with the same server as VS Code or IntelliJ.
Questions to answer first:
- whether the server module or the debugger owns the route;
- how the server limits the number of sessions and their memory;
- how a session sees the files of a bundle;
- whether the editor in the debugger stays a plain text area.