4 Commits

Author SHA1 Message Date
John Dvorak 88f10f9db4 feat: evidence composition — compile-time reference resolution for evidence sub-rules
CI / publish (push) Successful in 11s
CI / test (push) Successful in 15s
An evidence may now reference another derived evidence as a sub-rule
(WHEN can_read(user, doc) where can_read is itself an evidence). Resolution
is a compile-time linker pass: after every evidence config is generated, each
direct reference to an evidence is inlined with that evidence's own (resolved)
config, so the engine evaluates a fully-resolved, acyclic config tree.

- resolveEvidenceReferences(): post-generation pass over evidence configs,
  recursing into logical/defeasible containers (when/unless/never/always/
  requires/union/intersection), always.direct nests, and comparator operands.
- Forward references resolve (all configs exist before the pass runs).
- Cycles and self-references are compile-time errors.
- _subjectAsObject scoping is preserved through inlining.
- dependsOn is recomputed after resolution, so partial-graph requirements
  reach transitively through composed evidence.
- buildDirectRule/buildPredicateRule now apply subject-scoping to top-level
  PredicateCall evidence bodies (latent gap, previously missed).
- validation: reject relation names shared across facts/sources/evidence/
  measures (a collision silently overwrote configs and read as a false cycle).

Tests: EvidenceComposition (9), DSLRuntime transitive requiredFacts, oracle
campaign composition construct, illegal-mutations cycle + cross-kind cases.
2026-08-03 11:17:30 -07:00
John Dvorak 0a744329e6 feat: fix lowering, DSLRuntime wrapper, rigor oracle + rejection campaigns
CI / publish (push) Successful in 10s
CI / test (push) Successful in 13s
Lowering fixes (validate/lower/compile into known-correct core structures):
- tuple_to_userset: structural classification by object-side predicate
  (owner(*g, doc) { member_of(user, g) } -> tuple_to_userset with direction
  'in'/'out'); the old heuristic routed every outer-wildcard to chain.
- relational_comparator: operands now lower to real direct-rule configs
  (evaluateFrom derived from evidence param positions; expectedValue for
  literal args) instead of raw AST nodes the engine could not evaluate.
- defeasible: multi-level bodies (NEVER/REQUIRES/ALWAYS/WHEN/UNLESS) merge
  into one five-level rule instead of ANDed level-only rules that always
  resolved 0; nested PatternMatches flatten to N-step chains; unary predicate
  calls mark _subjectAsObject (subject-as-object semantics).
- validation: reject duplicate fact/evidence definitions.

DSLRuntime (higher-order DSL+Core wrapper):
- typed addNode/updateNodeData/addRelation/updateRelation against the DSL
  schema (known types, relation params, field types, value-carrying facts);
- check() derives the evidence's injectable partial-graph requirements,
  retrieves missing facts through caller data callbacks, injects them, and
  delegates, returning requiredFacts/providedFacts/missingFacts.

js-rigor campaigns:
- generative oracle: generate legal DSL per construct and compare every
  verdict against an independent hand-computed oracle (8 constructs x P grid)
  plus an exhaustive deterministic sweep;
- illegal mutations: one-flaw perturbations of a valid program must be
  reliably rejected (duplicate evidence/fact, arity/type mismatches, reserved
  built-ins, malformed syntax), with a control that must compile.

Depends on @arbiter/core@^1.0.2 (reason codes + _subjectAsObject).
2026-08-03 10:58:29 -07:00
John Dvorak 0c2ddc282b test: fix legacy fixture suites against modern DSL validation
CI / test (push) Successful in 25s
CI / publish (push) Has been skipped
The legacy test files (Definition/Evidence/Expression/Fact/Integration/
Measure) predate the DSL's validation rules: reserved built-in types
(User/Account/Device/AuthSession) and the boolean/predicate-call
requirements on evidence statements. Fixed the fixtures, not the engine:

- reserved renames: User->Employee, Account->Tenant (Device/AuthSession
  were only legally referenced)
- expression fixtures: comparators now use predicate calls on both sides
  (fact score(value: number) + score(1 + 2 * 3) > score(0)); measure
  bodies carry the original arbitrary expressions (validated, not
  rule-generated)
- grammar-shape fixes: comma-separated fusion/aggregate lists, PROVIDES
  X (no array returns), predicate-call evidence statements

All 54 tests across the 8 files pass.
2026-08-03 09:12:20 -07:00
John Dvorak ae21605fb7 evidence-dsl: extract Evidence DSL v2 compiler from @arbiter/core
CI / test (push) Successful in 11s
CI / publish (push) Successful in 9s
The Evidence DSL (ADR-000) is a thin declarative layer that compiles to
engine rule types. It has zero runtime coupling to the core engine
(DSLCompiler takes an arbiter as a duck-typed argument; the only shared
code was the ip-utils helpers, now local). Extracting it into its own
package keeps the core artifact free of the DSL surface.

- @arbiter/evidence-dsl depends on @arbiter/core (config formats are the
  compilation target)
- deep-path exports for the compiler, parser, generator, validation,
  and built-in functions (the surface the core's DSL tests consume)
- tests moved alongside; generate-parser script + peggy devDep local
- CI: test on push, publish on v* tags
2026-08-03 08:48:39 -07:00