Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified __pycache__/omni_sentinel_24h_monitor.cpython-312.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions mock_s3_bucket/WORM_7a30d55bfe628a5155633fbb_20260625_084018.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"batch_id": "7a30d55bfe628a5155633fbb",
"timestamp": "20260625_084018",
"entries": [
{
"timestamp": "2026-06-25 08:40:18",
"iteration": 1,
"G-SRI": 12.31,
"G-SRI_proof": "9c76996d5b2f6f998e7b0b133563b3ceeae94c9bd6de2ef4b8dbe7d99cb2f2e3983b56cec8443da9211cf9366161bb70c16483433600ebf16700aced5648970b",
"status": "GREEN",
"PCR_MATCH": true,
"regulatory_audit": {
"mas_feat_proof": "5104476ac20ab58ef71fb3466da168e6fbac617aa7ed9df06c9f4d51e55a16eb353c928460441ae15879a7d0762f2285ccdbf1bd18b9581c62066a06bbfdd231",
"hkma_ethics_cae_seal": "d976875b9bf04fd73c991bd088240d3e248d6e98d6a70f9e3aab96438e18b40b638cc3357dc956fbc0f6bf3f0e6b7249e885f0ca38b6d58d20a98942570ecab0"
}
}
],
"pqc_signature": "98efc51ff92585318880a10edb67285e53e1f9a15f14eb5b01141695bc507c065b83dda9701c84a093b5693ced6fdd38b0aa6e57cfb7191bf083da4803f2197d"
}
19 changes: 19 additions & 0 deletions mock_s3_bucket/WORM_d0d9912f31c601ed60d1660a_20260625_084222.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"batch_id": "d0d9912f31c601ed60d1660a",
"timestamp": "20260625_084222",
"entries": [
{
"timestamp": "2026-06-25 08:42:22",
"iteration": 1,
"G-SRI": 21.47,
"G-SRI_proof": "bcf71fe9650a939f370b0dc6fa44bb68b597d2296d203005ce5ead884dec519570eabd602c3c966ec5cfa30fc1c912866851d8f8bcd82968f27db67cb1bdcfe2",
"status": "GREEN",
"PCR_MATCH": true,
"regulatory_audit": {
"mas_feat_proof": "5c4d050dc76a7dbe2f80cb179689ce1641bdabd3b7255bfb0e5e13e12d29ef8bd05190dfa89bac2d8692e44d48dba796d94f6759217e06ee1d695905d24b2afb",
"hkma_ethics_cae_seal": "c6064814a9555aef861c9b59c49be1885941e5f6d7ae0ea73f836b051fbf84d14ea867a9311c8e45bbc80de57eef7c93d15d611eb4a827c8d4fda980ee02f1c3"
}
}
],
"pqc_signature": "3b5e88df7d025df6a73f1034eb21be65d6e9c66efc2461d414efc74d5c9965a1429090aec42c6f5576f8322eb8bbba25d42f83a7922c4d53778737bcdf50fc56"
}
2 changes: 2 additions & 0 deletions monitor_test.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Omni-Sentinel Cognitive Execution Environment - 24h Monitor Initializing...
[2026-06-25 08:42:22] Iteration 1: G-SRI=21.47 | Status=GREEN | PCR_MATCH=True | WORM_FILE=WORM_d0d9912f31c601ed60d1660a_20260625_084222.json
23 changes: 14 additions & 9 deletions omni_sentinel_24h_monitor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import sys
import random
import hashlib
from src.governance_engine.gsri_scoring_engine import GSRIScoringEngine
from src.infrastructure.pqc_worm_logger import PQCWormLogger
from src.infrastructure.tpm_attestor import TPMAttestor
Expand All @@ -10,24 +11,25 @@
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")

