Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m7s
Reports carry an :evidence list, asserted as evidence/3 facts; reviewer-remove rule (highest precedence) lets human review override classification. Proof tree built constructively by re-querying each rule body goal against the same DB with the report id bound, so derivations carry real unification bindings. Append-only audit log records decision + proof + evidence snapshot per decide, monotonic seq, never mutates prior entries. +29 audit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
73 lines
1.7 KiB
Plaintext
73 lines
1.7 KiB
Plaintext
;; lib/mod/api.sx — report registry + public entry points.
|
|
;;
|
|
;; mod/report files a report (assigning a sequential id) into the in-memory
|
|
;; registry; mod/add-evidence accumulates evidence onto a filed report;
|
|
;; mod/decide resolves an id, runs the policy engine against the current registry
|
|
;; and rule set, and commits the decision to the append-only audit log.
|
|
|
|
(define mod/*reports* (list))
|
|
(define mod/*counter* 0)
|
|
(define mod/*rules* mod/default-rules)
|
|
|
|
(define
|
|
mod/reset!
|
|
(fn
|
|
()
|
|
(begin
|
|
(set! mod/*reports* (list))
|
|
(set! mod/*counter* 0)
|
|
(mod/audit-reset!))))
|
|
|
|
(define
|
|
mod/report
|
|
(fn
|
|
(by about reason)
|
|
(begin
|
|
(set! mod/*counter* (+ mod/*counter* 1))
|
|
(let
|
|
((id (str "r" mod/*counter*)))
|
|
(let
|
|
((r (mod/mk-report id by about reason)))
|
|
(begin (append! mod/*reports* r) r))))))
|
|
|
|
(define
|
|
mod/get-report
|
|
(fn
|
|
(id)
|
|
(reduce
|
|
(fn (acc r) (if (= (mod/report-id r) id) r acc))
|
|
nil
|
|
mod/*reports*)))
|
|
|
|
(define
|
|
mod/add-evidence
|
|
(fn
|
|
(id kind val)
|
|
(let
|
|
((r (mod/get-report id)))
|
|
(if
|
|
(nil? r)
|
|
nil
|
|
(let
|
|
((updated (mod/attach-evidence r (mod/mk-evidence kind val))))
|
|
(begin
|
|
(set!
|
|
mod/*reports*
|
|
(map
|
|
(fn (x) (if (= (mod/report-id x) id) updated x))
|
|
mod/*reports*))
|
|
updated))))))
|
|
|
|
(define
|
|
mod/decide
|
|
(fn
|
|
(id)
|
|
(let
|
|
((r (mod/get-report id)))
|
|
(if
|
|
(nil? r)
|
|
nil
|
|
(let
|
|
((d (mod/decide-report r mod/*reports* mod/*rules*)))
|
|
(begin (mod/log-decision! d (mod/report-evidence r)) d))))))
|