Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upstream update from clara-rules 0.24.0 #496

Closed
wants to merge 89 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
afd749a
feat: initial commit removing cljs support and converting over to deps
k13gomez Dec 27, 2023
36d4283
chore: remove old project.clj file
k13gomez Dec 27, 2023
0c1ea12
fix: ensure buidl runs, add linter support
k13gomez Dec 27, 2023
fcff5c7
feat: ensure clean build deploy
k13gomez Dec 27, 2023
2478d16
fix: build add clojure and corretto jvm
k13gomez Dec 27, 2023
ec822d3
feat: use clojure
k13gomez Dec 27, 2023
5f8d726
feat: cleanup
k13gomez Dec 27, 2023
83306cb
feat: add pom file
k13gomez Dec 27, 2023
04ecb7a
chore: update ignore file
k13gomez Dec 27, 2023
c2986af
feat: dont delete pom
k13gomez Dec 27, 2023
892bf79
feat: make minor enhancements to cancelling cache
k13gomez Dec 27, 2023
c6e1dbe
feat: implement update cache using ham fisted mut list
k13gomez Dec 27, 2023
3a79d0a
feat: simply multiple equality wrappers into mostly single JEQ wrapper
k13gomez Dec 27, 2023
84b48ff
chore: formatting
k13gomez Dec 27, 2023
32192b0
feat: progress converting memory to mutable map/coll, add kaocha script
k13gomez Dec 28, 2023
8fa2b85
feat: remove unnecessary mutable flags and set statements
k13gomez Dec 28, 2023
1798006
feat: refactor elements and token fns using mutable map compute
k13gomez Dec 28, 2023
5f94ae0
chore: formatting and cleanup
k13gomez Dec 28, 2023
83fa452
feat: map persistent accum memory using compute
k13gomez Dec 28, 2023
281eef7
fix: lint deps
k13gomez Dec 28, 2023
fed0df7
fix: compute if present for remove accum
k13gomez Dec 28, 2023
9d0f22b
feat: update transient production memory ops using mutable ops
k13gomez Dec 28, 2023
67e0e57
feat: accum simplify using persistent strucs for results
k13gomez Dec 28, 2023
37eaa07
feat: memory tweaks to initialize nodes as persistent colls
k13gomez Dec 28, 2023
ac03512
feat: enhance compilter with hamf collections and update serialization
k13gomez Dec 29, 2023
1b3db0d
feat: add parallel processing support to various node types
k13gomez Dec 30, 2023
77f3174
feat: initial pass at poppping multiple activations for parallelization
k13gomez Dec 30, 2023
8abaa78
feat: first cut of parallel compute rhs activations
k13gomez Dec 30, 2023
c03f6f0
feat: add support for async rhs productions
k13gomez Dec 31, 2023
05fa0c0
chore: lint produce-try macro
k13gomez Dec 31, 2023
34f643d
feat: update pom
k13gomez Dec 31, 2023
cf3f864
feat: update docs
k13gomez Dec 31, 2023
f1b6ab6
fix: use correct build status url
k13gomez Jan 1, 2024
2090874
feat: update platform async patterns using futurama, prepare for release
k13gomez Jan 2, 2024
823512f
chore: update pom deps
k13gomez Jan 2, 2024
3ab4626
feat: async enhancements, add async tests
k13gomez Jan 2, 2024
3df55fe
chore: cleanup comments
k13gomez Jan 2, 2024
8463bd4
feat: add explicit async methods
k13gomez Jan 6, 2024
7f9e53b
feat: refactor fire rules into two separate async and sync handlers
k13gomez Jan 7, 2024
d74b0b9
WIP
k13gomez Jan 7, 2024
40b3e88
feat: refactor bound session and fire rules fns
k13gomez Jan 7, 2024
8f6770b
feat: disable rule order tests when doing parallel testing
k13gomez Jan 7, 2024
ac03bde
feat: update changelog and pom file for release
k13gomez Jan 7, 2024
a36ae24
feat: bump futurama to 0.3.8
k13gomez Jan 7, 2024
7be6dea
feat: add YourKit to README
k13gomez Jan 7, 2024
7645ec8
feat: bump futurama to 0.3.9
k13gomez Jan 7, 2024
302f99c
feat: add a built-in way to interrupt running session during rules
k13gomez Jan 8, 2024
c1faf0c
chore: release 0.9.3
k13gomez Jan 8, 2024
9afec6a
feat: update futurama lib version
k13gomez Jan 8, 2024
9cf439c
feat: update docs, explicit use async future for fire-rules-async
k13gomez Jan 9, 2024
1db3fbb
feat: async enhancements and add engine test with 10k async rules fired
k13gomez Jan 10, 2024
191c7b8
feat: update to latest async lib
k13gomez Jan 11, 2024
0db7edc
feat: update deps and format clj-kondo
k13gomez Jan 25, 2024
b45a54f
chore: update deps
k13gomez Jan 25, 2024
30f4c6c
feat: update pom deps
k13gomez Jan 25, 2024
f7db812
chore: fix futurama version in pom
k13gomez Jan 25, 2024
af3d083
feat: bump deps for release 1.0.0
k13gomez Feb 12, 2024
810b894
feat: initial major release 1.0.0
k13gomez Feb 12, 2024
98c7628
feat: bump futurama to latest version 1.0.1
k13gomez Feb 12, 2024
f3166f2
feat: release 1.0.2 with latest futurama version
k13gomez Feb 17, 2024
4bcea93
feat: implement custom caching support using core CacheProtocol
k13gomez Feb 19, 2024
58dc178
feat: update deps and change log and prepare for release 1.1.0
k13gomez Feb 19, 2024
d859436
feat: add support for a compiler cache which can cache exprs eval'd
k13gomez Feb 19, 2024
1e0c118
feat: don't include node id on compiled fns
k13gomez Feb 19, 2024
77f32e0
chore: set next dev version 1.2.0-SNAPSHOT
k13gomez Feb 19, 2024
2ea09cc
chore: update changelog and docs
k13gomez Feb 19, 2024
7b14dd7
feat: release 1.2.0
k13gomez Feb 19, 2024
eab3bcc
feat: enhancements of compiler hotspots using ham fisted mutables
k13gomez Feb 21, 2024
dfeee4e
feat: compiler class loading enhancements
k13gomez Feb 21, 2024
4ea3e1c
feat: prepare for release 1.3.0
k13gomez Feb 21, 2024
cf05a64
feat: update user ns
k13gomez Feb 21, 2024
0b40d90
feat: enhance caching performance by more predictable md5 caching and…
k13gomez Feb 22, 2024
e01304f
feat: enhance memory add-activations implementation by replacing get/…
k13gomez Feb 26, 2024
7506c0e
chore: remove deprecated either schema usage from compiler ns
k13gomez Feb 27, 2024
741707f
feat: extract way to build the production without adding to beta network
k13gomez Feb 27, 2024
a106cf1
feat: some more progress to support functions that are rules
k13gomez Feb 27, 2024
587a360
feat: change handler declaration to var, add var serde, add load sources
k13gomez Feb 27, 2024
271fa4f
chore: add useful user ns scribles
k13gomez Feb 27, 2024
a01d840
chore: run CI on all branches
k13gomez Feb 27, 2024
f897ad2
chore: minor enhancements for rule loading
k13gomez Feb 27, 2024
8d6ee9a
chore: prepare for snapshot release 1.4.0-SNAPSHOT
k13gomez Feb 27, 2024
07e0892
feat: store handler as symbol instead of var
k13gomez Feb 27, 2024
b27dc9e
feat: add coverage test to verify coverage works
k13gomez Feb 29, 2024
4b77d75
feat: upgrade clojure to 1.11.2 and fix clj-kondo linter
k13gomez Mar 8, 2024
bee29ff
feat: linter fixes
k13gomez Mar 10, 2024
b92f791
feat: implement hierarchy loaders, fact loaders, update deps (#2)
k13gomez Mar 10, 2024
364fa0f
chore: update deps
k13gomez Mar 11, 2024
0854469
Merge branch '1.3.3-hotfix'
k13gomez Mar 11, 2024
0d6a8ae
Merge remote-tracking branch 'upstream/main'
k13gomez May 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,34 @@ name: Clojure CI

on:
push:
branches: [ "main" ]
branches: "*"
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Java JDK
uses: actions/[email protected]
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
# The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28
java-version: 1.8
- name: Setup Node.js environment
uses: actions/[email protected]
# see: https://github.com/marketplace/actions/setup-java
distribution: 'corretto'
java-version: '11'
- name: Install clojure tools
uses: DeLaGuardo/[email protected]
with:
# Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0
node-version: 18.16.0
- name: Install Puppeteer
run: npm install puppeteer
- name: Install Chrome
run: npx puppeteer browsers install chrome
- name: Install dependencies
run: lein deps
# see: https://github.com/marketplace/actions/setup-clojure
cli: 1.11.1.1429
- name: Run tests
run: lein test
run: make test
- name: Run coverage tests
run: make test-coverage
- name: Run generative tests
run: lein test :generative
- name: Run recent-clj tests
run: lein with-profile dev,recent-clj test
run: make test-generative
- name: Run clj-kondo linter
run: lein with-profile dev,recent-clj clj-kondo-lint
run: make lint
- name: Run build jar
run: make clean build
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/build
/target
/lib
/classes
/checkouts
/resources/public/js/*
pom.xml
pom.xml.asc
*.jar
*.class
Expand All @@ -17,4 +17,5 @@ figwheel_server.log
*.iml
.clj-kondo
.lsp
node_modules/*
.cpcache
node_modules/*
76 changes: 74 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,79 @@
This is a history of changes to clara-rules.
This is a history of changes to k13labs/clara-rules.

# 0.25.0-SNAPSHOT
# 1.4.0-SNAPSHOT
* update linter config for new macros.
* `defrule` now defines rules as functions with two arities, no args returns the rule map, and 2 args is the compiled RHS.
* `clojure.lang.Fn` now implements `clara.rules.compiler/IRuleSource`, and returns a single rule by invoking the like `(a-rule)`.
* add built-in support to serialize `clojure.lang.Var` so that a rule handler var can be serialized correctly.
* add function `clara.rules.compiler/load-rules-from-source` to simplify loading rules
* add `defhierarchy` macro to define hierarchies of facts allowing to easily establish parent/child relationships.
* add `defdata` macro to define facts and collections of facts in namespaces allowing to easily embed and insert them during mk-session.
* rename `clear-ns-productions!` to `clear-ns-vars!` since now there are ns-installed vars that are not productions.

# 1.3.3
* Upgrade to clojure 1.11.2 to fix `CVE-2024-22871`, despite not really affecting clara-rules.
* Add clj-kondo linter updates to fix bad docstring expression.

# 1.3.2
* Enhance memory add-activations implementation by replacing get/set with compute!

# 1.3.1
* Enhance caching performance by more predictable md5 caching and sorting productions

# 1.3.0
* Enhance compilation performance by using mutable maps from ham-fisted lib

# 1.2.0
* Enhance caching support by adding compile caching using core CacheProtocol

# 1.1.0
* Enhance caching support by adding session caching using core CacheProtocol

# 1.0.2
* Bump futurama version to 1.0.2 to get enhancements

# 1.0.1
* Bump futurama version to 1.0.1 to get enhancements

# 1.0.0
* Bump futurama version to first major version
* Initial major release of k13labs/clara-rules

# 0.9.9
* Bump futurama version to latest

# 0.9.8
* Update to latest async library (futurama) to get fixes for async-reduce

# 0.9.7
* Update to latest async library

# 0.9.6
* Async enhancements and add engine test with thousands of async rules fired for stress test

# 0.9.5
* Update docs and explicit async-future in fire-rules-async

# 0.9.4
* Update `futurama` to latest version

# 0.9.3
* Implement interruptible sessions using futurama's async-cancel capabilities.
* Add tests for infinite loop runaway sessions which can be interrupted.

# 0.9.2
* Update docs and futurama version bump again

# 0.9.1
* Update docs and futurama version bump

# 0.9.0
* Add parallel support to Node and RHS activation.
* Remove ClojureScript support, general cleanup.
* Refactor engine to support both fire-rules and fire-rules-async
* Replace mutable/transient collections with [ham-fisted](https://github.com/cnuernber/ham-fisted) data structures.

This is a history of changes to clara-rules prior to forking to k13labs/clara-rules.

### 0.24.0
* uplift to cljs 1.11.132
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Thanks.
* Open a [pull request][7].
* The pull request will be reviewed by the community and merged by the project committers.

[1]: https://github.com/cerner/clara-rules/issues
[1]: https://github.com/k13labs/clara-rules/issues
[2]: http://gun.io/blog/how-to-github-fork-branch-and-pull-request
[3]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[4]: ./CHANGELOG.md
[5]: ./LICENSE
[6]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
[7]: https://help.github.com/articles/using-pull-requests
[7]: https://help.github.com/articles/using-pull-requests
5 changes: 1 addition & 4 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
Cerner Corporation
Clara Rules Contributors

- Ryan Brush [@rbrush]
- Mike Rodriguez [@mrrodriguez]
- William Parker [@WilliamParker]
- Ethan Christian [@EthanEChristian]
- Pushkar Kulkarni [@kulkarnipushkar]

Community

- David Goeke [@dgoeke]
- Dave Dixon [@sparkofreason]
- Baptiste Fontaine [@bfontaine]
Expand Down
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.PHONY: repl test clean compile-main-java compile-test-java deploy install format-check format-fix

SHELL := /bin/bash

compile-main-java:
clojure -T:build compile-main-java

compile-test-java: compile-main-java
clojure -T:build compile-test-java

repl: compile-test-java
clojure -M:dev:test:repl

test: compile-test-java
clojure -M:dev:test:runner --focus :unit --reporter kaocha.report/documentation --no-capture-output

test-coverage: compile-test-java
clojure -M:dev:test:runner --focus :coverage --reporter kaocha.report/documentation --no-capture-output
jq '.coverage["clara/coverage_ruleset.clj"]|join("_")' target/coverage/codecov.json | grep "_1___1____1_0_1__1__" || echo "Unexpected coverage output for clara.coverage-ruleset." exit 1

test-generative: compile-test-java
clojure -M:dev:test:runner --focus :generative --reporter kaocha.report/documentation --no-capture-output

test-config:
clojure -M:dev:test:runner --print-config

clean:
rm -rf target build

lint: compile-test-java
clojure -M:dev:test:clj-kondo --copy-configs --dependencies --parallel --lint "$(shell clojure -A:dev:test -Spath)"
clojure -M:dev:test:clj-kondo --lint "src/main:src/test" --fail-level "error"

build: compile-main-java
clojure -X:jar :sync-pom true

deploy: clean build
clojure -X:deploy-maven

install:
clojure -X:install-maven

format-check:
clojure -M:format-check

format-fix:
clojure -M:format-fix
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2016 Cerner Innovation, Inc.
Copyright 2023 Jose Gomez

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
47 changes: 32 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
[![Build Status](https://github.com/cerner/clara-rules/actions/workflows/clojure.yml/badge.svg)](https://github.com/cerner/clara-rules/actions/workflows/clojure.yml)
[![Build Status](https://github.com/k13labs/clara-rules/actions/workflows/clojure.yml/badge.svg)](https://github.com/k13labs/clara-rules/actions/workflows/clojure.yml)

# _About_

Clara is a forward-chaining rules engine written in Clojure(Script) with Java interoperability. It aims to simplify code with a developer-centric approach to expert systems. See [clara-rules.org](http://www.clara-rules.org) for more.

NOTE: this fork only supports the JVM/Clojure, and not ClojureScript.

# _Usage_

Here's a simple example. Complete documentation is at [clara-rules.org](http://www.clara-rules.org/docs/firststeps/).

```clj
(ns clara.support-example
(:require [clara.rules :refer :all]))
(:require [clara.rules :refer :all]
[futurama.core :refer [!<!!]))

(defrecord SupportRequest [client level])

Expand All @@ -29,12 +32,20 @@ Here's a simple example. Complete documentation is at [clara-rules.org](http://w
=>
(println "Notify" ?name "that" ?client "has a new support request!"))

;; Run the rules! We can just use Clojure's threading macro to wire things up.
;; We can just use Clojure's threading macro to wire things up below.

;; Run the rules!
(-> (mk-session)
(insert (->ClientRepresentative "Alice" "Acme")
(->SupportRequest "Acme" :high))
(fire-rules))

;; Run the rules asynchronously!
(!<!! (-> (mk-session)
(insert (->ClientRepresentative "Alice" "Acme")
(->SupportRequest "Acme" :high))
(fire-rules-async {:parallel-batch-size 50})))

;;;; Prints this:

;; High support requested!
Expand All @@ -43,35 +54,41 @@ Here's a simple example. Complete documentation is at [clara-rules.org](http://w

# _Building_

Clara is built, tested, and deployed using [Leiningen](http://leiningen.org).
ClojureScript tests are executed via [puppeteer](https://pptr.dev/).
```
npm install -g puppeteer
npx puppeteer browsers install chrome
```
Clara is built, tested, and deployed using [Clojure Tools Deps](https://clojure.org/guides/deps_and_cli).

GNU Make is used to simplify invocation of some commands.

# _Availability_

Clara releases are on [Clojars](https://clojars.org/). Simply add the following to your project:
Clara releases for this project are on [Clojars](https://clojars.org/). Simply add the following to your project:

[![Clojars Project](http://clojars.org/com.cerner/clara-rules/latest-version.svg)](http://clojars.org/com.cerner/clara-rules)
[![Clojars Project](http://clojars.org/com.github.k13labs/clara-rules/latest-version.svg)](http://clojars.org/com.github.k13labs/clara-rules)

# _Communication_

Questions can be posted to the [Clara Rules Google Group](https://groups.google.com/forum/?hl=en#!forum/clara-rules) or the [Slack channel](https://clojurians.slack.com/messages/clara/).
- Questions about Clara rules can be posted to the [Clara Rules Google Group](https://groups.google.com/forum/?hl=en#!forum/clara-rules) or the [Slack channel](https://clojurians.slack.com/messages/clara/).
- For any other questions or issues about this Clara rules fork specifically feel free to browse or open a [Github Issue](https://github.com/k13labs/clara-rules/issues).

# Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)

# YourKit

[![YourKit](https://www.yourkit.com/images/yklogo.png)](https://www.yourkit.com/)

YourKit supports open source projects with innovative and intelligent tools
for monitoring and profiling Java and .NET applications.
YourKit is the creator of [YourKit Java Profiler](https://www.yourkit.com/java/profiler/),
[YourKit .NET Profiler](https://www.yourkit.com/dotnet-profiler/),
and [YourKit YouMonitor](https://www.yourkit.com/youmonitor/).

# LICENSE

Copyright 2018 Cerner Innovation, Inc.
Copyright 2023 Jose Gomez

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

&nbsp;&nbsp;&nbsp;&nbsp;http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


23 changes: 10 additions & 13 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ This project is hosted on [Clojars][clojars]. You can see it [here][release-sit

Releasing the project requires these steps:

0. Assert all tests are passing and the project builds : `lein do clean, test`
1. Make sure CHANGELOG.md is up-to-date for the upcoming release.
2. Assert you have Github setup with [gpg](https://docs.github.com/en/authentication/managing-commit-signature-verification/adding-a-gpg-key-to-your-github-account)
3. Add gpg key to [sign](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work) your commits
* GPG will likely require an additional export to spawn an interactive prompt for signing:
```export GPG_TTY=$(tty)```
4. Create a [Clojars][clojars] Account and [Deploy Token](https://github.com/clojars/clojars-web/wiki/Deploy-Tokens) if you do not already have one.
5. Create a lein [credentials](https://leiningen.org/deploy.html#gpg) file using the account and token above.
6. Run `lein release <release-type>`, where release-type is one of `:patch`,`:minor` and `:major`
7. Push the new main branch to the repo.
8. Push the new tag to the repo.
1. Run ```make test``` to ensure everything is working as expected.
2. Set the version number and tag in the `pom.xml` file, commit the changes.
3. Use a GitHub [project release][github-release-url] to release the project and tag (be sure it follows [semver][semantic-versioning])
4. Run ```make clean build``` to test building the project, commit any changes to the `pom.xml` file.
5. Run ```make deploy``` to deploy the project to the Clojars repository.
6. Update the `pom.xml` in `main` to a new minor version, commit the changes.

[clojars]: https://clojars.org
[release-site]: https://clojars.org/com.cerner/clara-rules

[release-site]: https://clojars.org/com.github.k13labs/clara-rules
[project-url]: https://github.com/k13labs/clara-rules/
[semantic-versioning]: http://semver.org/
[github-release-url]: https://help.github.com/articles/creating-releases/
2 changes: 2 additions & 0 deletions bin/kaocha
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
clojure -M:dev:test:runner $@
5 changes: 4 additions & 1 deletion clj-kondo/clj-kondo.exports/clara/rules/config.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{:lint-as {clara.rules/defsession clojure.core/def
clara.rules.platform/eager-for clojure.core/for}
clara.rules/defhierarchy clojure.core/def
clara.rules/defdata clojure.core/def
clara.rules.platform/eager-for clojure.core/for
clara.rules.platform/compute-for clojure.core/for}
:hooks {:analyze-call {clara.rules/defquery hooks.clara-rules/analyze-defquery-macro
clara.rules/defrule hooks.clara-rules/analyze-defrule-macro
clara.rules.dsl/parse-query hooks.clara-rules/analyze-parse-query-macro
Expand Down
Loading