aegisstate 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aegisstate/__init__.py +4 -0
- aegisstate/agent.py +20 -0
- aegisstate/benchmark.py +70 -0
- aegisstate/demo.py +95 -0
- aegisstate/demo2.py +164 -0
- aegisstate/engine.py +370 -0
- aegisstate/evidence_updates.py +38 -0
- aegisstate/executor.py +81 -0
- aegisstate/main.py +104 -0
- aegisstate/replay_store.py +286 -0
- aegisstate/report_bridge.py +83 -0
- aegisstate/report_ingestion.py +144 -0
- aegisstate/report_security.py +74 -0
- aegisstate-0.1.0.dist-info/METADATA +362 -0
- aegisstate-0.1.0.dist-info/RECORD +18 -0
- aegisstate-0.1.0.dist-info/WHEEL +5 -0
- aegisstate-0.1.0.dist-info/licenses/LICENSE.txt +16 -0
- aegisstate-0.1.0.dist-info/top_level.txt +1 -0
aegisstate/__init__.py
ADDED
aegisstate/agent.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class Agent:
|
|
2
|
+
def __init__(self, state):
|
|
3
|
+
self.state = state
|
|
4
|
+
|
|
5
|
+
def execute(self, action_name):
|
|
6
|
+
"""Execute an action only if AegisState allows it."""
|
|
7
|
+
|
|
8
|
+
decision = self.state.validate(action_name)
|
|
9
|
+
|
|
10
|
+
if not decision["valid"]:
|
|
11
|
+
print(f"BLOCKED: {action_name}")
|
|
12
|
+
print(f"Reason: {decision['reason']}")
|
|
13
|
+
|
|
14
|
+
return False
|
|
15
|
+
|
|
16
|
+
print(f"ALLOWED: {action_name}")
|
|
17
|
+
print(f"Reason: {decision['reason']}")
|
|
18
|
+
print("Action executed (simulation only).")
|
|
19
|
+
|
|
20
|
+
return True
|
aegisstate/benchmark.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
from time import perf_counter
|
|
3
|
+
|
|
4
|
+
from aegisstate.engine import AegisState
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def build_chain(size=100):
|
|
8
|
+
state = AegisState()
|
|
9
|
+
|
|
10
|
+
for i in range(size):
|
|
11
|
+
state.add_item(f"decision_{i}")
|
|
12
|
+
|
|
13
|
+
for i in range(1, size):
|
|
14
|
+
state.add_dependency(
|
|
15
|
+
f"decision_{i}",
|
|
16
|
+
f"decision_{i - 1}",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# Record decisions from the root to the final node.
|
|
20
|
+
for i in range(size):
|
|
21
|
+
state.commit_decision(
|
|
22
|
+
f"decision_{i}",
|
|
23
|
+
{"value": i},
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
return state
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def main():
|
|
30
|
+
size = 100
|
|
31
|
+
repetitions = 100
|
|
32
|
+
|
|
33
|
+
state = build_chain(size)
|
|
34
|
+
final_decision = f"decision_{size - 1}"
|
|
35
|
+
|
|
36
|
+
# Measure validation before any evidence changes.
|
|
37
|
+
start = perf_counter()
|
|
38
|
+
|
|
39
|
+
for _ in range(repetitions):
|
|
40
|
+
result = state.validate(final_decision)
|
|
41
|
+
|
|
42
|
+
if not result["valid"]:
|
|
43
|
+
raise RuntimeError("Expected a valid decision")
|
|
44
|
+
|
|
45
|
+
validation_time = (
|
|
46
|
+
perf_counter() - start
|
|
47
|
+
) / repetitions
|
|
48
|
+
|
|
49
|
+
# Build a fresh graph for the invalidation measurement.
|
|
50
|
+
state = build_chain(size)
|
|
51
|
+
|
|
52
|
+
start = perf_counter()
|
|
53
|
+
state.set_version("decision_0", 2)
|
|
54
|
+
invalidation_time = perf_counter() - start
|
|
55
|
+
|
|
56
|
+
print("\n=== AEGISSTATE DAY 8 BENCHMARK ===")
|
|
57
|
+
print(f"Dependency chain size: {size}")
|
|
58
|
+
print(f"Validation repetitions: {repetitions}")
|
|
59
|
+
print(
|
|
60
|
+
f"Average validation time: "
|
|
61
|
+
f"{validation_time * 1000:.3f} ms"
|
|
62
|
+
)
|
|
63
|
+
print(
|
|
64
|
+
f"Root-change invalidation time: "
|
|
65
|
+
f"{invalidation_time * 1000:.3f} ms"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
main()
|
aegisstate/demo.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
|
|
2
|
+
from aegisstate.engine import AegisState
|
|
3
|
+
from aegisstate.executor import ProtectedExecutor
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
state = AegisState()
|
|
8
|
+
executor = ProtectedExecutor(state)
|
|
9
|
+
|
|
10
|
+
state.add_item("transaction")
|
|
11
|
+
state.add_item("risk_assessment")
|
|
12
|
+
state.add_item("approval")
|
|
13
|
+
state.add_item("agent_action")
|
|
14
|
+
state.add_item("inventory_report")
|
|
15
|
+
state.add_item("inventory_data")
|
|
16
|
+
|
|
17
|
+
state.add_dependency("risk_assessment", "transaction")
|
|
18
|
+
state.add_dependency("approval", "risk_assessment")
|
|
19
|
+
state.add_dependency("agent_action", "approval")
|
|
20
|
+
|
|
21
|
+
state.add_dependency("inventory_report", "inventory_data")
|
|
22
|
+
|
|
23
|
+
state.commit_decision(
|
|
24
|
+
"risk_assessment",
|
|
25
|
+
{"risk_score": 20},
|
|
26
|
+
)
|
|
27
|
+
state.commit_decision(
|
|
28
|
+
"approval",
|
|
29
|
+
{"approved": True},
|
|
30
|
+
)
|
|
31
|
+
state.commit_decision(
|
|
32
|
+
"agent_action",
|
|
33
|
+
{"action": "execute_transaction"},
|
|
34
|
+
)
|
|
35
|
+
state.commit_decision(
|
|
36
|
+
"inventory_report",
|
|
37
|
+
{"items_available": 120},
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
print("\n1. Initial decisions recorded.")
|
|
41
|
+
|
|
42
|
+
result = executor.execute(
|
|
43
|
+
"execute_transaction",
|
|
44
|
+
"agent_action",
|
|
45
|
+
lambda: "Transaction executed",
|
|
46
|
+
)
|
|
47
|
+
print("Initial execution:", result)
|
|
48
|
+
|
|
49
|
+
state.set_version("transaction", 2)
|
|
50
|
+
|
|
51
|
+
print("\n2. Transaction evidence changed.")
|
|
52
|
+
|
|
53
|
+
print(
|
|
54
|
+
"Risk assessment:",
|
|
55
|
+
state.validate("risk_assessment"),
|
|
56
|
+
)
|
|
57
|
+
print("Approval:", state.validate("approval"))
|
|
58
|
+
print("Agent action:", state.validate("agent_action"))
|
|
59
|
+
print(
|
|
60
|
+
"Inventory report:",
|
|
61
|
+
state.validate("inventory_report"),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
blocked = executor.execute(
|
|
65
|
+
"execute_transaction",
|
|
66
|
+
"agent_action",
|
|
67
|
+
lambda: "Transaction executed",
|
|
68
|
+
)
|
|
69
|
+
print("\n3. Attempt using stale approval:", blocked)
|
|
70
|
+
|
|
71
|
+
state.commit_decision(
|
|
72
|
+
"risk_assessment",
|
|
73
|
+
{"risk_score": 35},
|
|
74
|
+
)
|
|
75
|
+
state.commit_decision(
|
|
76
|
+
"approval",
|
|
77
|
+
{"approved": True},
|
|
78
|
+
)
|
|
79
|
+
state.commit_decision(
|
|
80
|
+
"agent_action",
|
|
81
|
+
{"action": "execute_transaction"},
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
print("\n4. Decisions recalculated.")
|
|
85
|
+
|
|
86
|
+
recovered = executor.execute(
|
|
87
|
+
"execute_transaction",
|
|
88
|
+
"agent_action",
|
|
89
|
+
lambda: "Transaction executed after revalidation",
|
|
90
|
+
)
|
|
91
|
+
print("Execution after recovery:", recovered)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
main()
|
aegisstate/demo2.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
from aegisstate.engine import AegisState
|
|
5
|
+
from aegisstate.executor import ProtectedExecutor
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def read_transaction(label):
|
|
9
|
+
"""Collect transaction evidence at runtime."""
|
|
10
|
+
print(f"\n--- {label} ---")
|
|
11
|
+
|
|
12
|
+
while True:
|
|
13
|
+
try:
|
|
14
|
+
amount = float(input("Transaction amount: "))
|
|
15
|
+
|
|
16
|
+
# float() accepts "nan" and "inf". NaN is False for every
|
|
17
|
+
# comparison, so it would skip all risk thresholds and receive
|
|
18
|
+
# the lowest risk score (auto-approval).
|
|
19
|
+
if not math.isfinite(amount):
|
|
20
|
+
print("Enter a finite number.")
|
|
21
|
+
continue
|
|
22
|
+
|
|
23
|
+
if amount < 0:
|
|
24
|
+
print("Amount cannot be negative.")
|
|
25
|
+
continue
|
|
26
|
+
|
|
27
|
+
break
|
|
28
|
+
except ValueError:
|
|
29
|
+
print("Enter a valid number.")
|
|
30
|
+
|
|
31
|
+
while True:
|
|
32
|
+
status = input(
|
|
33
|
+
"Transaction status (pending/completed/cancelled): "
|
|
34
|
+
).strip().lower()
|
|
35
|
+
|
|
36
|
+
if status in {"pending", "completed", "cancelled"}:
|
|
37
|
+
break
|
|
38
|
+
|
|
39
|
+
print("Enter pending, completed, or cancelled.")
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
"amount": amount,
|
|
43
|
+
"status": status,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def calculate_risk(transaction):
|
|
48
|
+
"""Calculate a demonstration risk score from the evidence."""
|
|
49
|
+
amount = transaction["amount"]
|
|
50
|
+
status = transaction["status"]
|
|
51
|
+
|
|
52
|
+
if status != "pending":
|
|
53
|
+
return 100
|
|
54
|
+
if amount > 100_000:
|
|
55
|
+
return 80
|
|
56
|
+
if amount > 50_000:
|
|
57
|
+
return 60
|
|
58
|
+
|
|
59
|
+
return 20
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def process_decisions(state, transaction):
|
|
63
|
+
"""Recalculate decisions using the current transaction evidence."""
|
|
64
|
+
risk_score = calculate_risk(transaction)
|
|
65
|
+
|
|
66
|
+
approval = (
|
|
67
|
+
risk_score < 50
|
|
68
|
+
and transaction["status"] == "pending"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
state.commit_decision(
|
|
72
|
+
"risk_assessment",
|
|
73
|
+
{
|
|
74
|
+
"risk_score": risk_score,
|
|
75
|
+
"based_on": transaction.copy(),
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
state.commit_decision(
|
|
80
|
+
"approval",
|
|
81
|
+
{
|
|
82
|
+
"approved": approval,
|
|
83
|
+
"risk_score": risk_score,
|
|
84
|
+
},
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
print(f"Calculated risk score: {risk_score}")
|
|
88
|
+
print(f"Approval decision: {approval}")
|
|
89
|
+
|
|
90
|
+
return approval
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def main():
|
|
94
|
+
state = AegisState()
|
|
95
|
+
executor = ProtectedExecutor(state)
|
|
96
|
+
|
|
97
|
+
state.add_item("transaction", version=1)
|
|
98
|
+
state.add_item("risk_assessment")
|
|
99
|
+
state.add_item("approval")
|
|
100
|
+
state.add_item("agent_action")
|
|
101
|
+
|
|
102
|
+
state.add_dependency("risk_assessment", "transaction")
|
|
103
|
+
state.add_dependency("approval", "risk_assessment")
|
|
104
|
+
state.add_dependency("agent_action", "approval")
|
|
105
|
+
|
|
106
|
+
# First transaction input.
|
|
107
|
+
first_transaction = read_transaction("FIRST TRANSACTION")
|
|
108
|
+
|
|
109
|
+
print("\n--- FIRST DECISION ---")
|
|
110
|
+
first_approved = process_decisions(state, first_transaction)
|
|
111
|
+
|
|
112
|
+
if first_approved:
|
|
113
|
+
state.commit_decision(
|
|
114
|
+
"agent_action",
|
|
115
|
+
{"action": "process_transaction"},
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
first_result = executor.execute(
|
|
119
|
+
"process_transaction",
|
|
120
|
+
"agent_action",
|
|
121
|
+
lambda: "Transaction action executed",
|
|
122
|
+
)
|
|
123
|
+
print("Execution result:", first_result)
|
|
124
|
+
|
|
125
|
+
# Read the evidence again to detect changes.
|
|
126
|
+
second_transaction = read_transaction("UPDATED TRANSACTION")
|
|
127
|
+
|
|
128
|
+
if second_transaction == first_transaction:
|
|
129
|
+
print("\nEvidence has not changed.")
|
|
130
|
+
print("No new version is required.")
|
|
131
|
+
return
|
|
132
|
+
|
|
133
|
+
print("\nEvidence changed! Updating transaction version...")
|
|
134
|
+
state.set_version("transaction", 2)
|
|
135
|
+
|
|
136
|
+
print("\n--- STALE DECISION CHECK ---")
|
|
137
|
+
print(state.validate("agent_action"))
|
|
138
|
+
|
|
139
|
+
print("\n--- RECOMPUTING DECISIONS ---")
|
|
140
|
+
second_approved = process_decisions(state, second_transaction)
|
|
141
|
+
|
|
142
|
+
if second_approved:
|
|
143
|
+
# Commit a fresh action decision based on fresh approval.
|
|
144
|
+
state.commit_decision(
|
|
145
|
+
"agent_action",
|
|
146
|
+
{"action": "process_updated_transaction"},
|
|
147
|
+
)
|
|
148
|
+
else:
|
|
149
|
+
print("No new action decision will be committed.")
|
|
150
|
+
|
|
151
|
+
print("\n--- FINAL EXECUTION CHECK ---")
|
|
152
|
+
final_result = executor.execute(
|
|
153
|
+
"process_transaction",
|
|
154
|
+
"agent_action",
|
|
155
|
+
lambda: "Transaction action executed",
|
|
156
|
+
)
|
|
157
|
+
print("Execution result:", final_result)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
if __name__ == "__main__":
|
|
161
|
+
try:
|
|
162
|
+
main()
|
|
163
|
+
except (EOFError, KeyboardInterrupt):
|
|
164
|
+
print("\nInput ended; exiting.")
|