PR P: Pluggable Rules Engine (JSON DSL) #20
Reference in New Issue
Block a user
Delete Branch "devin/1776882394-pr-p-rules-engine"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes gap-analysis v2 §5.2 partial — the arch §5.2 Rules Engine was marked "partial (hardcoded rules)".
What
New:
services/rulesEngine.ts— declarative JSON DSL for business-rule evaluation.Operators
eq·neq·gt·gte·lt·lte·in·not_in·exists·matches(regex) ·length_gte·length_lteCombinators
{all: [...]}·{any: [...]}·{not: ...}Rule shape
when(optional) — gates the rule; when false, the rule is skipped.assert— condition the rule requires to hold.severity: "warn"reports but does not block (ok: true).Safety
false, bad regex returnsfalse.Built-ins
preconditions.builtin— arch §8 PRECONDITIONS_PENDING → READY_FOR_PREPARE (plan exists, ≥1 step, pay step present, ≥1 participant, KYC=ok when compliance present).commit.builtin— arch §9.2 (DLT 0x+64-hex tx hash, bank ISO message id present, state=VALIDATING, exceptions.active empty).Pluggability
RULES_FILE=/path/to/rules.json— JSON map{ruleSetId: RuleSet}overriding built-ins by id. Silent fall-through to built-ins on load failure (matches the existingservices/hsm.tsdev-friendly pattern).Verification
npx tsc --noEmitclean.npx jest96/96 green.whengating, severity semantics, built-in rule sets, loader behaviour, empty-ruleset fallback for unknown ids.Follow-ups (intentionally out-of-scope)
Closes gap-analysis v2 §5.2 partial (Rules Engine was hardcoded). - services/rulesEngine.ts — declarative JSON DSL with a closed operator set (eq/neq/gt/gte/lt/lte/in/not_in/exists/matches/ length_gte/length_lte) + AND/OR/NOT combinators. No eval, no runtime code injection. Dotted + indexed path resolver. - evaluate(ruleSet, context) returns {ok, failures}; 'error' severity blocks, 'warn' is reported but non-blocking. 'when' clauses gate a rule (e.g. only check compliance.kyc if the compliance block is present at all). - Built-in rule sets mirror the pre-DSL hardcoded checks: preconditions.builtin — plan + pay step + participants + KYC commit.builtin — dlt tx hash + bank iso msg id + state=VALIDATING + no exceptions (arch §9.2) - Pluggable: RULES_FILE env points at a JSON map overriding any built-in by id. Silent fall-through to built-ins on error. - 16 unit tests across operators, combinators, severity semantics, 'when' gating, built-in rule sets, and loader behaviour. - Full suite 96/96 green; tsc --noEmit clean.