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
+133 -5
View File
@@ -154,15 +154,17 @@ def op_CHAIN(ctx: XICContext, *args):
def op_CALL_GLYPH(ctx: XICContext, *args):
"""CALL_GLYPH <glyph_id> <payload>: Invoke glyph-aware cognition.
"""CALL_GLYPH <glyph_id> <payload>: Invoke glyph-aware cognition with resonance tracking.
Routes through symbolic pipeline with explicit glyph_id parameter.
The glyph_id is propagated into the pipeline context and used for
glyph-aware symbolic transformations in the LAIN layer.
Stores result with key "glyph_{glyph_id}" containing:
Stores comprehensive result with key "glyph_{glyph_id}" containing:
- output_text: Final text from cognition
- fused_symbol: Fused symbolic representation (if produced)
- fused_symbol: Fused symbolic representation with glyph_ids and resonance_map
- resonance_metrics: Extracted per-glyph resonance scores (weight, lineage, contributor, etc.)
- global_resonance_score: Overall resonance from LAIN
- steps: List of symbolic pipeline steps
"""
if not args:
@@ -170,7 +172,12 @@ def op_CALL_GLYPH(ctx: XICContext, *args):
glyph_id = str(args[0])
payload = str(args[1]) if len(args) > 1 else ""
from glyphos.symbolic_pipeline import run_symbolic_pipeline
from glyphos.symbolic_pipeline import (
run_symbolic_pipeline,
extract_glyph_resonances,
format_glyph_resonance_report,
)
glyph_context = dict(ctx.params.get("context", {}))
glyph_context["glyph_id"] = glyph_id
@@ -179,14 +186,31 @@ def op_CALL_GLYPH(ctx: XICContext, *args):
context=glyph_context,
glyph_id=glyph_id,
)
print(f"[XIC-GLYPH] {pipeline_result.output_text}")
# Extract resonance metrics
resonance_metrics = extract_glyph_resonances(pipeline_result)
global_resonance = 0.0
if pipeline_result.fused_symbol:
global_resonance = pipeline_result.fused_symbol.resonance_map.global_resonance_score
# Store comprehensive result
ctx._state[f"glyph_{glyph_id}"] = {
"output_text": pipeline_result.output_text,
"fused_symbol": pipeline_result.fused_symbol,
"fused_symbol": {
"summary": pipeline_result.fused_symbol.summary if pipeline_result.fused_symbol else None,
"glyph_ids": pipeline_result.fused_symbol.glyph_ids if pipeline_result.fused_symbol else [],
} if pipeline_result.fused_symbol else None,
"resonance_metrics": resonance_metrics,
"global_resonance_score": global_resonance,
"steps": [{"name": s.name, "kind": s.kind, "payload": str(s.payload)[:100]}
for s in pipeline_result.steps],
}
# Also store for direct query access
ctx._state[f"glyph_{glyph_id}_pipeline_result"] = pipeline_result
def op_SET_CONTEXT(ctx: XICContext, *args):
"""SET_CONTEXT <key> <value>: Set symbolic/cognitive context key."""
@@ -206,6 +230,109 @@ def op_LOG(ctx: XICContext, *args):
print(f"[XIC-LOG] {message}")
def op_GET_GLYPH_RESONANCE(ctx: XICContext, *args):
"""GET_GLYPH_RESONANCE <glyph_id> [metric]: Query glyph resonance metrics from previous CALL_GLYPH.
Retrieves resonance data stored by CALL_GLYPH and provides:
- No metric arg: Returns formatted resonance report for the glyph
- metric="weight" | "lineage" | "contributor" | "frequency" | "grammar": Returns specific metric for glyph
- metric="global": Returns global resonance score
- metric="dominant": Returns top 5 dominant glyphs by weight
Results are printed and stored in ctx._state["resonance_query_<glyph_id>_<metric>"]
"""
if not args:
raise ValueError("GET_GLYPH_RESONANCE requires glyph_id argument")
glyph_id = str(args[0])
metric = str(args[1]) if len(args) > 1 else None
# Try to find the stored glyph result
glyph_key = f"glyph_{glyph_id}"
if glyph_key not in ctx._state:
print(f"[XIC-RESONANCE] No resonance data for glyph: {glyph_id}")
ctx._state[f"resonance_query_{glyph_id}_notfound"] = None
return
glyph_data = ctx._state[glyph_key]
# If we have the pipeline result object, use it to regenerate report
pipeline_key = f"glyph_{glyph_id}_pipeline_result"
if pipeline_key in ctx._state:
from glyphos.symbolic_pipeline import (
format_glyph_resonance_report,
extract_glyph_resonances,
get_dominant_glyphs,
)
pipeline_result = ctx._state[pipeline_key]
if metric is None or metric == "report":
report = format_glyph_resonance_report(pipeline_result)
print(f"[XIC-RESONANCE] Report for {glyph_id}:\n{report}")
ctx._state[f"resonance_query_{glyph_id}_report"] = report
elif metric == "global":
if pipeline_result.fused_symbol:
score = pipeline_result.fused_symbol.resonance_map.global_resonance_score
print(f"[XIC-RESONANCE] Global resonance for {glyph_id}: {score:.3f}")
ctx._state[f"resonance_query_{glyph_id}_global"] = score
else:
print(f"[XIC-RESONANCE] No fused_symbol for {glyph_id}")
ctx._state[f"resonance_query_{glyph_id}_global"] = None
elif metric == "dominant":
dominant = get_dominant_glyphs(pipeline_result, n=5)
print(f"[XIC-RESONANCE] Dominant glyphs for {glyph_id}:")
for glyph, weight in dominant:
print(f" {glyph}: {weight:.3f}")
ctx._state[f"resonance_query_{glyph_id}_dominant"] = dominant
elif metric in ["weight", "lineage", "contributor", "frequency", "grammar"]:
resonances = extract_glyph_resonances(pipeline_result)
if glyph_id in resonances:
metric_val = resonances[glyph_id].get(
metric if metric != "lineage" else "lineage_score",
resonances[glyph_id].get(f"{metric}_score") if metric != "weight" else None
)
if metric == "lineage":
metric_val = resonances[glyph_id].get("lineage_score")
elif metric == "contributor":
metric_val = resonances[glyph_id].get("contributor_score")
elif metric == "frequency":
metric_val = resonances[glyph_id].get("frequency_score")
elif metric == "grammar":
metric_val = resonances[glyph_id].get("grammar_score")
if metric_val is not None:
print(f"[XIC-RESONANCE] {metric} for {glyph_id}: {metric_val:.3f}")
ctx._state[f"resonance_query_{glyph_id}_{metric}"] = metric_val
else:
print(f"[XIC-RESONANCE] Metric '{metric}' not found for {glyph_id}")
ctx._state[f"resonance_query_{glyph_id}_{metric}"] = None
else:
print(f"[XIC-RESONANCE] Glyph {glyph_id} not in resonance data")
ctx._state[f"resonance_query_{glyph_id}_{metric}"] = None
else:
print(f"[XIC-RESONANCE] Unknown metric: {metric}")
ctx._state[f"resonance_query_{glyph_id}_{metric}"] = None
else:
# Fallback: use stored resonance_metrics if available
if "resonance_metrics" in glyph_data:
resonance_metrics = glyph_data["resonance_metrics"]
if metric is None:
print(f"[XIC-RESONANCE] Resonance metrics for {glyph_id}:")
for glyph, metrics_dict in resonance_metrics.items():
print(f" {glyph}: weight={metrics_dict.get('weight', 0):.3f}")
ctx._state[f"resonance_query_{glyph_id}_report"] = resonance_metrics
elif metric == "global":
score = glyph_data.get("global_resonance_score", 0.0)
print(f"[XIC-RESONANCE] Global resonance for {glyph_id}: {score:.3f}")
ctx._state[f"resonance_query_{glyph_id}_global"] = score
else:
print(f"[XIC-RESONANCE] Specific metric query requires pipeline result")
ctx._state[f"resonance_query_{glyph_id}_{metric}"] = None
else:
print(f"[XIC-RESONANCE] No resonance metrics available for {glyph_id}")
ctx._state[f"resonance_query_{glyph_id}_notfound"] = None
# Operation dispatch table
OP_TABLE = {
"LOAD_MODEL": op_LOAD_MODEL,
@@ -216,5 +343,6 @@ OP_TABLE = {
"STREAM": op_STREAM,
"CHAIN": op_CHAIN,
"CALL_GLYPH": op_CALL_GLYPH,
"GET_GLYPH_RESONANCE": op_GET_GLYPH_RESONANCE,
"LOG": op_LOG,
}