mod: Phase 3 — lifecycle state machine + escalation + appeal, 106/106
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 54s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 54s
Pure SX state machine (lib/mod/lifecycle.sx) over the engine: open→triaged→decided→appealed→final, transition table guards illegal moves. Auto-tier resolves terminal actions; escalate parks at human-tier (resolve blocked until review supplies evidence). Appeal re-runs the engine — new exonerated-keep rule at top precedence lets exoneration override a prior hide. Api façade (mod/triage/resolve/review/appeal/finalize) over a case registry, logging committed decisions to the audit trail. +46 escalation tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
103
lib/mod/api.sx
103
lib/mod/api.sx
@@ -1,11 +1,13 @@
|
||||
;; lib/mod/api.sx — report registry + public entry points.
|
||||
;; lib/mod/api.sx — report registry + lifecycle façade + 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.
|
||||
;; mod/report files a report (assigning a sequential id) and opens a lifecycle
|
||||
;; case for it; mod/add-evidence accumulates evidence; mod/decide runs the engine
|
||||
;; and commits to the audit log. The lifecycle façade (mod/triage, mod/resolve,
|
||||
;; mod/review, mod/appeal, mod/finalize) drives the per-report case through its
|
||||
;; states, logging each committed decision to the audit trail.
|
||||
|
||||
(define mod/*reports* (list))
|
||||
(define mod/*cases* (list))
|
||||
(define mod/*counter* 0)
|
||||
(define mod/*rules* mod/default-rules)
|
||||
|
||||
@@ -15,6 +17,7 @@
|
||||
()
|
||||
(begin
|
||||
(set! mod/*reports* (list))
|
||||
(set! mod/*cases* (list))
|
||||
(set! mod/*counter* 0)
|
||||
(mod/audit-reset!))))
|
||||
|
||||
@@ -28,7 +31,10 @@
|
||||
((id (str "r" mod/*counter*)))
|
||||
(let
|
||||
((r (mod/mk-report id by about reason)))
|
||||
(begin (append! mod/*reports* r) r))))))
|
||||
(begin
|
||||
(append! mod/*reports* r)
|
||||
(append! mod/*cases* {:id id :case (mod/mk-case r)})
|
||||
r))))))
|
||||
|
||||
(define
|
||||
mod/get-report
|
||||
@@ -70,3 +76,88 @@
|
||||
(let
|
||||
((d (mod/decide-report r mod/*reports* mod/*rules*)))
|
||||
(begin (mod/log-decision! d (mod/report-evidence r)) d))))))
|
||||
|
||||
;; ── lifecycle façade over the case registry ──
|
||||
|
||||
(define
|
||||
mod/case-of
|
||||
(fn
|
||||
(id)
|
||||
(reduce
|
||||
(fn (acc rec) (if (= (get rec :id) id) (get rec :case) acc))
|
||||
nil
|
||||
mod/*cases*)))
|
||||
|
||||
(define
|
||||
mod/case-store!
|
||||
(fn
|
||||
(id c)
|
||||
(set!
|
||||
mod/*cases*
|
||||
(map
|
||||
(fn (rec) (if (= (get rec :id) id) {:id id :case c} rec))
|
||||
mod/*cases*))))
|
||||
|
||||
;; apply a lifecycle op to the stored case, persist it, and (when a decision was
|
||||
;; committed cleanly) append it to the audit log; returns the updated case
|
||||
(define
|
||||
mod/case-apply!
|
||||
(fn
|
||||
(id op log?)
|
||||
(let
|
||||
((c (mod/case-of id)))
|
||||
(if
|
||||
(nil? c)
|
||||
nil
|
||||
(let
|
||||
((c2 (op c)))
|
||||
(begin
|
||||
(mod/case-store! id c2)
|
||||
(when
|
||||
log?
|
||||
(when
|
||||
(nil? (mod/case-error c2))
|
||||
(let
|
||||
((d (mod/case-decision c2)))
|
||||
(if
|
||||
(nil? d)
|
||||
nil
|
||||
(mod/log-decision!
|
||||
d
|
||||
(mod/report-evidence (mod/case-report c2)))))))
|
||||
c2))))))
|
||||
|
||||
(define
|
||||
mod/triage
|
||||
(fn
|
||||
(id)
|
||||
(mod/case-apply!
|
||||
id
|
||||
(fn (c) (mod/case-triage c mod/*reports* mod/*rules*))
|
||||
false)))
|
||||
|
||||
(define
|
||||
mod/resolve
|
||||
(fn (id) (mod/case-apply! id (fn (c) (mod/case-resolve c)) true)))
|
||||
|
||||
(define
|
||||
mod/review
|
||||
(fn
|
||||
(id kind val)
|
||||
(mod/case-apply!
|
||||
id
|
||||
(fn (c) (mod/case-review c kind val mod/*reports* mod/*rules*))
|
||||
true)))
|
||||
|
||||
(define
|
||||
mod/appeal
|
||||
(fn
|
||||
(id kind val)
|
||||
(mod/case-apply!
|
||||
id
|
||||
(fn (c) (mod/case-appeal c kind val mod/*reports* mod/*rules*))
|
||||
true)))
|
||||
|
||||
(define
|
||||
mod/finalize
|
||||
(fn (id) (mod/case-apply! id (fn (c) (mod/case-finalize c)) false)))
|
||||
|
||||
Reference in New Issue
Block a user