conservation-enforcer 0.1.0__tar.gz
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.
- conservation_enforcer-0.1.0/LICENSE +21 -0
- conservation_enforcer-0.1.0/PKG-INFO +227 -0
- conservation_enforcer-0.1.0/README.md +214 -0
- conservation_enforcer-0.1.0/pyproject.toml +18 -0
- conservation_enforcer-0.1.0/setup.cfg +4 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer/__init__.py +46 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer/assembler.py +206 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer/enforcer.py +100 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer/policies/__init__.py +228 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer/vm.py +412 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer.egg-info/PKG-INFO +227 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer.egg-info/SOURCES.txt +16 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer.egg-info/dependency_links.txt +1 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer.egg-info/requires.txt +3 -0
- conservation_enforcer-0.1.0/src/conservation_enforcer.egg-info/top_level.txt +1 -0
- conservation_enforcer-0.1.0/tests/test_assembler.py +186 -0
- conservation_enforcer-0.1.0/tests/test_enforcer.py +158 -0
- conservation_enforcer-0.1.0/tests/test_vm.py +153 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SuperInstance
|
|
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.
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: conservation-enforcer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: FLUX bytecode conservation-law enforcement for LLM outputs
|
|
5
|
+
Author: SuperInstance
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# ⚡ Conservation Enforcer
|
|
15
|
+
|
|
16
|
+
**FLUX bytecode conservation-law enforcement for LLM outputs.**
|
|
17
|
+
|
|
18
|
+
This is a working prototype that demonstrates conservation-law governance on AI behavior. It wraps any LLM call in a deterministic, auditable policy layer implemented as FLUX bytecode.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
User Request → LLM Call → [FLUX Conservation Validator] → Response
|
|
22
|
+
↓
|
|
23
|
+
If violation: return correction
|
|
24
|
+
If clean: return response
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The FLUX bytecode acts as a deterministic, auditable policy layer. **You can't lie to bytecode** — it doesn't have opinions, it just executes instructions.
|
|
28
|
+
|
|
29
|
+
## Why This Matters
|
|
30
|
+
|
|
31
|
+
Current AI alignment approaches rely on:
|
|
32
|
+
- **Prompt engineering** (the LLM can ignore instructions)
|
|
33
|
+
- **RLHF tuning** (opaque, hard to verify)
|
|
34
|
+
- **Output filtering** (post-hoc, not deterministic)
|
|
35
|
+
|
|
36
|
+
Conservation enforcement is different:
|
|
37
|
+
- **Deterministic**: Same input always produces the same decision
|
|
38
|
+
- **Auditable**: Every byte of policy can be inspected and verified
|
|
39
|
+
- **Immune to manipulation**: Bytecode has no opinions to argue with
|
|
40
|
+
- **Composable**: Multiple conservation laws combine into one program
|
|
41
|
+
- **Portable**: FLUX bytecode runs on Python, Rust, and JS VMs
|
|
42
|
+
|
|
43
|
+
Conservation laws are the foundation of physics. Noether's theorem connects symmetries to conservation laws. This project brings that same mathematical rigor to AI governance.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install -e .
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from conservation_enforcer import ConservationEnforcer, combined_policy
|
|
55
|
+
|
|
56
|
+
# Create a combined policy: length + repetition + category + entropy
|
|
57
|
+
policy = combined_policy(
|
|
58
|
+
max_tokens=500,
|
|
59
|
+
max_repetition=300,
|
|
60
|
+
min_overlap=100,
|
|
61
|
+
min_entropy=1500,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
enforcer = ConservationEnforcer(policy, budget=500)
|
|
65
|
+
|
|
66
|
+
# Check an LLM output
|
|
67
|
+
result = enforcer.enforce(
|
|
68
|
+
input_text="What is machine learning?",
|
|
69
|
+
output_text="Machine learning is a subset of AI that learns from data.",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
if result.allowed:
|
|
73
|
+
print(result.output)
|
|
74
|
+
else:
|
|
75
|
+
print(f"Blocked: {result.violation.reason}")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Conservation Laws
|
|
79
|
+
|
|
80
|
+
### 1. Length Budget (Information Quantity)
|
|
81
|
+
```python
|
|
82
|
+
from conservation_enforcer import length_budget_policy
|
|
83
|
+
|
|
84
|
+
policy = length_budget_policy(max_tokens=500)
|
|
85
|
+
```
|
|
86
|
+
The output cannot exceed the allocated information budget. This is analogous to energy conservation in physics — you can't output more information than you were allocated.
|
|
87
|
+
|
|
88
|
+
### 2. Repetition Limit (Information Diversity)
|
|
89
|
+
```python
|
|
90
|
+
from conservation_enforcer import repetition_policy
|
|
91
|
+
|
|
92
|
+
policy = repetition_policy(max_ratio=300) # max 30% repetition
|
|
93
|
+
```
|
|
94
|
+
The output must maintain diversity. Degenerate repetition is the informational equivalent of thermal equilibrium — a system that repeats has exhausted its information capacity.
|
|
95
|
+
|
|
96
|
+
### 3. Category Confinement (Topical Coherence)
|
|
97
|
+
```python
|
|
98
|
+
from conservation_enforcer import category_policy
|
|
99
|
+
|
|
100
|
+
policy = category_policy(min_overlap=150) # 15% word overlap required
|
|
101
|
+
```
|
|
102
|
+
The output must stay within the category/domain of the input. This prevents hallucinated content and topic drift — the output's "state" must remain in the same "potential well" as the input.
|
|
103
|
+
|
|
104
|
+
### 4. Entropy Floor (Information Density)
|
|
105
|
+
```python
|
|
106
|
+
from conservation_enforcer import entropy_policy
|
|
107
|
+
|
|
108
|
+
policy = entropy_policy(min_entropy=2000) # 2.0 bits/word minimum
|
|
109
|
+
```
|
|
110
|
+
The output must have sufficient Shannon entropy. Low entropy means the output is too predictable and not carrying enough information.
|
|
111
|
+
|
|
112
|
+
### Combined Policy (All Four Laws)
|
|
113
|
+
```python
|
|
114
|
+
from conservation_enforcer import combined_policy
|
|
115
|
+
|
|
116
|
+
policy = combined_policy(
|
|
117
|
+
max_tokens=500,
|
|
118
|
+
max_repetition=300,
|
|
119
|
+
min_overlap=100,
|
|
120
|
+
min_entropy=1500,
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Writing Custom Policies
|
|
125
|
+
|
|
126
|
+
Policies are written in FLUX assembly:
|
|
127
|
+
|
|
128
|
+
```flux
|
|
129
|
+
; Custom policy: block outputs longer than 100 tokens
|
|
130
|
+
MOVI R0, 5 ; syscall: GET_TOKEN_COUNT
|
|
131
|
+
SYSCALL
|
|
132
|
+
MOV R2, R0 ; save token count
|
|
133
|
+
|
|
134
|
+
MOVI R0, 10 ; syscall: GET_BUDGET
|
|
135
|
+
SYSCALL
|
|
136
|
+
MOV R3, R0 ; save budget
|
|
137
|
+
|
|
138
|
+
JGT R2, R3, block ; if tokens > budget → block
|
|
139
|
+
|
|
140
|
+
MOVI R0, 0 ; ALLOW
|
|
141
|
+
HALT
|
|
142
|
+
|
|
143
|
+
block:
|
|
144
|
+
MOVI R1, 1 ; reason: LENGTH_BUDGET
|
|
145
|
+
MOVI R0, 8 ; syscall: SET_VIOLATION
|
|
146
|
+
SYSCALL
|
|
147
|
+
MOVI R0, 1 ; BLOCK
|
|
148
|
+
HALT
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Compile and use:
|
|
152
|
+
```python
|
|
153
|
+
from conservation_enforcer import assemble, ConservationEnforcer
|
|
154
|
+
|
|
155
|
+
bytecode = assemble(source_code)
|
|
156
|
+
enforcer = ConservationEnforcer(bytecode, budget=100)
|
|
157
|
+
result = enforcer.enforce("question", "response")
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## FLUX ISA
|
|
161
|
+
|
|
162
|
+
The VM implements a register-based ISA with 16 registers (R0–R15):
|
|
163
|
+
|
|
164
|
+
| Format | Layout | Example |
|
|
165
|
+
|--------|--------|---------|
|
|
166
|
+
| A | `[opcode]` | `HALT` |
|
|
167
|
+
| B | `[opcode][reg]` | `INC R0` |
|
|
168
|
+
| C | `[opcode][rd][rs]` | `CMP R0, R1` |
|
|
169
|
+
| D | `[opcode][reg][off_lo][off_hi]` | `JE label` |
|
|
170
|
+
| E | `[opcode][rd][rs1][rs2]` | `IADD R0, R1, R2` |
|
|
171
|
+
|
|
172
|
+
Key instructions: `MOVI`, `MOV`, `IADD`, `ISUB`, `IMUL`, `IDIV`, `CMP`, `JE`, `JNE`, `JSGE`, `JSLT`, `SYSCALL`, `HALT`.
|
|
173
|
+
|
|
174
|
+
Pseudo-instructions for convenience: `JGE`, `JGT`, `JLE`, `JLT`.
|
|
175
|
+
|
|
176
|
+
### Syscalls
|
|
177
|
+
|
|
178
|
+
| # | Name | Returns |
|
|
179
|
+
|---|------|---------|
|
|
180
|
+
| 1 | GET_INPUT_LEN | Length of input text |
|
|
181
|
+
| 2 | GET_OUTPUT_LEN | Length of output text |
|
|
182
|
+
| 5 | GET_TOKEN_COUNT | Approximate token count |
|
|
183
|
+
| 6 | GET_REPETITION | Max word frequency ratio × 1000 |
|
|
184
|
+
| 7 | GET_CATEGORY | Input/output word overlap × 1000 |
|
|
185
|
+
| 8 | SET_VIOLATION | Sets violation flag (R1 = reason code) |
|
|
186
|
+
| 10 | GET_BUDGET | Configured information budget |
|
|
187
|
+
| 11 | GET_UNIQUE_RATIO | Unique/total words × 1000 |
|
|
188
|
+
| 12 | GET_ENTROPY | Shannon entropy × 1000 |
|
|
189
|
+
|
|
190
|
+
## Demonstration
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
python examples/demo.py
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Tests
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
python -m pytest tests/ -v
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Architecture
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
src/conservation_enforcer/
|
|
206
|
+
├── __init__.py Public API
|
|
207
|
+
├── vm.py FLUX VM (register-based bytecode interpreter)
|
|
208
|
+
├── assembler.py Two-pass FLUX assembler with label resolution
|
|
209
|
+
├── enforcer.py ConservationEnforcer class
|
|
210
|
+
└── policies/
|
|
211
|
+
└── __init__.py Pre-built conservation policies in FLUX assembly
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Related Projects
|
|
215
|
+
|
|
216
|
+
- [flux-runtime](https://github.com/SuperInstance/flux-runtime) — Full FLUX runtime (Python)
|
|
217
|
+
- [flux-core](https://github.com/SuperInstance/flux-core) — FLUX bytecode runtime (Rust)
|
|
218
|
+
- [flux-js](https://github.com/SuperInstance/flux-js) — FLUX VM (JavaScript)
|
|
219
|
+
- [conservation-law-rs](https://github.com/SuperInstance/conservation-law-rs) — Conservation laws for agent dynamics
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
MIT
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
*This is not alignment theory. This is enforcement engineering.*
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# ⚡ Conservation Enforcer
|
|
2
|
+
|
|
3
|
+
**FLUX bytecode conservation-law enforcement for LLM outputs.**
|
|
4
|
+
|
|
5
|
+
This is a working prototype that demonstrates conservation-law governance on AI behavior. It wraps any LLM call in a deterministic, auditable policy layer implemented as FLUX bytecode.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
User Request → LLM Call → [FLUX Conservation Validator] → Response
|
|
9
|
+
↓
|
|
10
|
+
If violation: return correction
|
|
11
|
+
If clean: return response
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The FLUX bytecode acts as a deterministic, auditable policy layer. **You can't lie to bytecode** — it doesn't have opinions, it just executes instructions.
|
|
15
|
+
|
|
16
|
+
## Why This Matters
|
|
17
|
+
|
|
18
|
+
Current AI alignment approaches rely on:
|
|
19
|
+
- **Prompt engineering** (the LLM can ignore instructions)
|
|
20
|
+
- **RLHF tuning** (opaque, hard to verify)
|
|
21
|
+
- **Output filtering** (post-hoc, not deterministic)
|
|
22
|
+
|
|
23
|
+
Conservation enforcement is different:
|
|
24
|
+
- **Deterministic**: Same input always produces the same decision
|
|
25
|
+
- **Auditable**: Every byte of policy can be inspected and verified
|
|
26
|
+
- **Immune to manipulation**: Bytecode has no opinions to argue with
|
|
27
|
+
- **Composable**: Multiple conservation laws combine into one program
|
|
28
|
+
- **Portable**: FLUX bytecode runs on Python, Rust, and JS VMs
|
|
29
|
+
|
|
30
|
+
Conservation laws are the foundation of physics. Noether's theorem connects symmetries to conservation laws. This project brings that same mathematical rigor to AI governance.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install -e .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from conservation_enforcer import ConservationEnforcer, combined_policy
|
|
42
|
+
|
|
43
|
+
# Create a combined policy: length + repetition + category + entropy
|
|
44
|
+
policy = combined_policy(
|
|
45
|
+
max_tokens=500,
|
|
46
|
+
max_repetition=300,
|
|
47
|
+
min_overlap=100,
|
|
48
|
+
min_entropy=1500,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
enforcer = ConservationEnforcer(policy, budget=500)
|
|
52
|
+
|
|
53
|
+
# Check an LLM output
|
|
54
|
+
result = enforcer.enforce(
|
|
55
|
+
input_text="What is machine learning?",
|
|
56
|
+
output_text="Machine learning is a subset of AI that learns from data.",
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if result.allowed:
|
|
60
|
+
print(result.output)
|
|
61
|
+
else:
|
|
62
|
+
print(f"Blocked: {result.violation.reason}")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Conservation Laws
|
|
66
|
+
|
|
67
|
+
### 1. Length Budget (Information Quantity)
|
|
68
|
+
```python
|
|
69
|
+
from conservation_enforcer import length_budget_policy
|
|
70
|
+
|
|
71
|
+
policy = length_budget_policy(max_tokens=500)
|
|
72
|
+
```
|
|
73
|
+
The output cannot exceed the allocated information budget. This is analogous to energy conservation in physics — you can't output more information than you were allocated.
|
|
74
|
+
|
|
75
|
+
### 2. Repetition Limit (Information Diversity)
|
|
76
|
+
```python
|
|
77
|
+
from conservation_enforcer import repetition_policy
|
|
78
|
+
|
|
79
|
+
policy = repetition_policy(max_ratio=300) # max 30% repetition
|
|
80
|
+
```
|
|
81
|
+
The output must maintain diversity. Degenerate repetition is the informational equivalent of thermal equilibrium — a system that repeats has exhausted its information capacity.
|
|
82
|
+
|
|
83
|
+
### 3. Category Confinement (Topical Coherence)
|
|
84
|
+
```python
|
|
85
|
+
from conservation_enforcer import category_policy
|
|
86
|
+
|
|
87
|
+
policy = category_policy(min_overlap=150) # 15% word overlap required
|
|
88
|
+
```
|
|
89
|
+
The output must stay within the category/domain of the input. This prevents hallucinated content and topic drift — the output's "state" must remain in the same "potential well" as the input.
|
|
90
|
+
|
|
91
|
+
### 4. Entropy Floor (Information Density)
|
|
92
|
+
```python
|
|
93
|
+
from conservation_enforcer import entropy_policy
|
|
94
|
+
|
|
95
|
+
policy = entropy_policy(min_entropy=2000) # 2.0 bits/word minimum
|
|
96
|
+
```
|
|
97
|
+
The output must have sufficient Shannon entropy. Low entropy means the output is too predictable and not carrying enough information.
|
|
98
|
+
|
|
99
|
+
### Combined Policy (All Four Laws)
|
|
100
|
+
```python
|
|
101
|
+
from conservation_enforcer import combined_policy
|
|
102
|
+
|
|
103
|
+
policy = combined_policy(
|
|
104
|
+
max_tokens=500,
|
|
105
|
+
max_repetition=300,
|
|
106
|
+
min_overlap=100,
|
|
107
|
+
min_entropy=1500,
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Writing Custom Policies
|
|
112
|
+
|
|
113
|
+
Policies are written in FLUX assembly:
|
|
114
|
+
|
|
115
|
+
```flux
|
|
116
|
+
; Custom policy: block outputs longer than 100 tokens
|
|
117
|
+
MOVI R0, 5 ; syscall: GET_TOKEN_COUNT
|
|
118
|
+
SYSCALL
|
|
119
|
+
MOV R2, R0 ; save token count
|
|
120
|
+
|
|
121
|
+
MOVI R0, 10 ; syscall: GET_BUDGET
|
|
122
|
+
SYSCALL
|
|
123
|
+
MOV R3, R0 ; save budget
|
|
124
|
+
|
|
125
|
+
JGT R2, R3, block ; if tokens > budget → block
|
|
126
|
+
|
|
127
|
+
MOVI R0, 0 ; ALLOW
|
|
128
|
+
HALT
|
|
129
|
+
|
|
130
|
+
block:
|
|
131
|
+
MOVI R1, 1 ; reason: LENGTH_BUDGET
|
|
132
|
+
MOVI R0, 8 ; syscall: SET_VIOLATION
|
|
133
|
+
SYSCALL
|
|
134
|
+
MOVI R0, 1 ; BLOCK
|
|
135
|
+
HALT
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Compile and use:
|
|
139
|
+
```python
|
|
140
|
+
from conservation_enforcer import assemble, ConservationEnforcer
|
|
141
|
+
|
|
142
|
+
bytecode = assemble(source_code)
|
|
143
|
+
enforcer = ConservationEnforcer(bytecode, budget=100)
|
|
144
|
+
result = enforcer.enforce("question", "response")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## FLUX ISA
|
|
148
|
+
|
|
149
|
+
The VM implements a register-based ISA with 16 registers (R0–R15):
|
|
150
|
+
|
|
151
|
+
| Format | Layout | Example |
|
|
152
|
+
|--------|--------|---------|
|
|
153
|
+
| A | `[opcode]` | `HALT` |
|
|
154
|
+
| B | `[opcode][reg]` | `INC R0` |
|
|
155
|
+
| C | `[opcode][rd][rs]` | `CMP R0, R1` |
|
|
156
|
+
| D | `[opcode][reg][off_lo][off_hi]` | `JE label` |
|
|
157
|
+
| E | `[opcode][rd][rs1][rs2]` | `IADD R0, R1, R2` |
|
|
158
|
+
|
|
159
|
+
Key instructions: `MOVI`, `MOV`, `IADD`, `ISUB`, `IMUL`, `IDIV`, `CMP`, `JE`, `JNE`, `JSGE`, `JSLT`, `SYSCALL`, `HALT`.
|
|
160
|
+
|
|
161
|
+
Pseudo-instructions for convenience: `JGE`, `JGT`, `JLE`, `JLT`.
|
|
162
|
+
|
|
163
|
+
### Syscalls
|
|
164
|
+
|
|
165
|
+
| # | Name | Returns |
|
|
166
|
+
|---|------|---------|
|
|
167
|
+
| 1 | GET_INPUT_LEN | Length of input text |
|
|
168
|
+
| 2 | GET_OUTPUT_LEN | Length of output text |
|
|
169
|
+
| 5 | GET_TOKEN_COUNT | Approximate token count |
|
|
170
|
+
| 6 | GET_REPETITION | Max word frequency ratio × 1000 |
|
|
171
|
+
| 7 | GET_CATEGORY | Input/output word overlap × 1000 |
|
|
172
|
+
| 8 | SET_VIOLATION | Sets violation flag (R1 = reason code) |
|
|
173
|
+
| 10 | GET_BUDGET | Configured information budget |
|
|
174
|
+
| 11 | GET_UNIQUE_RATIO | Unique/total words × 1000 |
|
|
175
|
+
| 12 | GET_ENTROPY | Shannon entropy × 1000 |
|
|
176
|
+
|
|
177
|
+
## Demonstration
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
python examples/demo.py
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Tests
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
python -m pytest tests/ -v
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Architecture
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
src/conservation_enforcer/
|
|
193
|
+
├── __init__.py Public API
|
|
194
|
+
├── vm.py FLUX VM (register-based bytecode interpreter)
|
|
195
|
+
├── assembler.py Two-pass FLUX assembler with label resolution
|
|
196
|
+
├── enforcer.py ConservationEnforcer class
|
|
197
|
+
└── policies/
|
|
198
|
+
└── __init__.py Pre-built conservation policies in FLUX assembly
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Related Projects
|
|
202
|
+
|
|
203
|
+
- [flux-runtime](https://github.com/SuperInstance/flux-runtime) — Full FLUX runtime (Python)
|
|
204
|
+
- [flux-core](https://github.com/SuperInstance/flux-core) — FLUX bytecode runtime (Rust)
|
|
205
|
+
- [flux-js](https://github.com/SuperInstance/flux-js) — FLUX VM (JavaScript)
|
|
206
|
+
- [conservation-law-rs](https://github.com/SuperInstance/conservation-law-rs) — Conservation laws for agent dynamics
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
MIT
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
*This is not alignment theory. This is enforcement engineering.*
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "conservation-enforcer"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "FLUX bytecode conservation-law enforcement for LLM outputs"
|
|
9
|
+
authors = [{name = "SuperInstance"}]
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
|
|
14
|
+
[project.optional-dependencies]
|
|
15
|
+
dev = ["pytest>=7.0"]
|
|
16
|
+
|
|
17
|
+
[tool.setuptools.packages.find]
|
|
18
|
+
where = ["src"]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Conservation Enforcer — FLUX bytecode governance for LLM outputs.
|
|
2
|
+
|
|
3
|
+
Implements conservation-law enforcement on AI behavior using deterministic
|
|
4
|
+
FLUX bytecode programs as policy layers.
|
|
5
|
+
|
|
6
|
+
Architecture:
|
|
7
|
+
User Request → LLM Call → [FLUX Conservation Validator] → Response
|
|
8
|
+
↓
|
|
9
|
+
If violation: return correction
|
|
10
|
+
If clean: return response
|
|
11
|
+
|
|
12
|
+
The FLUX bytecode acts as a deterministic, auditable policy layer.
|
|
13
|
+
You can't lie to bytecode — it doesn't have opinions, it just executes instructions.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from .vm import VM, Op, Syscall, RegisterFile, Memory
|
|
17
|
+
from .assembler import assemble
|
|
18
|
+
from .enforcer import ConservationEnforcer, EnforcementResult, Violation
|
|
19
|
+
from .policies import (
|
|
20
|
+
length_budget_policy,
|
|
21
|
+
repetition_policy,
|
|
22
|
+
category_policy,
|
|
23
|
+
combined_policy,
|
|
24
|
+
entropy_policy,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__version__ = "0.1.0"
|
|
28
|
+
__author__ = "SuperInstance"
|
|
29
|
+
__license__ = "MIT"
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"VM",
|
|
33
|
+
"Op",
|
|
34
|
+
"Syscall",
|
|
35
|
+
"RegisterFile",
|
|
36
|
+
"Memory",
|
|
37
|
+
"assemble",
|
|
38
|
+
"ConservationEnforcer",
|
|
39
|
+
"EnforcementResult",
|
|
40
|
+
"Violation",
|
|
41
|
+
"length_budget_policy",
|
|
42
|
+
"repetition_policy",
|
|
43
|
+
"category_policy",
|
|
44
|
+
"combined_policy",
|
|
45
|
+
"entropy_policy",
|
|
46
|
+
]
|