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