Implement XIC v2 control flow with IF, MATCH, LOOP operations

PHASE A: Safe predicate evaluator (glyphos/control/predicate.py)
- AST-based safe expression evaluation
- Supports comparisons, boolean ops, attribute access
- Helper function: dominant_contains()
- Protected against code injection attacks

PHASE B: XICContext queue helpers
- enqueue_chain(label) for FIFO chain scheduling
- pop_next_chain() to get next scheduled chain
- jump_to(label) for immediate destination changes

PHASE C: Control flow operations (xic_ops.py)
- op_IF: Conditional branching with optional else
- op_MATCH: Pattern matching against fused fields
- op_LOOP: Iterative execution with guardrails
- Added to OP_TABLE for operation dispatch

PHASE D: Execution loop enhancement (xic_vm.py)
- Chain queue scheduling with label matching
- Total steps tracking for guardrail enforcement
- max_total_steps limit across all operations
- Graceful execution stop on guardrail trigger

PHASE E: Comprehensive test suite (tests/test_control_flow.py)
- 14 unit tests covering all operations
- Predicate evaluator tests
- IF/MATCH/LOOP operation tests
- Queue helper and guardrail tests
- All tests passing (14/14)

PHASE F: Example programs
- demo_control_flow_if.gx.json: IF branching example
- demo_control_flow_loop.gx.json: LOOP iteration example

PHASE G: Complete documentation
- XIC_V2_CONTROL_FLOW_SUMMARY.md: Technical guide
- XIC_V2_QUICK_REFERENCE.md: Developer quick reference
- FedMart UI and integration documentation

Integration points:
- FedMart telemetry captures control flow steps
- UI dashboard displays control branching
- Symbolic pipeline predicate evaluation
- 100% backward compatible with XIC v1.5

Test results: 36/36 passing (14 control flow + 12 FedMart + 10 UI)
Status: Production ready
This commit is contained in:
GlyphRunner System
2026-05-21 03:40:39 -04:00
parent 8f55949b11
commit c3a826b65c
17 changed files with 4299 additions and 3 deletions
+82
View File
@@ -0,0 +1,82 @@
{
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {
"main": 0,
"high_resonance": 6,
"low_resonance": 11,
"end": 15
},
"instructions": [
{
"op": "SET_MODE",
"args": ["symbolic"]
},
{
"op": "SET_CONTEXT",
"args": ["domain", "symbolic_cognition"]
},
{
"op": "PUSH_GLYPH_CONTEXT",
"args": ["glyph://compression"]
},
{
"op": "PUSH_GLYPH_CONTEXT",
"args": ["glyph://entropy"]
},
{
"op": "RUN_PROMPT",
"args": ["Analyze the relationship between compression and entropy in information theory"]
},
{
"op": "IF",
"args": ["fused.global_resonance_score > 0.8", "high_resonance", "low_resonance"]
},
{
"op": "CHAIN",
"args": ["high_resonance"]
},
{
"op": "LOG",
"args": ["High resonance detected - proceeding with deep analysis"]
},
{
"op": "RUN_PROMPT",
"args": ["Provide deeper symbolic insights into compression and entropy"]
},
{
"op": "LOG",
"args": ["Deep analysis complete"]
},
{
"op": "CHAIN",
"args": ["end"]
},
{
"op": "CHAIN",
"args": ["low_resonance"]
},
{
"op": "LOG",
"args": ["Low resonance - attempting different approach"]
},
{
"op": "RUN_PROMPT",
"args": ["Explain compression and entropy from a different perspective"]
},
{
"op": "CHAIN",
"args": ["end"]
},
{
"op": "CHAIN",
"args": ["end"]
},
{
"op": "LOG",
"args": ["IF control flow demonstration complete"]
}
]
}
+69
View File
@@ -0,0 +1,69 @@
{
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {
"main": 0,
"loop_body": 7,
"end": 12
},
"instructions": [
{
"op": "SET_MODE",
"args": ["symbolic"]
},
{
"op": "SET_CONTEXT",
"args": ["domain", "iterative_analysis"]
},
{
"op": "SET_PARAM",
"args": ["max_loop_iterations", 5]
},
{
"op": "SET_PARAM",
"args": ["max_total_steps", 100]
},
{
"op": "LOG",
"args": ["Starting iterative symbolic analysis with LOOP control flow"]
},
{
"op": "PUSH_GLYPH_CONTEXT",
"args": ["glyph://analysis"]
},
{
"op": "LOOP",
"args": ["fused.global_resonance_score > 0.6", "loop_body", 5]
},
{
"op": "CHAIN",
"args": ["loop_body"]
},
{
"op": "RUN_PROMPT",
"args": ["Analyze the current symbolic state and refine understanding"]
},
{
"op": "GET_GLYPH_RESONANCE",
"args": ["glyph://analysis", "global"]
},
{
"op": "LOG",
"args": ["Iteration complete, checking resonance score"]
},
{
"op": "CHAIN",
"args": ["end"]
},
{
"op": "CHAIN",
"args": ["end"]
},
{
"op": "LOG",
"args": ["LOOP control flow demonstration complete"]
}
]
}