Implement XIC v1.5 glyph resonance awareness upgrade (Phase 3-4)

This commit completes the comprehensive glyph resonance awareness upgrade
with queryable resonance metrics, new instruction, and formal specification.

## Changes

### Phase 3: New GET_GLYPH_RESONANCE Instruction
- Added op_GET_GLYPH_RESONANCE to xic_ops.py for querying glyph resonance data
- Supports metrics: report, global, dominant, weight, lineage, contributor, frequency, grammar
- Results printed with [XIC-RESONANCE] prefix and stored in ctx._state
- Handles both full pipeline result (preferred) and fallback to resonance_metrics dict
- Updated OP_TABLE to include 10th operation

### Phase 4: Formal Specification & Demo

#### XIC_SEMANTICS_v1_5.md Updates
- Added comprehensive "Glyph Resonance Structure" section documenting:
  - FusedSymbol dataclass with summary, glyph_ids, resonance_map
  - GlyphResonanceMap with resonances dict and utility methods
  - GlyphResonanceMetrics (weight, lineage_score, contributor_score, frequency_score, grammar_score)
  - Example JSON structure from LAIN cognition
- Added "GET_GLYPH_RESONANCE" instruction semantics with:
  - Signature and preconditions/postconditions
  - Metric table describing all query types
  - Detailed side effects and remarks
  - Data access patterns

#### New Demo Program
- Created programs/demo_glyph_resonance.gx.json
- Two-chain demonstration:
  - Chain 1: compression_theory glyph with report, global, dominant, weight queries
  - Chain 2: neural_dynamics glyph with individual metric queries (lineage, contributor, frequency, grammar)
- Full instrumentation with CHAIN markers and LOG statements

#### Comprehensive Report
- Created XIC_GLYPH_RESONANCE_REPORT.md documenting:
  - Executive summary of resonance awareness upgrade
  - Detailed explanation of all components
  - Architecture and data flow diagrams
  - All 10 validation test results
  - Usage examples and design decisions
  - Backward compatibility guarantees
  - Future extensibility notes

## Implementation Details

### Enhanced Data Structures (glyphos/symbolic_pipeline.py)
- GlyphResonanceMetrics: 5-dimensional resonance scoring
- GlyphResonanceMap: with get_glyph_resonance(), get_top_glyphs(), get_average_resonance()
- FusedSymbol.from_lain_result(): parses LAIN output structure

### Glyph Resonance Utilities
- extract_glyph_resonances(): extract per-glyph metrics from pipeline result
- get_dominant_glyphs(n): rank glyphs by weight
- format_glyph_resonance_report(): human-readable resonance output

### Enhanced CALL_GLYPH
- Now stores comprehensive resonance data in ctx._state["glyph_{glyph_id}"]
- Captures output_text, fused_symbol, resonance_metrics, global_resonance_score, steps
- Also stores full SymbolicPipelineResult for direct access

### New op_GET_GLYPH_RESONANCE
- Query stored resonance metrics with flexible metric selection
- Integrates with symbolic_pipeline utilities for full introspection
- Prints results and stores in ctx._state for programmatic access

## Exports (glyphos/__init__.py)
- GlyphResonanceMetrics
- GlyphResonanceMap
- extract_glyph_resonances
- get_dominant_glyphs
- format_glyph_resonance_report

## Testing
All 10 validation tests pass:
 GlyphResonanceMetrics instantiation
 GlyphResonanceMap methods (get_glyph_resonance, get_top_glyphs, get_average_resonance)
 FusedSymbol.from_lain_result() parsing
 extract_glyph_resonances() functionality
 get_dominant_glyphs() ranking
 format_glyph_resonance_report() generation
 OP_TABLE has GET_GLYPH_RESONANCE
 op_GET_GLYPH_RESONANCE callable
 demo_glyph_resonance.gx.json valid
 All exports available from glyphos

