Home /Modules/observer/SLObserverGuardModule.sleela

SLObserverGuardModule.sleela

lib/observer/SLObserverGuardModule.sleela · 89 line(s) · sleela

<< lib/observer/SLObserverGuardModule.sleela
   SLeeLa Standard Library Definition.
   Definition: A drop-in module for the dynamic document observer. The nested
     class SLObserverGuardModule.Responder watches for a forbidden line (exact
     match) and PROPOSES replacing it with a redaction marker. It never edits
     the document itself: the observer decides, and tells the guard the result. >>
#sleela 2.5
material;
< Family: observer. The safe-response example: proposals, not mutations. >
class SLObserverGuardModule {
  < ---- 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 = 39206;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-11-11";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-11-11";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 8;
  < 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; }

  class Responder {
    SLObserverPort port;
    String forbidden;
    int redactions;
    int declinedCount;
    void attach(String portName, String forbiddenLine) {
      port = new SLObserverPort();
      port.configure(portName);
      forbidden = forbiddenLine;
      redactions = 0; declinedCount = 0;
    }
    SLObserverPort portOf() { return port; }
    int redactionCount() { return redactions; }
    int declinedTotal() { return declinedCount; }
    int pump() {
      int n = 0;
      while (port.hasMail()) {
        SLObserverMessage m = port.next();
        n = n + 1;
        int k = m.getKind();
        if (k == 5) {
          if (m.getOp() != 2 && m.getText() == forbidden) {
            port.propose(1, m.getLine(), "[redacted]", m.getRevision());
            port.note("*", "guard proposed redacting line " + m.getLine());
          }
        } else if (k == 2) {
          if (m.getFrom() == "observer") {
            if (m.getExtra() == "declined") { declinedCount = declinedCount + 1; }
            else { redactions = redactions + 1; }
          }
        }
      }
      return n;
    }
  }
}