Home /Modules/moral-capacitor/SLMoralLedger.sleela

SLMoralLedger.sleela

lib/moral-capacitor/SLMoralLedger.sleela · 92 line(s) · sleela

<< lib/moral-capacitor/SLMoralLedger.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLMoralLedger — an append-only audit record of the
     verdicts a Moral Capacitor(TM) has returned. Each entry names the operation
     judged, the decision (PERMIT / DEFER / DENY), the charge versus threshold,
     and the reason, so a library can prove after the fact what was asked and how
     it was decided. The ledger keeps running counts of each decision for a
     quick posture summary.
   
   The record is a newline-separated String (the same bounded, enumerable form
   the rest of the library favours); a caller can print it or persist it.
   
   Family: moral-capacitor. Written by SLMoralCapacitor / the adapters. >>
#sleela 2.5
material;
class SLMoralLedger {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10915;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-10";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  < newline-separated verdict summaries >
  String entries;
  int total;
  int permits;
  int defers;
  int denials;
  int configured;

  void configure() {
    entries = ""; total = 0; permits = 0; defers = 0; denials = 0; configured = 1;
  }

  < Append a verdict for an operation. >
  void record(SLMoralOperation op, SLMoralVerdict v) {
    String line = op.identity() + " -> " + v.summary();
    if (entries == "") { entries = line; } else { entries = entries + "\n" + line; }
    total = total + 1;
    if (v.permitted())    { permits = permits + 1; }
    else if (v.deferred()){ defers = defers + 1; }
    else                  { denials = denials + 1; }
  }

  String log()        { return entries; }
  int recordCount()   { return total; }
  int permitCount()   { return permits; }
  int deferCount()    { return defers; }
  int denyCount()     { return denials; }

  String summary() {
    return intToStr(total) + " decisions: " + intToStr(permits) + " permit, "
         + intToStr(defers) + " defer, " + intToStr(denials) + " deny";
  }
  String intToStr(int v) { return "" + v; }
}