## Backward Compatibility
- Zero breaking changes
- All XIC v1 and v1.5 programs work unchanged
- New resonance features are additive
- Existing instruction signatures preserved
- Compressed mode execution unaffected

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
GlyphRunner System
2026-05-21 02:21:44 -04:00
parent 6e0a586f51
commit bce6b6fa37
6 changed files with 1121 additions and 13 deletions
+122
View File
@@ -284,6 +284,128 @@ Dual paths:
---
### 10. GET_GLYPH_RESONANCE
**Signature**
```json
{ "op": "GET_GLYPH_RESONANCE", "args": ["<glyph_id>", "<metric>"] }
```
**Preconditions**
- `glyph_id` must have been previously used in a CALL_GLYPH operation.
- `metric` is optional. Valid values: "report", "global", "dominant", "weight", "lineage", "contributor", "frequency", "grammar".
**Postconditions**
- Prints formatted resonance data based on requested metric.
- Stores result in `ctx._state[f"resonance_query_{glyph_id}_{metric}"]`.
**Behavior by metric**:
| Metric | Output | Description |
|--------|--------|-------------|
| `<none>` or `"report"` | Human-readable resonance report | Formatted report with global score and top 5 glyphs by weight |
| `"global"` | Global resonance score (float) | Single float value representing overall resonance |
| `"dominant"` | List of top 5 glyphs by weight | List of (glyph_id, weight) tuples sorted descending |
| `"weight"` | Weight metric (float) | Weight component of resonance (relative importance) |
| `"lineage"` | Lineage score (float) | Score representing symbolic lineage and ancestry |
| `"contributor"` | Contributor score (float) | Score representing contribution to fusion |
| `"frequency"` | Frequency score (float) | Score representing occurrence frequency in cognition |
| `"grammar"` | Grammar score (float) | Score representing grammatical/structural alignment |
**Side effects**
- Prints `[XIC-RESONANCE] ...` with requested data.
- Stores result in `ctx._state` for programmatic access.
**Remarks**
- GET_GLYPH_RESONANCE requires prior CALL_GLYPH execution to populate glyph resonance data.
- If glyph_id not found, prints error and stores None.
- Queries access the full SymbolicPipelineResult stored by CALL_GLYPH.
---
## Glyph Resonance Structure
### FusedSymbol Data Structure
The `fused_symbol` in SymbolicPipelineResult contains:
```python
@dataclass
class FusedSymbol:
summary: str # Text summary of fused cognition
glyph_ids: List[str] # List of glyph IDs engaged in fusion
resonance_map: GlyphResonanceMap # Resonance metrics for each glyph
```
### GlyphResonanceMap
Maps glyph IDs to their resonance metrics:
```python
@dataclass
class GlyphResonanceMap:
resonances: Dict[str, GlyphResonanceMetrics] # glyph_id → metrics
global_resonance_score: float # Overall fusion quality score [0.0, 1.0]
```
Methods:
- `get_glyph_resonance(glyph_id: str) → Optional[GlyphResonanceMetrics]`: Retrieve metrics for a specific glyph.
- `get_top_glyphs(n: int = 5) → List[tuple[str, GlyphResonanceMetrics]]`: Get top N glyphs by weight.
- `get_average_resonance() → float`: Get average resonance across all glyphs.
### GlyphResonanceMetrics
Per-glyph resonance metrics capturing multiple dimensions of symbolic activity:
```python
@dataclass
class GlyphResonanceMetrics:
weight: float # Relative importance of glyph in fusion [0.0, 1.0]
lineage_score: float # Symbolic lineage and ancestry score [0.0, 1.0]
contributor_score: float # Contribution to overall fusion [0.0, 1.0]
frequency_score: float # Occurrence frequency in cognition [0.0, 1.0]
grammar_score: float # Grammatical/structural alignment [0.0, 1.0]
```
### Example Structure
```json
{
"fused_symbol": {
"summary": "Compression and information theory are foundational to cognition...",
"glyph_ids": ["glyph://compression_theory", "glyph://entropy", "glyph://coding"],
"resonance_map": {
"global_resonance_score": 0.847,
"resonances": {
"glyph://compression_theory": {
"weight": 0.95,
"lineage_score": 0.82,
"contributor_score": 0.89,
"frequency_score": 0.76,
"grammar_score": 0.88
},
"glyph://entropy": {
"weight": 0.73,
"lineage_score": 0.68,
"contributor_score": 0.71,
"frequency_score": 0.65,
"grammar_score": 0.75
}
}
}
}
}
```
### Accessing Resonance Data
From XIC programs:
1. CALL_GLYPH stores result in `ctx._state[f"glyph_{glyph_id}"]` including resonance_metrics and global_resonance_score.
2. GET_GLYPH_RESONANCE queries the stored data with various metric filters.
3. Access pipeline result object via `ctx._state[f"glyph_{glyph_id}_pipeline_result"]` for direct FusedSymbol manipulation.
---
## Symbolic Pipeline Semantics
### run_symbolic_pipeline() Entrypoint