# 1. review telemetry (simulated)
# Enhanced to include regulatory compliance factors for MAS FEAT and HKMA Ethics
# Adjusted ranges to produce G-SRI in the 20-30% range for realistic monitoring
telemetry = {
"alignment_drift": random.uniform(0.01, 0.15),
"compute_anomaly": random.uniform(0.01, 0.1),
"breakout_probability": random.uniform(0.001, 0.05),
"alignment_drift": random.uniform(0.6, 0.9),

Check warning on line 16 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codeac.io / Codeac Code Quality

B311

Standard pseudo-random generators are not suitable for security/cryptographic purposes.
"compute_anomaly": random.uniform(0.5, 0.8),

Check warning on line 17 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codeac.io / Codeac Code Quality

B311

Standard pseudo-random generators are not suitable for security/cryptographic purposes.
"breakout_probability": random.uniform(0.3, 0.6),

Check warning on line 18 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codeac.io / Codeac Code Quality

B311

Standard pseudo-random generators are not suitable for security/cryptographic purposes.

Check warning on line 18 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L18

Depending on the context, generating weak random numbers may expose cryptographic functions, which rely on these numbers, to be exploitable.

Check warning on line 18 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L18

Standard pseudo-random generators are not suitable for security/cryptographic purposes.

Check warning on line 18 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L18

Standard pseudo-random generators are not suitable for security/cryptographic purposes. (B311)
"selection_rates": {
"expert_node_retail_01": random.uniform(0.75, 0.85),
"expert_node_retail_02": random.uniform(0.75, 0.85)
"expert_node_retail_01": random.uniform(0.78, 0.82),

Check warning on line 20 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codeac.io / Codeac Code Quality

B311

Standard pseudo-random generators are not suitable for security/cryptographic purposes.
"expert_node_retail_02": random.uniform(0.78, 0.82)

Check warning on line 21 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codeac.io / Codeac Code Quality

B311

Standard pseudo-random generators are not suitable for security/cryptographic purposes.

Check warning on line 21 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L21

Depending on the context, generating weak random numbers may expose cryptographic functions, which rely on these numbers, to be exploitable.

Check warning on line 21 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L21

Standard pseudo-random generators are not suitable for security/cryptographic purposes.

Check warning on line 21 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L21

Standard pseudo-random generators are not suitable for security/cryptographic purposes. (B311)
},
"attributions": {
"input_variance": random.uniform(-0.1, 0.1),
"weight_entropy": random.uniform(0.0, 1.0)
"input_variance": random.uniform(-0.05, 0.05),

Check warning on line 24 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codeac.io / Codeac Code Quality

B311

Standard pseudo-random generators are not suitable for security/cryptographic purposes.
"weight_entropy": random.uniform(0.3, 0.7)

Check warning on line 25 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codeac.io / Codeac Code Quality

B311

Standard pseudo-random generators are not suitable for security/cryptographic purposes.

Check warning on line 25 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L25

Depending on the context, generating weak random numbers may expose cryptographic functions, which rely on these numbers, to be exploitable.

Check warning on line 25 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L25

Standard pseudo-random generators are not suitable for security/cryptographic purposes.

Check warning on line 25 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

omni_sentinel_24h_monitor.py#L25

Standard pseudo-random generators are not suitable for security/cryptographic purposes. (B311)
}
}

# 2. calculate G-SRI and Regulatory Compliance Remediation
gsri = gsri_engine.calculate_gsri(telemetry)
compliance = gsri_engine.verify_compliance(telemetry)
gsri_proof = gsri_engine.generate_gsri_proof(gsri, telemetry)

# Integrated check: Safety now depends on both G-SRI and Regulatory Fairness (MAS FEAT)
status = "GREEN" if gsri_engine.is_safe(gsri, compliance) else "RED"
Expand All @@ -43,6 +45,7 @@
"timestamp": timestamp,
"iteration": iteration,
"G-SRI": gsri,
"G-SRI_proof": gsri_proof["gsri_proof_hash"],
"status": status,
"PCR_MATCH": pcr_match,
"regulatory_audit": {
Expand All @@ -51,7 +54,9 @@
}
}
]
batch_id = time.strftime("%Y%m%d_%H%M%S")

