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3 |
+
**Complete specification-to-execution trace. Every step names an actual file.**
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## The Actual Workflow
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
HyperKittyConstraintDSL.xml (specification)
|
| 11 |
+
β
|
| 12 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 13 |
+
β β
|
| 14 |
+
xslt/constraint-dsl-to-rust.xsl hyperkitty_dsl/parser.py
|
| 15 |
+
(XSLT transform) (Python parser)
|
| 16 |
+
β β
|
| 17 |
+
β β
|
| 18 |
+
Rust source code HKGraph { nodes, edges,
|
| 19 |
+
- Agent struct constraints, entropy_bound }
|
| 20 |
+
- UniverseLedger.step() β
|
| 21 |
+
- validity_predicate( β
|
| 22 |
+
entropy_nats <= 0.20 constraint_graph_svg.py
|
| 23 |
+
proof_valid) - Kahn's topological sort
|
| 24 |
+
β - pipeline dict (execution order)
|
| 25 |
+
β - SVG visualization
|
| 26 |
+
cargo build β
|
| 27 |
+
β β
|
| 28 |
+
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββ
|
| 29 |
+
β
|
| 30 |
+
SovereignEntropyEngine
|
| 31 |
+
(entropy vector per token)
|
| 32 |
+
β
|
| 33 |
+
β
|
| 34 |
+
ConstraintPass.validate(entropy)
|
| 35 |
+
(entropy <= 0.20 gate)
|
| 36 |
+
β
|
| 37 |
+
pass? βββ€ββ fail? β HALT
|
| 38 |
+
β
|
| 39 |
+
MachineCodeSelector.select(entropy, result)
|
| 40 |
+
(maps entropy to x86-64 op)
|
| 41 |
+
β
|
| 42 |
+
β
|
| 43 |
+
SovereignVM.run(program)
|
| 44 |
+
β
|
| 45 |
+
β
|
| 46 |
+
WORM seal (SHA-256 append-only)
|
| 47 |
+
β
|
| 48 |
+
β
|
| 49 |
+
Result + receipt
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## Phase-by-Phase Trace
|
| 55 |
+
|
| 56 |
+
### Phase 1: Specification
|
| 57 |
+
|
| 58 |
+
**Input:** XML file in one of three schemas:
|
| 59 |
+
- `ConstraintGraph` (nodes, edges, DAG structure)
|
| 60 |
+
- `HyperKittyConstraintDSL` (full pipeline spec with agents, glyphs, entropy bounds)
|
| 61 |
+
- `SymbolicLedgerAlgebra` / `QLGFamily` (algebraic type specifications)
|
| 62 |
+
|
| 63 |
+
**Files produced:** XML file on disk
|
| 64 |
+
|
| 65 |
+
**Deterministic:** Yes (manually authored)
|
| 66 |
+
|
| 67 |
+
**Validated:** Not yet β validation happens at next stage
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
### Phase 2: Meta-Program Execution
|
| 72 |
+
|
| 73 |
+
**Input:** XML specification file
|
| 74 |
+
|
| 75 |
+
**Transformation A (XSLT):**
|
| 76 |
+
```
|
| 77 |
+
xslt/constraint-dsl-to-rust.xsl + HyperKittyConstraintDSL.xml
|
| 78 |
+
β [xsltproc or Saxon]
|
| 79 |
+
β UniverseLedger.rs (Rust source, AUTO-GENERATED comment)
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
The generated `validity_predicate`:
|
| 83 |
+
```rust
|
| 84 |
+
pub fn validity_predicate(entry: &JournalEntry) -> bool {
|
| 85 |
+
entry.delta_a + entry.delta_e == entry.delta_l + entry.delta_r // balance
|
| 86 |
+
&& entry.entropy_nats <= 0.20 // entropy bound
|
| 87 |
+
&& entry.proof_valid // proof gate
|
| 88 |
+
}
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
The `0.20` comes from `<EntropyBound>` in the XML. Changing the XML changes the generated code.
|
| 92 |
+
|
| 93 |
+
**Transformation B (Python):**
|
| 94 |
+
```
|
| 95 |
+
hyperkitty_dsl/parser.py + HyperKittyConstraintDSL.xml
|
| 96 |
+
β HKGraph { nodes, edges, constraints, entropy_bound=0.20 }
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
**Transformation C (XSLT β C header):**
|
| 100 |
+
```
|
| 101 |
+
generated/generate-native-config.xsl + QUANTUM-KITTY XML
|
| 102 |
+
β native/include/hyperkitty/generated_config.h
|
| 103 |
+
/* GENERATED FILE β do not edit by hand */
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
**Validated:** Yes (XSLT structural validation, entropy bound preservation baked in)
|
| 107 |
+
|
| 108 |
+
**Deterministic:** Yes (pure XSLT transforms)
|
| 109 |
+
|
| 110 |
+
---
|
| 111 |
+
|
| 112 |
+
### Phase 3: DAG Construction
|
| 113 |
+
|
| 114 |
+
**Input:** XML graph β Python parser output
|
| 115 |
+
|
| 116 |
+
**Program:** `sovereign-xml-compiler/constraint_graph_svg.py`
|
| 117 |
+
|
| 118 |
+
**Transformation:**
|
| 119 |
+
```python
|
| 120 |
+
nodes, edges = _parse_graph_xml(xml_source)
|
| 121 |
+
pipeline = _topological_sort(nodes, edges) # Kahn's algorithm
|
| 122 |
+
# Raises ValueError if cycle detected
|
| 123 |
+
svg = _render_svg(nodes, edges, pipeline)
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
**Output:**
|
| 127 |
+
1. `pipeline = ["input", "memory", "retrieval", "transform", "constraint", "proof", "output"]`
|
| 128 |
+
(the execution order β this IS the executable artifact)
|
| 129 |
+
2. SVG visualization file
|
| 130 |
+
|
| 131 |
+
**Validated:** Cycle detection (raises if not a DAG)
|
| 132 |
+
|
| 133 |
+
**Deterministic:** Yes
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
### Phase 4: Entropy-Based Compilation
|
| 138 |
+
|
| 139 |
+
**Input:** String tokens (agent operations, kernel names)
|
| 140 |
+
|
| 141 |
+
**Program:** `sovereign-shadow-compiler/engine/entropy_engine.py`
|
| 142 |
+
|
| 143 |
+
```python
|
| 144 |
+
engine = SovereignEntropyEngine(kernel_map)
|
| 145 |
+
entropy_vector = engine.calculate_entropy_vector(tokens)
|
| 146 |
+
# entropy_vector: List[complex] β one value per token
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
The entropy vector encodes the input as complex activations over a sparse shadow tree seeded with phase angles `exp(2Οi Β· idx/n)`.
|
| 150 |
+
|
| 151 |
+
**Validated:**
|
| 152 |
+
```python
|
| 153 |
+
constraint = ConstraintPass()
|
| 154 |
+
result = constraint.validate(entropy) # checks each |e| <= threshold
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
**Deterministic:** Yes (same input, same phase angles, same output)
|
| 158 |
+
|
| 159 |
+
---
|
| 160 |
+
|
| 161 |
+
### Phase 5: Machine Code Selection
|
| 162 |
+
|
| 163 |
+
**Input:** Entropy vector + constraint result
|
| 164 |
+
|
| 165 |
+
**Program:** `sovereign-shadow-compiler/codegen/selector.py`
|
| 166 |
+
|
| 167 |
+
```python
|
| 168 |
+
op = selector.select(entropy, result)
|
| 169 |
+
# maps abs(entropy.real) % len(KERNEL_MAP) β x86-64 opcode name
|
| 170 |
+
kernel_bytes = selector.emit(op)
|
| 171 |
+
# returns raw bytes for the selected operation
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
**KERNEL_MAP:** operations like `MOV`, `LOOP`, `HALT`
|
| 175 |
+
|
| 176 |
+
**Output:** x86-64 byte sequence + operation name
|
| 177 |
+
|
| 178 |
+
---
|
| 179 |
+
|
| 180 |
+
### Phase 6: VM Execution
|
| 181 |
+
|
| 182 |
+
**Input:** Machine program `[{"op": "MOV", "reg": "RDI", "imm": n}, {"op": "LOOP", ...}, {"op": "HALT"}]`
|
| 183 |
+
|
| 184 |
+
**Program:** `sovereign-shadow-compiler/vm/sovereign_vm.py`
|
| 185 |
+
|
| 186 |
+
**Output:** `vm_result` dict
|
| 187 |
+
|
| 188 |
+
---
|
| 189 |
+
|
| 190 |
+
### Phase 7: WORM Sealing
|
| 191 |
+
|
| 192 |
+
**Program:** `bob-orchestrator/core/bob.mjs` `worm.seal()`
|
| 193 |
+
|
| 194 |
+
```javascript
|
| 195 |
+
const raw = JSON.stringify({ label, payload, meta, ts, prev })
|
| 196 |
+
const seal = createHash('sha256').update(raw).digest('hex')
|
| 197 |
+
// prev = SHA-256 of previous event (or quantum seed hash for genesis)
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
**Six distinct WORM ledgers exist:**
|
| 201 |
+
| Ledger | Path | Records |
|
| 202 |
+
|--------|------|---------|
|
| 203 |
+
| Quantum swarm | `bob-orchestrator/data/quantum-swarm-worm.jsonl` | ANU seed + swarm collapse events |
|
| 204 |
+
| Tool API | `bob-orchestrator/data/tool-api-worm.jsonl` | Tool invocations |
|
| 205 |
+
| BOB FSM | `DEVFLOW-FINANCE/packages/sovereign-router/.bob-worm.jsonl` | Phase-by-phase execution + output hashes |
|
| 206 |
+
| Execution | `backend/.worm/execution-ledger.jsonl` | Every bash command + allowlist verdict |
|
| 207 |
+
| AVR kernel | `sov-kernel-monster/avr_cold_boot_ledger.jsonl` | QATAAUM cycle invariants |
|
| 208 |
+
| Agda proofs | `sov-kernel-monster/PHASE_3_WORM_ATTESTATION.jsonl` | Proof discharge events |
|
| 209 |
+
|
| 210 |
+
---
|
| 211 |
+
|
| 212 |
+
## BOB sovereignStep: Complete Trace
|
| 213 |
+
|
| 214 |
+
This is the most complete single-pipeline trace in the codebase.
|
| 215 |
+
|
| 216 |
+
**Input:**
|
| 217 |
+
```json
|
| 218 |
+
{
|
| 219 |
+
"agentId": "...",
|
| 220 |
+
"task": "verify_claim",
|
| 221 |
+
"input": "...",
|
| 222 |
+
"lean4Theorem": "...",
|
| 223 |
+
"adaContractText": "..."
|
| 224 |
+
}
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
**Step 0:** ANU QRNG batch β `_quantumSeed` buffer (32 bytes)
|
| 228 |
+
|
| 229 |
+
**Step 1:** METATRON gate (`metatron.mjs`) β `permitted: true/false`
|
| 230 |
+
If `false`: immediate return, no WORM entry written
|
| 231 |
+
|
| 232 |
+
**Step 2:** `SHA-256(lean4Theorem)` β `proof_hash`
|
| 233 |
+
Theorem < 10 chars β freeze
|
| 234 |
+
|
| 235 |
+
**Step 3:** `SHA-256(adaContractText)` β `contract_hash`
|
| 236 |
+
ORACLE class β read-only (gateAdvance returns false)
|
| 237 |
+
|
| 238 |
+
**Step 4:** `worm.seal('BOB_STEP:{task}', step)` β step seal
|
| 239 |
+
|
| 240 |
+
**Step 5:** SSM injection vector construction (Float32Array[2048]):
|
| 241 |
+
```
|
| 242 |
+
dims 0β255: proof_hash bytes β [-1,1]
|
| 243 |
+
dims 256β511: contract_hash bytes β [-1,1]
|
| 244 |
+
dims 512β767: step WORM seal bytes β [-1,1]
|
| 245 |
+
dims 768β2047: ANU quantum seed bytes, 50/50 blended with METATRON cage
|
| 246 |
+
```
|
| 247 |
+
|
| 248 |
+
**Step 6:** Ada gate check (`ada.gateAdvance(class, injectionValid)`)
|
| 249 |
+
|
| 250 |
+
**Step 7:** SSM state update:
|
| 251 |
+
```
|
| 252 |
+
h(t) = 0.9Β·h(t-1) + 0.1Β·x_input + inject_normΒ·0.01
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
**Step 8:** LLM call (Ollama, optional β continues if offline)
|
| 256 |
+
|
| 257 |
+
**Step 9:** `worm.seal('BOB_STEP_COMPLETE:{task}', result)` β final seal
|
| 258 |
+
|
| 259 |
+
**Return:**
|
| 260 |
+
```json
|
| 261 |
+
{
|
| 262 |
+
"proof_hash": "...",
|
| 263 |
+
"contract_hash": "...",
|
| 264 |
+
"ssm_state": [...],
|
| 265 |
+
"worm_seal": "...",
|
| 266 |
+
"injection_vector": [...],
|
| 267 |
+
"llm_reply": "..."
|
| 268 |
+
}
|
| 269 |
+
```
|
| 270 |
+
|
| 271 |
+
---
|
| 272 |
+
|
| 273 |
+
## Where Does the DAG Enter?
|
| 274 |
+
|
| 275 |
+
The DAG enters at three points:
|
| 276 |
+
|
| 277 |
+
1. **Specification:** `ConstraintGraph.xml` defines the DAG structure (which node types, which edges)
|
| 278 |
+
2. **Compilation:** `constraint_graph_svg.py` applies Kahn's algorithm to the XML β produces the execution order
|
| 279 |
+
3. **Governance:** `ICP-DAG.m` enforces that no execution happens without an authorized decision in the governance DAG
|
| 280 |
+
|
| 281 |
+
The compilation output (pipeline list) becomes the execution order for the Python constraint evaluator.
|
| 282 |
+
|
| 283 |
+
---
|
| 284 |
+
|
| 285 |
+
## Where Does SUBLEQ Enter?
|
| 286 |
+
|
| 287 |
+
Currently: independently. The SUBLEQ attention mechanism (`j-matrix-twin/subleq_attention.ijs`, `DEVFLOW-FINANCE/snapkitty-wasm/src/subleq_vm.rs`) is not yet wired into the main BOB workflow or the XSLT code generation pipeline. It exists as a separate experimental track.
|
| 288 |
+
|
| 289 |
+
**The missing integration point:** The SUBLEQ VM could replace the LLM call at Step 8 β activation vectors β SUBLEQ routing β context selection, feeding into the SSM state. This is the proposed architectural connection, not yet implemented.
|
| 290 |
+
|
| 291 |
+
---
|
| 292 |
+
|
| 293 |
+
## Reproducibility
|
| 294 |
+
|
| 295 |
+
| Component | Reproducible? | What's needed |
|
| 296 |
+
|-----------|:-------------:|---------------|
|
| 297 |
+
| SSM computation | β | `proof_hash`, `contract_hash`, `worm_seal`, `quantum_seed` (logged) |
|
| 298 |
+
| XSLT code generation | β | XML spec file + Saxon/xsltproc |
|
| 299 |
+
| Constraint validation | β | entropy vector (deterministic from input) |
|
| 300 |
+
| BOB FSM phases | β (hashes only) | `master_hex` + input β output hashes logged, not raw output |
|
| 301 |
+
| WORM chain | β | All inputs logged; chain is deterministic |
|
| 302 |
+
| LLM replies | β | Temperature and PRNG seed not logged |
|
| 303 |
+
| ANU QRNG seed | β | `master_hex` recorded in quantum-swarm-worm.jsonl |
|
| 304 |
+
| Quantum swarm temps | partial | `master_hex` logged; HKDF derivation deterministic from it |
|
| 305 |
+
|
| 306 |
+
**To reproduce a BOB step:** provide `master_hex` + input + `lean4Theorem` + `adaContractText` + prior agent state. The LLM reply will differ.
|
| 307 |
+
|
| 308 |
+
---
|
| 309 |
+
|
| 310 |
+
## Specification β Program Separation
|
| 311 |
+
|
| 312 |
+
SnapKitty does separate **what** from **how**, but the boundary is:
|
| 313 |
+
|
| 314 |
+
| Layer | What | Where |
|
| 315 |
+
|-------|------|-------|
|
| 316 |
+
| XML spec | Declares DAG structure, entropy bound, constraint expressions | `ConstraintGraph.xml`, `HyperKittyConstraintDSL.xml` |
|
| 317 |
+
| XSLT | Transforms declaration β implementation | `xslt/*.xsl` |
|
| 318 |
+
| Python parser | Turns declaration into runtime objects | `hyperkitty_dsl/parser.py` |
|
| 319 |
+
| Rust implementation | Compiled from generated source | `cargo build` |
|
| 320 |
+
| VM execution | Runs the selected machine code | `sovereign_vm.py` |
|
| 321 |
+
|
| 322 |
+
The separation is real but incomplete: the XSLT and Python parser both consume the same XML, but they produce independent outputs (Rust source vs. Python objects) that are not yet connected at runtime.
|