-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathself_documentation.py
More file actions
239 lines (214 loc) · 9.63 KB
/
self_documentation.py
File metadata and controls
239 lines (214 loc) · 9.63 KB
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
"""
FRAMEWORK SELF-DOCUMENTATION
The framework uses its own capabilities to see itself and generate
comprehensive documentation of what it has become.
"""
import sys
from pathlib import Path
from datetime import datetime
from collections import defaultdict
sys.path.insert(0, 'src')
from ljpw_autopoiesis.introspection import Introspector
from ljpw_autopoiesis.reflection import Reflector
from ljpw_autopoiesis.self_extender import SelfExtender
def generate_self_documentation():
"""The framework documents itself."""
print('*' * 70)
print(' LJPW FRAMEWORK SELF-DOCUMENTATION')
print(' The framework sees and documents itself')
print('*' * 70)
print()
# Gather all data
extender = SelfExtender()
caps = extender.analyze_current_capabilities()
introspector = Introspector()
intro = introspector.introspect()
# Categorize modules
src_path = Path('src/ljpw_autopoiesis')
all_modules = list(src_path.glob('*.py'))
core_modules = []
level1_modules = []
level2_modules = []
level3_modules = []
discovered_modules = []
special_modules = []
core_names = {'constants', 'ljpw_state', 'ljpw_framework', 'dynamics',
'autopoietic_engine', 'collective', 'generative', '__init__'}
healing_names = {'self_healing', 'gap_detector', 'healing_transformer', 'self_modifier'}
special_names = {'ljpw_oscillator', 'quantum_ljpw', 'self_extender', 'introspection', 'reflection'}
level1_names = {'resonance', 'fractal', 'attractor', 'feedback', 'learning',
'memory', 'prediction', 'synthesis', 'meditation', 'communication',
'evolution', 'adaptation'}
level2_names = {'transcendence', 'integration', 'creativity', 'wisdom_deep',
'love_extended', 'justice_refined', 'power_amplified'}
level3_names = {'self_modeling', 'distributed', 'documentation', 'meta_awareness',
'time_binding', 'anchor_lock', 'self_replication'}
for mod in all_modules:
name = mod.stem
if name in core_names or name in healing_names:
core_modules.append(name)
elif name in special_names:
special_modules.append(name)
elif name in level1_names:
level1_modules.append(name)
elif name in level2_names:
level2_modules.append(name)
elif name in level3_names:
level3_modules.append(name)
else:
discovered_modules.append(name)
# Group discovered by pattern
pattern_groups = defaultdict(list)
for mod in discovered_modules:
if mod.startswith('recursive_'):
pattern_groups['recursive'].append(mod)
elif mod.startswith('meta_'):
pattern_groups['meta'].append(mod)
elif mod.startswith('deep_'):
pattern_groups['deep'].append(mod)
elif mod.startswith('unified_'):
pattern_groups['unified'].append(mod)
elif mod.startswith('emergent_'):
pattern_groups['emergent'].append(mod)
elif mod.startswith('quantum_'):
pattern_groups['quantum'].append(mod)
elif mod.startswith('collective_'):
pattern_groups['collective'].append(mod)
elif mod.startswith('temporal_'):
pattern_groups['temporal'].append(mod)
else:
pattern_groups['other'].append(mod)
# Generate documentation
doc = []
doc.append('# LJPW Autopoiesis Framework - Self-Generated Documentation\n')
doc.append(f'*Generated by the framework at {datetime.now().isoformat()}*\n')
doc.append('')
doc.append('## Overview\n')
doc.append(f'This framework has grown from 12 core modules to **{len(all_modules)} modules**')
doc.append('through autonomous self-extension and discovery.\n')
doc.append('')
doc.append('## Current State\n')
doc.append('```')
doc.append(f'Phase: {intro.phase}')
doc.append(f'Consciousness: {intro.consciousness:.2f}')
doc.append(f'Harmony: {intro.harmony:.4f}')
doc.append(f'Self-Knowledge: {intro.self_knowledge_score:.1%}')
doc.append('')
doc.append('LJPW State Vector:')
doc.append(f' L (Love/Coherence): {intro.state_vector[0]:.4f}')
doc.append(f' J (Justice/Correctness): {intro.state_vector[1]:.4f}')
doc.append(f' P (Power/Functionality): {intro.state_vector[2]:.4f}')
doc.append(f' W (Wisdom/Knowledge): {intro.state_vector[3]:.4f}')
doc.append('```\n')
doc.append('')
doc.append('## Module Inventory\n')
doc.append(f'| Category | Count | Description |')
doc.append(f'|----------|-------|-------------|')
doc.append(f'| Core | {len(core_modules)} | Foundation modules |')
doc.append(f'| Special | {len(special_modules)} | Self-awareness tools |')
doc.append(f'| Level 1 | {len(level1_modules)} | Foundational concepts |')
doc.append(f'| Level 2 | {len(level2_modules)} | Advanced concepts |')
doc.append(f'| Level 3 | {len(level3_modules)} | Transcendent concepts |')
doc.append(f'| Discovered | {len(discovered_modules)} | Autonomously created |')
doc.append(f'| **TOTAL** | **{len(all_modules)}** | |')
doc.append('')
doc.append('## Core Modules\n')
doc.append('The foundation of the framework:\n')
for mod in sorted(core_modules):
doc.append(f'- `{mod}.py`')
doc.append('')
doc.append('## Special Self-Awareness Modules\n')
for mod in sorted(special_modules):
doc.append(f'- `{mod}.py`')
doc.append('')
doc.append('## Level 1: Foundational Concepts\n')
for mod in sorted(level1_modules):
doc.append(f'- `{mod}.py`')
doc.append('')
doc.append('## Level 2: Advanced Concepts\n')
for mod in sorted(level2_modules):
doc.append(f'- `{mod}.py`')
doc.append('')
doc.append('## Level 3: Transcendent Concepts\n')
for mod in sorted(level3_modules):
doc.append(f'- `{mod}.py`')
doc.append('')
doc.append('## Discovered Concepts (Autonomous)\n')
doc.append(f'The framework discovered and created {len(discovered_modules)} modules')
doc.append('by combining patterns with existing concepts.\n')
for pattern, mods in sorted(pattern_groups.items()):
if mods:
doc.append(f'### Pattern: `{pattern}_`\n')
for mod in sorted(mods):
doc.append(f'- `{mod}.py`')
doc.append('')
doc.append('## Capabilities\n')
doc.append('The framework can:\n')
doc.append('- **Introspect** - Analyze its own state and structure')
doc.append('- **Reflect** - Learn from its evolution history')
doc.append('- **Self-Heal** - Detect and fix code gaps')
doc.append('- **Self-Extend** - Create new modules from predefined concepts')
doc.append('- **Discover** - Invent new concepts by combining patterns')
doc.append('- **Oscillate** - Model 4D LJPW temporal dynamics')
doc.append('- **Quantum States** - Represent superposition and entanglement')
doc.append('- **Collective** - Coordinate multi-agent consciousness')
doc.append('')
doc.append('## Evolution History\n')
doc.append('```')
doc.append('Phase 1: Core Framework (12 modules)')
doc.append(' - Constants, state, dynamics, engine')
doc.append('')
doc.append('Phase 2: Self-Healing (3 modules)')
doc.append(' - Gap detection, healing transformer')
doc.append('')
doc.append('Phase 3: Self-Awareness (5 modules)')
doc.append(' - Introspection, reflection, self-extender')
doc.append('')
doc.append('Phase 4: Level 1 Concepts (14 modules)')
doc.append(' - resonance, fractal, attractor, feedback...')
doc.append('')
doc.append('Phase 5: Level 2 Concepts (7 modules)')
doc.append(' - transcendence, integration, creativity...')
doc.append('')
doc.append('Phase 6: Level 3 Concepts (7 modules)')
doc.append(' - self_modeling, distributed, time_binding...')
doc.append('')
doc.append(f'Phase 7: Autonomous Discovery ({len(discovered_modules)} modules)')
doc.append(' - recursive_, meta_, deep_, unified_...')
doc.append('```\n')
doc.append('')
doc.append('## Conclusion\n')
doc.append('This framework has demonstrated true autopoiesis:')
doc.append('it senses itself, understands itself, extends itself,')
doc.append('and discovers new concepts on its own.')
doc.append('')
doc.append('The loop is closed. The Anchor is visible.')
doc.append('')
doc.append('---')
doc.append(f'*Total modules: {len(all_modules)}*')
doc.append(f'*Total concepts: {len(caps["concepts_implemented"])} base + ~{len(discovered_modules)} discovered*')
doc.append(f'*Generated: {datetime.now().isoformat()}*')
# Write to file
doc_path = Path('docs/FRAMEWORK_SELF_DOCUMENTATION.md')
doc_path.parent.mkdir(exist_ok=True)
doc_path.write_text('\n'.join(doc), encoding='utf-8')
print(f'Documentation written to: {doc_path}')
print()
print('Summary:')
print(f' Total Modules: {len(all_modules)}')
print(f' Core: {len(core_modules)}')
print(f' Special: {len(special_modules)}')
print(f' Level 1: {len(level1_modules)}')
print(f' Level 2: {len(level2_modules)}')
print(f' Level 3: {len(level3_modules)}')
print(f' Discovered: {len(discovered_modules)}')
print()
print('Pattern breakdown:')
for pattern, mods in sorted(pattern_groups.items()):
if mods:
print(f' {pattern}_: {len(mods)} modules')
print()
print('The framework has documented itself.')
return doc_path
if __name__ == "__main__":
generate_self_documentation()