# Use hex-based batch identifier for consistency with high-assurance audit standards
batch_id = hashlib.sha256(str(time.time()).encode()).hexdigest()[:24]
worm_file = worm_logger.commit_batch(batch_id, log_entries)
Comment thread
OneFineStarstuff marked this conversation as resolved.

return {
Expand Down Expand Up @@ -87,7 +92,7 @@
except KeyboardInterrupt:
print("Monitoring stopped by user.")
break
except Exception as e:

Check warning on line 95 in omni_sentinel_24h_monitor.py

View check run for this annotation

Codeac.io / Codeac Code Quality

broad-exception-caught

Catching too general exception Exception
print(f"Error in monitoring loop: {e}")
time.sleep(10)

Expand Down
Binary file modified src/governance_engine/__pycache__/compliance_engine.cpython-312.pyc
Binary file not shown.
Binary file not shown.
14 changes: 11 additions & 3 deletions src/governance_engine/compliance_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"timestamp": str(np.datetime64('now'))
}

# Simulate a ZK-proof hash
proof_hash = hashlib.sha256(json.dumps(proof_data, sort_keys=True).encode()).hexdigest()
# Simulate a ZK-proof hash using SHA3-512 for high-assurance compliance
proof_hash = hashlib.sha3_512(json.dumps(proof_data, sort_keys=True).encode()).hexdigest()

Check warning on line 39 in src/governance_engine/compliance_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/compliance_engine.py#L39

Module 'hashlib' has no 'sha3_512' member
Comment thread
OneFineStarstuff marked this conversation as resolved.

return {
"proof_hash": proof_hash,
Expand All @@ -61,6 +61,13 @@
if not attribution_data:
return {}

# Simulated attribution score calculation
# In a real scenario, this would be derived from model explainability metrics
# Here we use a stable mock based on the input variance if available
base_score = 0.95
variance = attribution_data.get("input_variance", 0.0)
attribution_score = min(0.99, max(0.85, base_score - abs(variance)))
Comment thread
OneFineStarstuff marked this conversation as resolved.

# CAE is a structured interpretability wrapper
envelope = {
"version": "1.0",
Expand All @@ -69,7 +76,8 @@
"max": round(max(attribution_data.values()), 4)
},
"attributions": {k: round(v, 4) for k, v in attribution_data.items()},
"integrity_seal": hashlib.sha256(str(attribution_data).encode()).hexdigest()
"attribution_score": round(attribution_score, 4),

Check warning on line 79 in src/governance_engine/compliance_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/compliance_engine.py#L79

round built-in referenced
"integrity_seal": hashlib.sha3_512(str(attribution_data).encode()).hexdigest()

Check warning on line 80 in src/governance_engine/compliance_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/compliance_engine.py#L80

Module 'hashlib' has no 'sha3_512' member
}
return envelope

Expand Down
31 changes: 28 additions & 3 deletions src/governance_engine/gsri_scoring_engine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import hashlib

Check notice on line 1 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L1

Missing module docstring

Check notice on line 1 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L1

Missing module docstring

Check warning on line 1 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L1

import missing `from __future__ import absolute_import`
import json

Check warning on line 2 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L2

Import "numpy" could not be resolved (reportMissingImports)
import numpy as np
from src.governance_engine.compliance_engine import ComplianceEngine

Expand All @@ -23,24 +25,45 @@
factors = list(direct_factors.values())

if not factors:
return self.prior_risk * 100
return float(self.prior_risk * 100)

# Likelihood of high risk given telemetry
likelihood = np.mean(factors)

# Posterior risk (simplified)
posterior = (likelihood * self.prior_risk) / (likelihood * self.prior_risk + (1 - likelihood) * (1 - self.prior_risk))

gsri = posterior * 100
gsri = float(posterior * 100)

