File size: 3,009 Bytes
a80c9f6
 
 
 
 
 
 
 
 
 
 
 
 
4bfd01e
a80c9f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bfd01e
a80c9f6
 
 
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
"""

Deep Dive: Export Capabilities



Testing the capsule agent's self-export capabilities:

1. export_pt() - PyTorch format 

2. export_onnx() - ONNX for deployment

3. export_capsule() - Self-replicating quine!



The quine capability is special - the model can export itself

as a complete, self-contained Python module!

"""

import os
import champion_gen42 as ch

print("=" * 60)
print("📦 Capsule Export Capabilities")
print("=" * 60)

# Create agent
agent = ch.CapsuleAgent()

# Show current quine info
print(f"\n=== Current Quine Info ===")
print(f"Quine hash: {ch.get_quine_hash()}")
print(f"Integrity: {ch.verify_quine_integrity()}")

# Create export directory
export_dir = "exports"
os.makedirs(export_dir, exist_ok=True)

# Test export_capsule (the quine self-replication!)
print(f"\n=== Testing export_capsule() ===")
print("This creates a self-contained Python module...")

capsule_path = agent.export_capsule(os.path.join(export_dir, "child_capsule.py"))
print(f"Exported to: {capsule_path}")

# Check the file
if capsule_path and os.path.exists(capsule_path):
    size = os.path.getsize(capsule_path)
    print(f"File size: {size / 1024 / 1024:.2f} MB")
    
    # Read first few lines
    with open(capsule_path, 'r', encoding='utf-8', errors='ignore') as f:
        lines = f.readlines()[:30]
    
    print("\n=== First 30 lines of exported capsule ===")
    for i, line in enumerate(lines, 1):
        print(f"{i:3d}: {line.rstrip()[:80]}")
    
    print(f"\n... ({len(lines)} of total lines shown)")
    
    # Verify it's a valid quine
    print("\n=== Verifying exported capsule ===")
    try:
        import importlib.util
        spec = importlib.util.spec_from_file_location("child", capsule_path)
        child = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(child)
        
        if hasattr(child, 'get_quine_hash'):
            child_hash = child.get_quine_hash()
            print(f"Child quine hash: {child_hash}")
            print(f"Parent quine hash: {ch.get_quine_hash()}")
            print(f"Hashes match: {child_hash == ch.get_quine_hash()}")
        
        if hasattr(child, 'verify_quine_integrity'):
            print(f"Child integrity: {child.verify_quine_integrity()}")
            
    except Exception as e:
        print(f"Could not verify child: {e}")
else:
    print("Export may not have created a file")

# Test replicate_quine directly
print("\n=== Testing replicate_quine() ===")
replica_path = ch.replicate_quine(os.path.join(export_dir, "replica.py"))
print(f"Replicated to: {replica_path}")

if replica_path and os.path.exists(replica_path):
    replica_size = os.path.getsize(replica_path)
    original_size = os.path.getsize("champion_gen42.py")
    print(f"Original size: {original_size / 1024 / 1024:.2f} MB")
    print(f"Replica size: {replica_size / 1024 / 1024:.2f} MB")
    print(f"Size match: {abs(replica_size - original_size) < 1000}")