morphism-engine 3.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.
- morphism_engine-3.1.0/PKG-INFO +261 -0
- morphism_engine-3.1.0/README.md +235 -0
- morphism_engine-3.1.0/pyproject.toml +48 -0
- morphism_engine-3.1.0/setup.cfg +4 -0
- morphism_engine-3.1.0/src/morphism/__init__.py +3 -0
- morphism_engine-3.1.0/src/morphism/ai/__init__.py +0 -0
- morphism_engine-3.1.0/src/morphism/ai/synthesizer.py +163 -0
- morphism_engine-3.1.0/src/morphism/cli/__init__.py +0 -0
- morphism_engine-3.1.0/src/morphism/cli/shell.py +240 -0
- morphism_engine-3.1.0/src/morphism/cli/tui.py +397 -0
- morphism_engine-3.1.0/src/morphism/config.py +46 -0
- morphism_engine-3.1.0/src/morphism/core/__init__.py +0 -0
- morphism_engine-3.1.0/src/morphism/core/cache.py +112 -0
- morphism_engine-3.1.0/src/morphism/core/inference.py +62 -0
- morphism_engine-3.1.0/src/morphism/core/native_node.py +100 -0
- morphism_engine-3.1.0/src/morphism/core/node.py +59 -0
- morphism_engine-3.1.0/src/morphism/core/pipeline.py +333 -0
- morphism_engine-3.1.0/src/morphism/core/schemas.py +86 -0
- morphism_engine-3.1.0/src/morphism/exceptions.py +28 -0
- morphism_engine-3.1.0/src/morphism/math/__init__.py +0 -0
- morphism_engine-3.1.0/src/morphism/math/z3_verifier.py +198 -0
- morphism_engine-3.1.0/src/morphism/utils/__init__.py +0 -0
- morphism_engine-3.1.0/src/morphism/utils/logger.py +54 -0
- morphism_engine-3.1.0/src/morphism_engine.egg-info/PKG-INFO +261 -0
- morphism_engine-3.1.0/src/morphism_engine.egg-info/SOURCES.txt +35 -0
- morphism_engine-3.1.0/src/morphism_engine.egg-info/dependency_links.txt +1 -0
- morphism_engine-3.1.0/src/morphism_engine.egg-info/entry_points.txt +4 -0
- morphism_engine-3.1.0/src/morphism_engine.egg-info/requires.txt +9 -0
- morphism_engine-3.1.0/src/morphism_engine.egg-info/top_level.txt +1 -0
- morphism_engine-3.1.0/tests/test_phase1.py +113 -0
- morphism_engine-3.1.0/tests/test_phase11_tui.py +440 -0
- morphism_engine-3.1.0/tests/test_phase2.py +24 -0
- morphism_engine-3.1.0/tests/test_phase3_4.py +71 -0
- morphism_engine-3.1.0/tests/test_phase5_local.py +58 -0
- morphism_engine-3.1.0/tests/test_phase6_shell.py +75 -0
- morphism_engine-3.1.0/tests/test_phase8_native.py +239 -0
- morphism_engine-3.1.0/tests/test_phase9_10.py +355 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: morphism-engine
|
|
3
|
+
Version: 3.1.0
|
|
4
|
+
Summary: A self-healing, formally verified Category Theory shell.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Keywords: category-theory,pipeline,z3,formal-verification,tui,ollama
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: Environment :: Console
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: z3-solver>=4.12
|
|
19
|
+
Requires-Dist: aiohttp>=3.9
|
|
20
|
+
Requires-Dist: requests>=2.31
|
|
21
|
+
Requires-Dist: textual>=0.50
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
25
|
+
Requires-Dist: textual[dev]>=0.50; extra == "dev"
|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<strong>Morphism Engine</strong><br>
|
|
29
|
+
<em>A self-healing, formally verified Category Theory shell.</em>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<img src="https://img.shields.io/badge/tests-73%20passed-brightgreen" alt="Tests">
|
|
34
|
+
<img src="https://img.shields.io/badge/python-3.11%2B-blue" alt="Python 3.11+">
|
|
35
|
+
<img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License">
|
|
36
|
+
<img src="https://img.shields.io/badge/prover-Z3%20SMT-purple" alt="Z3 SMT">
|
|
37
|
+
<img src="https://img.shields.io/badge/LLM-Ollama-orange" alt="Ollama">
|
|
38
|
+
<img src="https://img.shields.io/badge/TUI-Textual-cyan" alt="Textual">
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## The Problem
|
|
44
|
+
|
|
45
|
+
POSIX pipes (`|`) are **untyped**. When you write:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
cat users.json | tr ',' '\n' | wc -l
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Nothing guarantees the output of `tr` is valid input for `wc -l` in any meaningful sense. One malformed byte and the entire pipeline fails silently — or worse, produces wrong results. There are no schemas, no contracts, and no safety nets.
|
|
52
|
+
|
|
53
|
+
## The Solution
|
|
54
|
+
|
|
55
|
+
**Morphism Engine** replaces "hope-based piping" with **mathematically guaranteed type safety**.
|
|
56
|
+
|
|
57
|
+
Every node in a Morphism pipeline carries a **typed schema** (e.g., `Int_0_to_100`, `Float_Normalized`, `JSON_Object`). When two adjacent nodes disagree on types, the engine:
|
|
58
|
+
|
|
59
|
+
1. **Detects** the mismatch at link-time.
|
|
60
|
+
2. **Synthesises** a bridge functor using a local **Ollama** LLM.
|
|
61
|
+
3. **Proves** the bridge is safe via the **Z3 SMT theorem prover** — if Z3 can't prove it, the bridge is rejected. No exceptions.
|
|
62
|
+
4. **Caches** the proven functor in a zero-latency **SQLite store** so it's never re-synthesised.
|
|
63
|
+
5. **Executes** the repaired pipeline end-to-end.
|
|
64
|
+
|
|
65
|
+
The result: a shell where **every pipe connection is a formally verified morphism** in the category-theoretic sense.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Features
|
|
70
|
+
|
|
71
|
+
| Feature | Description |
|
|
72
|
+
|---|---|
|
|
73
|
+
| **Self-Healing Pipelines** | Schema mismatches are autonomously repaired by AI synthesis + Z3 proof. |
|
|
74
|
+
| **Dynamic Schema Inference** | Native subprocesses (`echo`, `curl`, `python -c`) get their output schema inferred at runtime — JSON, CSV, or plaintext. |
|
|
75
|
+
| **Zero-Latency Functor Cache** | SQLite WAL-mode cache with SHA-256 keying. A proven bridge is never synthesised twice. |
|
|
76
|
+
| **DAG Branching (`\|+`)** | Fan-out a single node to multiple children with `emit_raw \|+ (render_float, to_sql)`. Parallel execution via `asyncio.gather`. |
|
|
77
|
+
| **Reactive Textual TUI** | 3-column layout: searchable Tool Catalog, live DAG Topographer tree, node Inspector, and streaming Telemetry log. |
|
|
78
|
+
| **Intelligent Autocomplete** | Pipe-aware command suggestions that reset after every `\|` token. |
|
|
79
|
+
| **Non-Blocking Execution** | Pipeline runs inside a Textual `@work` worker — the UI never freezes, even during long Ollama calls. |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
### 1. Clone & install
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
git clone https://github.com/your-org/morphism-engine.git
|
|
89
|
+
cd morphism-engine
|
|
90
|
+
pip install -e ".[dev]"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
This installs three console commands:
|
|
94
|
+
|
|
95
|
+
| Command | Interface |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `morphism-engine` | Textual TUI (recommended) |
|
|
98
|
+
| `morphism-tui` | Textual TUI (alias) |
|
|
99
|
+
| `morphism` | Classic `cmd.Cmd` REPL |
|
|
100
|
+
|
|
101
|
+
### 2. Pull the Ollama model
|
|
102
|
+
|
|
103
|
+
The self-healing synthesiser requires a local LLM. Install [Ollama](https://ollama.com), then:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
ollama pull qwen2.5-coder:1.5b
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3. Verify
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pytest tests/ -v
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
All **73 tests** should pass.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Quick Start
|
|
120
|
+
|
|
121
|
+
### Launch the TUI
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
morphism-engine
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Run a linear pipeline
|
|
128
|
+
|
|
129
|
+
Type in the command bar:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
emit_raw | render_float
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`emit_raw` outputs an `Int_0_to_100` value. `render_float` expects `Float_Normalized`. The engine detects the mismatch, synthesises a bridge (`x / 100.0`), proves it with Z3, and executes the full chain.
|
|
136
|
+
|
|
137
|
+
### Fan-out with DAG branching
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
emit_raw |+ (render_float, render_float)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The output of `emit_raw` fans out to two parallel `render_float` nodes, executed concurrently.
|
|
144
|
+
|
|
145
|
+
### Run native subprocesses
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
echo {"name":"Ada"} | python -c "import sys,json; print(json.load(sys.stdin)['name'])"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Morphism infers `JSON_Object` for the first node and `Plaintext` for the second, auto-bridging as needed.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Architecture
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
Morphism Engine — Under the Hood
|
|
159
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
160
|
+
│ │
|
|
161
|
+
│ User Input │
|
|
162
|
+
│ │ │
|
|
163
|
+
│ ▼ │
|
|
164
|
+
│ ┌─────────┐ ┌──────────────┐ ┌─────────────┐ │
|
|
165
|
+
│ │ Parse │────▶│ Link Nodes │────▶│ Schema │ │
|
|
166
|
+
│ │ (| |+) │ │ (DAG build) │ │ Check │ │
|
|
167
|
+
│ └─────────┘ └──────────────┘ └──────┬──────┘ │
|
|
168
|
+
│ │ │
|
|
169
|
+
│ ┌────────────────┼────────────────┐ │
|
|
170
|
+
│ │ Match? │ Mismatch? │ │
|
|
171
|
+
│ ▼ ▼ │ │
|
|
172
|
+
│ ┌─────────┐ ┌─────────────┐ │ │
|
|
173
|
+
│ │ Exec │ │ Cache Check │ │ │
|
|
174
|
+
│ │ as-is │ │ (SQLite) │ │ │
|
|
175
|
+
│ └─────────┘ └──────┬──────┘ │ │
|
|
176
|
+
│ │ │ │
|
|
177
|
+
│ ┌───────────┼──────────┐ │ │
|
|
178
|
+
│ │ HIT │ MISS │ │ │
|
|
179
|
+
│ ▼ ▼ │ │ │
|
|
180
|
+
│ ┌──────────┐ ┌──────────┐ │ │ │
|
|
181
|
+
│ │ Load │ │ AI Synth │ │ │ │
|
|
182
|
+
│ │ Cached │ │ (Ollama) │ │ │ │
|
|
183
|
+
│ │ Functor │ └────┬─────┘ │ │ │
|
|
184
|
+
│ └────┬─────┘ │ │ │ │
|
|
185
|
+
│ │ ▼ │ │ │
|
|
186
|
+
│ │ ┌──────────┐ │ │ │
|
|
187
|
+
│ │ │ Z3 Proof │ │ │ │
|
|
188
|
+
│ │ │ (SMT) │ │ │ │
|
|
189
|
+
│ │ └────┬─────┘ │ │ │
|
|
190
|
+
│ │ │ │ │ │
|
|
191
|
+
│ │ ┌──────┴──────┐ │ │ │
|
|
192
|
+
│ │ │PASS? FAIL? │ │ │ │
|
|
193
|
+
│ │ ▼ ▼ │ │ │ │
|
|
194
|
+
│ │ Cache Retry/ │ │ │ │
|
|
195
|
+
│ │ Store Reject │ │ │ │
|
|
196
|
+
│ │ │ │ │ │ │
|
|
197
|
+
│ ▼ ▼ │ │ │ │
|
|
198
|
+
│ ┌──────────────┐ │ │ │ │
|
|
199
|
+
│ │ JIT Execute │ │ │ │ │
|
|
200
|
+
│ │ (pipeline) │ │ │ │ │
|
|
201
|
+
│ └──────┬───────┘ │ │ │ │
|
|
202
|
+
│ │ │ │ │ │
|
|
203
|
+
│ ▼ │ │ │ │
|
|
204
|
+
│ ┌──────────┐ │ │ │ │
|
|
205
|
+
│ │ Output │ │ │ │ │
|
|
206
|
+
│ └──────────┘ │ │ │ │
|
|
207
|
+
│ │ │ │ │
|
|
208
|
+
│ ───────────────────────┘────┘─────┘ │
|
|
209
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Key modules
|
|
213
|
+
|
|
214
|
+
| Module | Purpose |
|
|
215
|
+
|---|---|
|
|
216
|
+
| `morphism.core.pipeline` | Async DAG executor with `asyncio.gather` fan-out |
|
|
217
|
+
| `morphism.core.node` | `FunctorNode` — DAG vertex with typed schemas |
|
|
218
|
+
| `morphism.core.schemas` | `Schema` dataclass + built-in instances |
|
|
219
|
+
| `morphism.core.cache` | `FunctorCache` — SQLite WAL + SHA-256 keying |
|
|
220
|
+
| `morphism.core.native_node` | `NativeCommandNode` — OS subprocess wrapper |
|
|
221
|
+
| `morphism.core.inference` | Runtime schema inference (JSON / CSV / Plaintext) |
|
|
222
|
+
| `morphism.ai.synthesizer` | Ollama LLM client for bridge functor generation |
|
|
223
|
+
| `morphism.math.z3_verifier` | Z3 SMT proof of generated functors |
|
|
224
|
+
| `morphism.cli.tui` | Textual TUI (recommended interface) |
|
|
225
|
+
| `morphism.cli.shell` | Classic `cmd.Cmd` REPL (fallback) |
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Testing
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Run the full suite
|
|
233
|
+
pytest tests/ -v
|
|
234
|
+
|
|
235
|
+
# Run only TUI tests
|
|
236
|
+
pytest tests/test_phase11_tui.py -v
|
|
237
|
+
|
|
238
|
+
# Run only cache + DAG tests
|
|
239
|
+
pytest tests/test_phase9_10.py -v
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**73 tests** across 8 test files covering schema verification, self-healing synthesis, native subprocess integration, SQLite cache lifecycle, DAG branching, and headless TUI pilot tests.
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Requirements
|
|
247
|
+
|
|
248
|
+
| Dependency | Version | Purpose |
|
|
249
|
+
|---|---|---|
|
|
250
|
+
| Python | ≥ 3.11 | Runtime |
|
|
251
|
+
| z3-solver | ≥ 4.12 | Formal verification of bridge functors |
|
|
252
|
+
| aiohttp | ≥ 3.9 | Async HTTP client for Ollama |
|
|
253
|
+
| requests | ≥ 2.31 | Sync HTTP fallback |
|
|
254
|
+
| textual | ≥ 0.50 | Reactive terminal UI framework |
|
|
255
|
+
| Ollama | latest | Local LLM inference server |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>Morphism Engine</strong><br>
|
|
3
|
+
<em>A self-healing, formally verified Category Theory shell.</em>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<img src="https://img.shields.io/badge/tests-73%20passed-brightgreen" alt="Tests">
|
|
8
|
+
<img src="https://img.shields.io/badge/python-3.11%2B-blue" alt="Python 3.11+">
|
|
9
|
+
<img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License">
|
|
10
|
+
<img src="https://img.shields.io/badge/prover-Z3%20SMT-purple" alt="Z3 SMT">
|
|
11
|
+
<img src="https://img.shields.io/badge/LLM-Ollama-orange" alt="Ollama">
|
|
12
|
+
<img src="https://img.shields.io/badge/TUI-Textual-cyan" alt="Textual">
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## The Problem
|
|
18
|
+
|
|
19
|
+
POSIX pipes (`|`) are **untyped**. When you write:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cat users.json | tr ',' '\n' | wc -l
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Nothing guarantees the output of `tr` is valid input for `wc -l` in any meaningful sense. One malformed byte and the entire pipeline fails silently — or worse, produces wrong results. There are no schemas, no contracts, and no safety nets.
|
|
26
|
+
|
|
27
|
+
## The Solution
|
|
28
|
+
|
|
29
|
+
**Morphism Engine** replaces "hope-based piping" with **mathematically guaranteed type safety**.
|
|
30
|
+
|
|
31
|
+
Every node in a Morphism pipeline carries a **typed schema** (e.g., `Int_0_to_100`, `Float_Normalized`, `JSON_Object`). When two adjacent nodes disagree on types, the engine:
|
|
32
|
+
|
|
33
|
+
1. **Detects** the mismatch at link-time.
|
|
34
|
+
2. **Synthesises** a bridge functor using a local **Ollama** LLM.
|
|
35
|
+
3. **Proves** the bridge is safe via the **Z3 SMT theorem prover** — if Z3 can't prove it, the bridge is rejected. No exceptions.
|
|
36
|
+
4. **Caches** the proven functor in a zero-latency **SQLite store** so it's never re-synthesised.
|
|
37
|
+
5. **Executes** the repaired pipeline end-to-end.
|
|
38
|
+
|
|
39
|
+
The result: a shell where **every pipe connection is a formally verified morphism** in the category-theoretic sense.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
| Feature | Description |
|
|
46
|
+
|---|---|
|
|
47
|
+
| **Self-Healing Pipelines** | Schema mismatches are autonomously repaired by AI synthesis + Z3 proof. |
|
|
48
|
+
| **Dynamic Schema Inference** | Native subprocesses (`echo`, `curl`, `python -c`) get their output schema inferred at runtime — JSON, CSV, or plaintext. |
|
|
49
|
+
| **Zero-Latency Functor Cache** | SQLite WAL-mode cache with SHA-256 keying. A proven bridge is never synthesised twice. |
|
|
50
|
+
| **DAG Branching (`\|+`)** | Fan-out a single node to multiple children with `emit_raw \|+ (render_float, to_sql)`. Parallel execution via `asyncio.gather`. |
|
|
51
|
+
| **Reactive Textual TUI** | 3-column layout: searchable Tool Catalog, live DAG Topographer tree, node Inspector, and streaming Telemetry log. |
|
|
52
|
+
| **Intelligent Autocomplete** | Pipe-aware command suggestions that reset after every `\|` token. |
|
|
53
|
+
| **Non-Blocking Execution** | Pipeline runs inside a Textual `@work` worker — the UI never freezes, even during long Ollama calls. |
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
### 1. Clone & install
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/your-org/morphism-engine.git
|
|
63
|
+
cd morphism-engine
|
|
64
|
+
pip install -e ".[dev]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This installs three console commands:
|
|
68
|
+
|
|
69
|
+
| Command | Interface |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `morphism-engine` | Textual TUI (recommended) |
|
|
72
|
+
| `morphism-tui` | Textual TUI (alias) |
|
|
73
|
+
| `morphism` | Classic `cmd.Cmd` REPL |
|
|
74
|
+
|
|
75
|
+
### 2. Pull the Ollama model
|
|
76
|
+
|
|
77
|
+
The self-healing synthesiser requires a local LLM. Install [Ollama](https://ollama.com), then:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
ollama pull qwen2.5-coder:1.5b
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. Verify
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pytest tests/ -v
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
All **73 tests** should pass.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Quick Start
|
|
94
|
+
|
|
95
|
+
### Launch the TUI
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
morphism-engine
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Run a linear pipeline
|
|
102
|
+
|
|
103
|
+
Type in the command bar:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
emit_raw | render_float
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`emit_raw` outputs an `Int_0_to_100` value. `render_float` expects `Float_Normalized`. The engine detects the mismatch, synthesises a bridge (`x / 100.0`), proves it with Z3, and executes the full chain.
|
|
110
|
+
|
|
111
|
+
### Fan-out with DAG branching
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
emit_raw |+ (render_float, render_float)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The output of `emit_raw` fans out to two parallel `render_float` nodes, executed concurrently.
|
|
118
|
+
|
|
119
|
+
### Run native subprocesses
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
echo {"name":"Ada"} | python -c "import sys,json; print(json.load(sys.stdin)['name'])"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Morphism infers `JSON_Object` for the first node and `Plaintext` for the second, auto-bridging as needed.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Architecture
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
Morphism Engine — Under the Hood
|
|
133
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
134
|
+
│ │
|
|
135
|
+
│ User Input │
|
|
136
|
+
│ │ │
|
|
137
|
+
│ ▼ │
|
|
138
|
+
│ ┌─────────┐ ┌──────────────┐ ┌─────────────┐ │
|
|
139
|
+
│ │ Parse │────▶│ Link Nodes │────▶│ Schema │ │
|
|
140
|
+
│ │ (| |+) │ │ (DAG build) │ │ Check │ │
|
|
141
|
+
│ └─────────┘ └──────────────┘ └──────┬──────┘ │
|
|
142
|
+
│ │ │
|
|
143
|
+
│ ┌────────────────┼────────────────┐ │
|
|
144
|
+
│ │ Match? │ Mismatch? │ │
|
|
145
|
+
│ ▼ ▼ │ │
|
|
146
|
+
│ ┌─────────┐ ┌─────────────┐ │ │
|
|
147
|
+
│ │ Exec │ │ Cache Check │ │ │
|
|
148
|
+
│ │ as-is │ │ (SQLite) │ │ │
|
|
149
|
+
│ └─────────┘ └──────┬──────┘ │ │
|
|
150
|
+
│ │ │ │
|
|
151
|
+
│ ┌───────────┼──────────┐ │ │
|
|
152
|
+
│ │ HIT │ MISS │ │ │
|
|
153
|
+
│ ▼ ▼ │ │ │
|
|
154
|
+
│ ┌──────────┐ ┌──────────┐ │ │ │
|
|
155
|
+
│ │ Load │ │ AI Synth │ │ │ │
|
|
156
|
+
│ │ Cached │ │ (Ollama) │ │ │ │
|
|
157
|
+
│ │ Functor │ └────┬─────┘ │ │ │
|
|
158
|
+
│ └────┬─────┘ │ │ │ │
|
|
159
|
+
│ │ ▼ │ │ │
|
|
160
|
+
│ │ ┌──────────┐ │ │ │
|
|
161
|
+
│ │ │ Z3 Proof │ │ │ │
|
|
162
|
+
│ │ │ (SMT) │ │ │ │
|
|
163
|
+
│ │ └────┬─────┘ │ │ │
|
|
164
|
+
│ │ │ │ │ │
|
|
165
|
+
│ │ ┌──────┴──────┐ │ │ │
|
|
166
|
+
│ │ │PASS? FAIL? │ │ │ │
|
|
167
|
+
│ │ ▼ ▼ │ │ │ │
|
|
168
|
+
│ │ Cache Retry/ │ │ │ │
|
|
169
|
+
│ │ Store Reject │ │ │ │
|
|
170
|
+
│ │ │ │ │ │ │
|
|
171
|
+
│ ▼ ▼ │ │ │ │
|
|
172
|
+
│ ┌──────────────┐ │ │ │ │
|
|
173
|
+
│ │ JIT Execute │ │ │ │ │
|
|
174
|
+
│ │ (pipeline) │ │ │ │ │
|
|
175
|
+
│ └──────┬───────┘ │ │ │ │
|
|
176
|
+
│ │ │ │ │ │
|
|
177
|
+
│ ▼ │ │ │ │
|
|
178
|
+
│ ┌──────────┐ │ │ │ │
|
|
179
|
+
│ │ Output │ │ │ │ │
|
|
180
|
+
│ └──────────┘ │ │ │ │
|
|
181
|
+
│ │ │ │ │
|
|
182
|
+
│ ───────────────────────┘────┘─────┘ │
|
|
183
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Key modules
|
|
187
|
+
|
|
188
|
+
| Module | Purpose |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `morphism.core.pipeline` | Async DAG executor with `asyncio.gather` fan-out |
|
|
191
|
+
| `morphism.core.node` | `FunctorNode` — DAG vertex with typed schemas |
|
|
192
|
+
| `morphism.core.schemas` | `Schema` dataclass + built-in instances |
|
|
193
|
+
| `morphism.core.cache` | `FunctorCache` — SQLite WAL + SHA-256 keying |
|
|
194
|
+
| `morphism.core.native_node` | `NativeCommandNode` — OS subprocess wrapper |
|
|
195
|
+
| `morphism.core.inference` | Runtime schema inference (JSON / CSV / Plaintext) |
|
|
196
|
+
| `morphism.ai.synthesizer` | Ollama LLM client for bridge functor generation |
|
|
197
|
+
| `morphism.math.z3_verifier` | Z3 SMT proof of generated functors |
|
|
198
|
+
| `morphism.cli.tui` | Textual TUI (recommended interface) |
|
|
199
|
+
| `morphism.cli.shell` | Classic `cmd.Cmd` REPL (fallback) |
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Testing
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Run the full suite
|
|
207
|
+
pytest tests/ -v
|
|
208
|
+
|
|
209
|
+
# Run only TUI tests
|
|
210
|
+
pytest tests/test_phase11_tui.py -v
|
|
211
|
+
|
|
212
|
+
# Run only cache + DAG tests
|
|
213
|
+
pytest tests/test_phase9_10.py -v
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**73 tests** across 8 test files covering schema verification, self-healing synthesis, native subprocess integration, SQLite cache lifecycle, DAG branching, and headless TUI pilot tests.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Requirements
|
|
221
|
+
|
|
222
|
+
| Dependency | Version | Purpose |
|
|
223
|
+
|---|---|---|
|
|
224
|
+
| Python | ≥ 3.11 | Runtime |
|
|
225
|
+
| z3-solver | ≥ 4.12 | Formal verification of bridge functors |
|
|
226
|
+
| aiohttp | ≥ 3.9 | Async HTTP client for Ollama |
|
|
227
|
+
| requests | ≥ 2.31 | Sync HTTP fallback |
|
|
228
|
+
| textual | ≥ 0.50 | Reactive terminal UI framework |
|
|
229
|
+
| Ollama | latest | Local LLM inference server |
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "morphism-engine"
|
|
7
|
+
version = "3.1.0"
|
|
8
|
+
description = "A self-healing, formally verified Category Theory shell."
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
keywords = ["category-theory", "pipeline", "z3", "formal-verification", "tui", "ollama"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 4 - Beta",
|
|
14
|
+
"Environment :: Console",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Topic :: Software Development :: Libraries",
|
|
22
|
+
]
|
|
23
|
+
readme = "README.md"
|
|
24
|
+
dependencies = [
|
|
25
|
+
"z3-solver>=4.12",
|
|
26
|
+
"aiohttp>=3.9",
|
|
27
|
+
"requests>=2.31",
|
|
28
|
+
"textual>=0.50",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=7.4",
|
|
34
|
+
"pytest-asyncio>=0.23",
|
|
35
|
+
"textual[dev]>=0.50",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
morphism = "morphism.cli.shell:main"
|
|
40
|
+
morphism-tui = "morphism.cli.tui:main"
|
|
41
|
+
morphism-engine = "morphism.cli.tui:main"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
asyncio_mode = "auto"
|
|
48
|
+
testpaths = ["tests"]
|
|
File without changes
|