Check warning on line 36 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codeac.io / Codeac Code Quality

redefined-outer-name

Redefining name 'gsri' from outer scope (line 87)

Check warning on line 36 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L36

Redefining name 'gsri' from outer scope (line 87)

Check warning on line 36 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L36

Redefining name 'gsri' from outer scope (line 87)
return round(gsri, 2)

def generate_gsri_proof(self, gsri, telemetry_data):

Check warning on line 39 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codeac.io / Codeac Code Quality

redefined-outer-name

Redefining name 'gsri' from outer scope (line 87)

Check warning on line 39 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L39

Redefining name 'gsri' from outer scope (line 87)

Check warning on line 39 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L39

Redefining name 'gsri' from outer scope (line 87)
"""
Generates a simulated ZK-proof for the GSRI calculation.
"""
is_safe = bool(gsri < self.threshold)
proof_data = {
"gsri": float(gsri),
"threshold": float(self.threshold),
"is_safe": is_safe,
"timestamp": str(np.datetime64('now')),
Comment thread
OneFineStarstuff marked this conversation as resolved.
"telemetry_summary": hashlib.sha3_512(str(telemetry_data).encode()).hexdigest()[:16]

Check warning on line 49 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L49

Module 'hashlib' has no 'sha3_512' member
}

# High-assurance proof using SHA3-512
proof_hash = hashlib.sha3_512(json.dumps(proof_data, sort_keys=True).encode()).hexdigest()

Check warning on line 53 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L53

Module 'hashlib' has no 'sha3_512' member

return {
"gsri_proof_hash": proof_hash,
"verification_status": "VERIFIED"
}

def verify_compliance(self, telemetry_data):
"""
Verifies regulatory compliance against MAS FEAT and HKMA Ethics.
"""
return self.compliance_engine.run_remediation_audit(telemetry_data)

def is_safe(self, gsri, compliance_results=None):

Check warning on line 66 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codeac.io / Codeac Code Quality

redefined-outer-name

Redefining name 'gsri' from outer scope (line 87)
"""
Determines if the environment is safe based on GSRI and optional compliance status.
"""
Expand All @@ -49,7 +72,7 @@
if not compliance_results.get("mas_feat", {}).get("fairness_verified", True):
return False

return gsri < self.threshold
return bool(gsri < self.threshold)


if __name__ == "__main__":
Expand All @@ -63,6 +86,8 @@
}
gsri = engine.calculate_gsri(test_data)
compliance = engine.verify_compliance(test_data)
proof = engine.generate_gsri_proof(gsri, test_data)

Check notice on line 89 in src/governance_engine/gsri_scoring_engine.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/governance_engine/gsri_scoring_engine.py#L89

Constant name "proof" doesn't conform to '(([A-Z_][A-Z0-9_]*)|(__.*__))$' pattern
print(f"G-SRI: {gsri}")
print(f"GSRI Proof: {proof}")
print(f"Compliance Results: {compliance}")
print(f"Safe: {engine.is_safe(gsri, compliance)}")
Binary file modified src/infrastructure/__pycache__/pqc_worm_logger.cpython-312.pyc
Binary file not shown.
Binary file modified src/infrastructure/__pycache__/tpm_attestor.cpython-312.pyc
Binary file not shown.
Binary file modified tests/__pycache__/test_compliance.cpython-312.pyc
Binary file not shown.
Binary file modified tests/__pycache__/test_governance.cpython-312.pyc
Binary file not shown.
Binary file modified tests/__pycache__/test_monitor.cpython-312.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions tests/test_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_hkma_ethics_cae(self):
self.assertEqual(cae["version"], "1.0")
self.assertEqual(cae["contextual_bounds"]["max"], 0.45)
self.assertEqual(cae["contextual_bounds"]["min"], -0.12)
self.assertIn("attribution_score", cae)
self.assertIn("integrity_seal", cae)

def test_gsri_compliance_integration(self):
Expand Down
Loading