theus 2.2.0__cp311-cp311-manylinux_2_24_aarch64.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.
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: theus
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: Programming Language :: Rust
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
9
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
14
|
+
Requires-Dist: pydantic>=2.0
|
|
15
|
+
Requires-Dist: pyyaml>=6.0
|
|
16
|
+
Requires-Dist: typing-extensions>=4.0
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Summary: Theus Agentic Framework - Industrial Grade Process-Oriented Programming (POP)
|
|
19
|
+
Keywords: ai,agent,pop,process-oriented,transactional,state-management,microkernel
|
|
20
|
+
Author-email: Do Huy Hoang <dohuyhoangvn93@gmail.com>
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
23
|
+
Project-URL: Homepage, https://github.com/dohuyhoang93/theus
|
|
24
|
+
Project-URL: Issues, https://github.com/dohuyhoang93/theus/issues
|
|
25
|
+
Project-URL: Repository, https://github.com/dohuyhoang93/theus
|
|
26
|
+
|
|
27
|
+
# Theus: Process-Oriented Operating System for Python
|
|
28
|
+
|
|
29
|
+
[](https://pypi.org/project/theus/)
|
|
30
|
+
[](https://opensource.org/licenses/MIT)
|
|
31
|
+
[](https://creativecommons.org/licenses/by/4.0/)
|
|
32
|
+
[](https://www.python.org/downloads/)
|
|
33
|
+
|
|
34
|
+
> **"Data is the Asset. Code is the Liability. Theus protects the Asset."**
|
|
35
|
+
|
|
36
|
+
Theus is a next-generation architectural framework that treats your application not as a collection of objects, but as a **deterministic workflow of processes**. It introduces the **Process-Oriented Programming (POP)** paradigm to solve the chaos of state management in complex systems like AI Agents, Core Banking, and Industrial Automation.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🌪️ The Problem
|
|
41
|
+
In modern software (OOP, EDA, Microservices), the biggest source of bugs is **State Management**:
|
|
42
|
+
* **Implicit Mutations:** Who changed `user.balance`? Was it the PaymentService or the RefundHandler?
|
|
43
|
+
* **Race Conditions:** Transient events corrupting persistent data.
|
|
44
|
+
* **Zombie State:** Old references pointing to stale data.
|
|
45
|
+
* **Audit Gaps:** We log *what* happened, but we can't mathematically prove *why* it was allowed.
|
|
46
|
+
|
|
47
|
+
## 🛡️ The Theus Solution
|
|
48
|
+
Theus acts as a micro-kernel for your logic, enforcing strict architectural invariants at runtime:
|
|
49
|
+
|
|
50
|
+
### 1. The 3-Axis Context Model
|
|
51
|
+
State is no longer a "bag of variables". It is a 3D space defined by:
|
|
52
|
+
* **Layer:** `Global` (Config), `Domain` (Session), `Local` (Process).
|
|
53
|
+
* **Semantic:** `Input` (Read-only), `Output` (Write-only), `SideEffect` (env), `Error`.
|
|
54
|
+
* **Zone:**
|
|
55
|
+
* **DATA:** Persistent Assets (Replayable).
|
|
56
|
+
* **SIGNAL:** Transient Events (Reset on Read).
|
|
57
|
+
* **META:** Observability (Logs/Traces).
|
|
58
|
+
* **HEAVY:** High-Perf Tensors/Blobs (Zero-Copy, Non-Transactional).
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
[Y] SEMANTIC
|
|
62
|
+
(Input, Output, SideEffect, Error)
|
|
63
|
+
^
|
|
64
|
+
|
|
|
65
|
+
|
|
|
66
|
+
| +------+------+
|
|
67
|
+
| /| /|
|
|
68
|
+
+--------------+ | CONTEXT + |----------> [Z] ZONE
|
|
69
|
+
/ | | OBJECT | | (Data, Signal, Meta, Heavy)
|
|
70
|
+
/ | +------------+ |
|
|
71
|
+
/ |/ |/
|
|
72
|
+
/ +------+------+
|
|
73
|
+
v
|
|
74
|
+
[X] LAYER
|
|
75
|
+
(Global, Domain, Local)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. Zero-Trust Memory
|
|
79
|
+
* **Default Deny:** Processes cannot access ANY data unless explicitly declared in a `@process` Contract.
|
|
80
|
+
* **Immutability:** Inputs are physically frozen (`FrozenList`, `FrozenDict`).
|
|
81
|
+
* **Isolation:** Signals cannot be used as Inputs for Business Logic (Architectural Boundary enforcement).
|
|
82
|
+
|
|
83
|
+
### 3. Industrial-Grade Audit
|
|
84
|
+
* **Active Defense:** Rules (`min`, `max`, `regex`) are enforced at Input/Output Gates.
|
|
85
|
+
* **Severity Levels:**
|
|
86
|
+
* **S (Safety):** Emergency Stop.
|
|
87
|
+
* **A (Abort):** Hard Stop Workflow.
|
|
88
|
+
* **B (Block):** Rollback Transaction.
|
|
89
|
+
* **C (Campaign):** Warning.
|
|
90
|
+
* **Resilience:** Configurable tolerance thresholds (e.g., "Allow 2 glitches, block on 3rd").
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 📦 Installation
|
|
95
|
+
|
|
96
|
+
Theus requires **Python 3.12+** to leverage advanced typing and dataclasses.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install theus
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## ⚡ Quick Start: Building a Bank
|
|
105
|
+
|
|
106
|
+
This example demonstrates Contracts, Zoning, and Transaction safety.
|
|
107
|
+
|
|
108
|
+
### 1. Define the Context (The Asset)
|
|
109
|
+
```python
|
|
110
|
+
from dataclasses import dataclass, field
|
|
111
|
+
from theus.context import BaseSystemContext, BaseDomainContext, BaseGlobalContext
|
|
112
|
+
|
|
113
|
+
@dataclass
|
|
114
|
+
class BankDomain(BaseDomainContext):
|
|
115
|
+
# DATA ZONE: Persistent Assets
|
|
116
|
+
accounts: dict = field(default_factory=dict) # {user_id: balance}
|
|
117
|
+
total_reserves: int = 1_000_000
|
|
118
|
+
|
|
119
|
+
# SIGNAL ZONE: Control Flow
|
|
120
|
+
sig_fraud_detected: bool = False
|
|
121
|
+
|
|
122
|
+
@dataclass
|
|
123
|
+
class BankSystem(BaseSystemContext):
|
|
124
|
+
domain_ctx: BankDomain = field(default_factory=BankDomain)
|
|
125
|
+
global_ctx: BaseGlobalContext = field(default_factory=BaseGlobalContext)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 2. Define the Process (The Logic)
|
|
129
|
+
```python
|
|
130
|
+
from theus.contracts import process
|
|
131
|
+
|
|
132
|
+
@process(
|
|
133
|
+
# STRICT CONTRACT
|
|
134
|
+
inputs=['domain_ctx.accounts'],
|
|
135
|
+
outputs=['domain_ctx.accounts', 'domain_ctx.total_reserves', 'domain_ctx.sig_fraud_detected'],
|
|
136
|
+
errors=['ValueError']
|
|
137
|
+
)
|
|
138
|
+
def transfer(ctx, from_user: str, to_user: str, amount: int):
|
|
139
|
+
# 1. Input Validation
|
|
140
|
+
if amount <= 0:
|
|
141
|
+
raise ValueError("Amount must be positive")
|
|
142
|
+
|
|
143
|
+
# 2. Business Logic (Operating on Shadow Copies)
|
|
144
|
+
sender_bal = ctx.domain_ctx.accounts.get(from_user, 0)
|
|
145
|
+
|
|
146
|
+
if sender_bal < amount:
|
|
147
|
+
# Trigger Signal
|
|
148
|
+
ctx.domain_ctx.sig_fraud_detected = True
|
|
149
|
+
return "Failed: Insufficient Funds"
|
|
150
|
+
|
|
151
|
+
# 3. Mutation (Optimistic Write)
|
|
152
|
+
ctx.domain_ctx.accounts[from_user] -= amount
|
|
153
|
+
ctx.domain_ctx.accounts[to_user] = ctx.domain_ctx.accounts.get(to_user, 0) + amount
|
|
154
|
+
|
|
155
|
+
return "Success"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 3. Run with Safety (The Engine)
|
|
159
|
+
```python
|
|
160
|
+
from theus.engine import TheusEngine
|
|
161
|
+
|
|
162
|
+
# Setup Data
|
|
163
|
+
sys_ctx = BankSystem()
|
|
164
|
+
sys_ctx.domain_ctx.accounts = {"Alice": 1000, "Bob": 0}
|
|
165
|
+
|
|
166
|
+
# Initialize Engine
|
|
167
|
+
engine = TheusEngine(sys_ctx, strict_mode=True)
|
|
168
|
+
|
|
169
|
+
# 🚀 PRO TIP: Auto-Discovery
|
|
170
|
+
# Instead of registering manually, you can scan an entire directory:
|
|
171
|
+
# engine.scan_and_register("src/processes")
|
|
172
|
+
|
|
173
|
+
engine.register_process("transfer", transfer)
|
|
174
|
+
|
|
175
|
+
# Execute
|
|
176
|
+
result = engine.run_process("transfer", from_user="Alice", to_user="Bob", amount=500)
|
|
177
|
+
|
|
178
|
+
print(f"Result: {result}")
|
|
179
|
+
print(f"Alice: {sys_ctx.domain_ctx.accounts['Alice']}") # 500
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## 🛠️ CLI Tools
|
|
185
|
+
|
|
186
|
+
Theus provides a powerful CLI suite to accelerate development and maintain architectural integrity.
|
|
187
|
+
|
|
188
|
+
* **`python -m theus.cli init <project_name>`**: Scaffolds a new project with the standard V2 structure (`src/`, `specs/`, `workflows/`).
|
|
189
|
+
* **`python -m theus.cli audit gen-spec`**: Scans your `@process` functions and automatically populates `specs/audit_recipe.yaml` with rule skeletons.
|
|
190
|
+
* **`python -m theus.cli audit inspect <process_name>`**: Inspects the effective audit rules, side effects, and error contracts for a specific process.
|
|
191
|
+
* **`python -m theus.cli schema gen`**: Infers and generates `specs/context_schema.yaml` from your Python Dataclass definitions.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## 🧠 Advanced Architecture
|
|
196
|
+
|
|
197
|
+
### The Transaction Engine
|
|
198
|
+
Theus uses a **Hybrid Transaction Model**:
|
|
199
|
+
* **Scalars:** Updated in-place with an Undo Log (for speed).
|
|
200
|
+
* **Collections:** Updated via **Shadow Copy** (for safety).
|
|
201
|
+
If a process crashes or is blocked by Audit, Theus rolls back the entire state instantly.
|
|
202
|
+
|
|
203
|
+
### The Heavy Zone (Optimization)
|
|
204
|
+
For AI workloads (Images, Tensors) > 1MB, use `heavy_` variables.
|
|
205
|
+
* **Behavior:** Writes bypass the Transaction Log (Zero-Copy).
|
|
206
|
+
* **Trade-off:** Changes to Heavy data are **NOT** reverted on Rollback.
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
### The Audit Recipe (`audit.yaml`)
|
|
210
|
+
Decouple your business rules from your code.
|
|
211
|
+
|
|
212
|
+
```yaml
|
|
213
|
+
process_recipes:
|
|
214
|
+
transfer:
|
|
215
|
+
inputs:
|
|
216
|
+
- field: "amount"
|
|
217
|
+
max: 10000 # Max transfer limit
|
|
218
|
+
level: "B" # Block transaction
|
|
219
|
+
outputs:
|
|
220
|
+
- field: "domain.total_reserves"
|
|
221
|
+
min: 0 # Reserves must never be negative
|
|
222
|
+
level: "S" # Safety Interlock (Stop System)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### The Orchestrator (FSM)
|
|
226
|
+
Manage complex flows using `workflow.yaml`:
|
|
227
|
+
```yaml
|
|
228
|
+
states:
|
|
229
|
+
IDLE:
|
|
230
|
+
events:
|
|
231
|
+
CMD_TX: "PROCESSING"
|
|
232
|
+
PROCESSING:
|
|
233
|
+
entry: "transfer"
|
|
234
|
+
events:
|
|
235
|
+
EVT_SUCCESS: "NOTIFY"
|
|
236
|
+
EVT_FAIL: "IDLE"
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 📚 Documentation
|
|
242
|
+
|
|
243
|
+
* **[POP Whitepaper v2.0](./Documents/POP_Whitepaper_v2.0.md):** The formal theoretical basis.
|
|
244
|
+
* **[Theus Master Class](./Documents/tutorials/en/):** 15-Chapter Zero-to-Hero Tutorial.
|
|
245
|
+
* **[AI Developer Guide](./Documents/AI_DEVELOPER_GUIDE.md):** Prompt context for LLMs.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## ⚖️ License
|
|
250
|
+
|
|
251
|
+
* **Software:** [MIT License](https://opensource.org/licenses/MIT).
|
|
252
|
+
* **Whitepaper:** [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/).
|
|
253
|
+
|
|
254
|
+
**Maintained by:** [Hoàng Đỗ Huy](https://github.com/dohuyhoang93)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
theus-2.2.0.dist-info/METADATA,sha256=3Jq5E7vrujHdfN8hb_wAidMK9-GrKDs0gfjWK1bP0Cw,9829
|
|
2
|
+
theus-2.2.0.dist-info/WHEEL,sha256=FCxMJ_FUdGXtOMV4MTwhpVs8OL3wADbzRcaMnnuh7iM,110
|
|
3
|
+
theus-2.2.0.dist-info/entry_points.txt,sha256=4XS3gLcx_c1TaU9K4RzZAa2a1pl9nOuIvc2gtP9CttY,39
|
|
4
|
+
theus-2.2.0.dist-info/licenses/LICENSE,sha256=c7Y8cFLqb0XiilV3Qj40Fir6ZOtFRKAaWXoo7lHE-Lg,1072
|
|
5
|
+
theus_core/__init__.py,sha256=6fM5ptalKe0oLgAT6PigBTLJNkeHI-sLSDhvknkoy4s,123
|
|
6
|
+
theus_core/theus_core.cpython-311-aarch64-linux-gnu.so,sha256=amQKx3G2Zn6aHOBL_OE4Ubo8R60CJYRP3h2snbTiUQI,1056104
|
|
7
|
+
theus-2.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 POP SDK Authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
theus_core/__init__.py
ADDED
|
Binary file
|