Repository navigation
Expand file tree
/
Copy pathverify_system.py
More file actions
executable file
·344 lines (286 loc) · 10.5 KB
/
Copy pathverify_system.py
File metadata and controls
executable file
·344 lines (286 loc) · 10.5 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/usr/bin/env python3
"""
System Verification Script for lmagi
Verifies autonomous mode, logging systems, and memory writing
"""
import os
import sys
import json
import pathlib
from datetime import datetime
# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def check_memory_folders():
"""Verify all memory folders exist"""
print("\n" + "="*60)
print("CHECKING MEMORY FOLDERS")
print("="*60)
folders = [
"./memory/",
"./memory/stm/",
"./memory/ltm/",
"./memory/episodic/",
"./memory/truth/",
"./memory/logs/",
"./mindx/",
"./mindx/agency/",
"./mindx/errors/"
]
all_exist = True
for folder in folders:
exists = os.path.exists(folder)
status = "✓" if exists else "✗"
print(f"{status} {folder}")
if not exists:
all_exist = False
print(f" WARNING: Folder does not exist!")
return all_exist
def check_log_files():
"""Verify log files exist and are writable"""
print("\n" + "="*60)
print("CHECKING LOG FILES")
print("="*60)
log_files = {
"Premises": "./memory/logs/premises.json",
"Not Premise": "./memory/logs/notpremise.json",
"Thoughts": "./memory/logs/thoughts.json",
"Conclusions": "./memory/logs/conclusions.txt",
"Truth Tables": "./memory/logs/truth.json",
"Socratic Logs": "./memory/logs/socraticlogs.txt",
"Truth Logs": "./memory/truth/logs.txt"
}
all_ok = True
for name, path in log_files.items():
exists = os.path.exists(path)
writable = os.access(os.path.dirname(path), os.W_OK) if os.path.exists(os.path.dirname(path)) else False
status = "✓" if (exists and writable) else "✗"
print(f"{status} {name}: {path}")
if exists:
try:
size = os.path.getsize(path)
print(f" Size: {size} bytes")
# Try to read if JSON
if path.endswith('.json'):
with open(path, 'r') as f:
try:
data = json.load(f)
if isinstance(data, list):
print(f" Entries: {len(data)}")
elif isinstance(data, dict):
print(f" Keys: {list(data.keys())[:5]}")
except json.JSONDecodeError:
# Check if it's line-delimited JSON
with open(path, 'r') as f2:
lines = f2.readlines()
print(f" Lines: {len(lines)}")
except Exception as e:
print(f" Error reading: {e}")
if not writable:
print(f" WARNING: Directory not writable!")
all_ok = False
return all_ok
def check_truth_table_logging():
"""Verify truth table logging functionality"""
print("\n" + "="*60)
print("CHECKING TRUTH TABLE LOGGING")
print("="*60)
try:
from automind.logic import LogicTables
lt = LogicTables()
print("✓ LogicTables initialized")
# Test adding variables
lt.add_variable('A')
lt.add_variable('B')
print("✓ Variables added")
# Test adding expressions
lt.add_expression('A and B')
print("✓ Expressions added")
# Check if belief files are created
truth_dir = "./memory/truth"
belief_files = list(pathlib.Path(truth_dir).glob("*_belief.json"))
print(f"✓ Belief files found: {len(belief_files)}")
# Check truth logs
truth_log_path = "./memory/truth/logs.txt"
if os.path.exists(truth_log_path):
with open(truth_log_path, 'r') as f:
lines = f.readlines()
print(f"✓ Truth logs: {len(lines)} lines")
return True
except Exception as e:
print(f"✗ Error checking truth tables: {e}")
import traceback
traceback.print_exc()
return False
def check_socratic_reasoning():
"""Verify SocraticReasoning logging"""
print("\n" + "="*60)
print("CHECKING SOCRATIC REASONING LOGGING")
print("="*60)
try:
from automind.SocraticReasoning import SocraticReasoning
# Check if files exist
files = {
"Premises": "./memory/logs/premises.json",
"Not Premise": "./memory/logs/notpremise.json",
"Truth Tables": "./memory/logs/truth.json",
"Conclusions": "./memory/logs/conclusions.txt",
"Socratic Logs": "./memory/logs/socraticlogs.txt"
}
all_ok = True
for name, path in files.items():
exists = os.path.exists(path)
status = "✓" if exists else "✗"
print(f"{status} {name} file exists")
if not exists:
all_ok = False
return all_ok
except Exception as e:
print(f"✗ Error checking SocraticReasoning: {e}")
import traceback
traceback.print_exc()
return False
def check_autonomous_mode():
"""Verify autonomous mode setup"""
print("\n" + "="*60)
print("CHECKING AUTONOMOUS MODE SETUP")
print("="*60)
try:
from automind.openmind import OpenMind
openmind = OpenMind()
print("✓ OpenMind initialized")
# Check if reasoning_loop method exists
if hasattr(openmind, 'reasoning_loop'):
print("✓ reasoning_loop method exists")
else:
print("✗ reasoning_loop method missing")
return False
# Check if autonomous_reasoning flag exists
if hasattr(openmind, 'autonomous_reasoning'):
print(f"✓ autonomous_reasoning flag exists: {openmind.autonomous_reasoning}")
else:
print("✗ autonomous_reasoning flag missing")
return False
# Check if reasoning_task tracking exists
if hasattr(openmind, 'reasoning_task'):
print("✓ reasoning_task tracking exists")
else:
print("✗ reasoning_task tracking missing")
return False
# Check if _create_task method exists
if hasattr(openmind, '_create_task'):
print("✓ _create_task method exists")
else:
print("✗ _create_task method missing")
return False
return True
except Exception as e:
print(f"✗ Error checking autonomous mode: {e}")
import traceback
traceback.print_exc()
return False
def test_memory_writing():
"""Test writing to memory files"""
print("\n" + "="*60)
print("TESTING MEMORY WRITING")
print("="*60)
try:
from memory.memory import (
create_memory_folders,
store_in_stm,
save_conversation_memory,
save_internal_reasoning,
save_valid_truth,
DialogEntry
)
# Ensure folders exist
create_memory_folders()
print("✓ Memory folders created")
# Test STM storage
test_entry = DialogEntry("test instruction", "test response")
store_in_stm(test_entry)
print("✓ STM storage works")
# Test conversation memory
test_memory = {"dialog": {"instruction": "test", "response": "test"}}
save_conversation_memory(test_memory)
print("✓ Conversation memory storage works")
# Test internal reasoning
test_reasoning = {
"timestamp": int(datetime.now().timestamp()),
"prompt": "test prompt",
"conclusion": "test conclusion"
}
save_internal_reasoning(test_reasoning)
print("✓ Internal reasoning storage works")
# Test valid truth
test_truth = {
"expression": "test expression",
"timestamp": datetime.now().isoformat()
}
save_valid_truth(test_truth)
print("✓ Valid truth storage works")
return True
except Exception as e:
print(f"✗ Error testing memory writing: {e}")
import traceback
traceback.print_exc()
return False
def check_recent_activity():
"""Check for recent activity in log files"""
print("\n" + "="*60)
print("CHECKING RECENT ACTIVITY")
print("="*60)
import time
log_files = {
"Premises": "./memory/logs/premises.json",
"Thoughts": "./memory/logs/thoughts.json",
"Conclusions": "./memory/logs/conclusions.txt",
"Truth Tables": "./memory/logs/truth.json"
}
current_time = time.time()
recent_threshold = 3600 # 1 hour
for name, path in log_files.items():
if os.path.exists(path):
mtime = os.path.getmtime(path)
age = current_time - mtime
age_hours = age / 3600
if age < recent_threshold:
status = "✓"
print(f"{status} {name}: Last updated {age_hours:.2f} hours ago")
else:
status = "⚠"
print(f"{status} {name}: Last updated {age_hours:.2f} hours ago (old)")
else:
print(f"✗ {name}: File does not exist")
def main():
"""Run all verification checks"""
print("\n" + "="*60)
print("LMAGI SYSTEM VERIFICATION")
print("="*60)
print(f"Timestamp: {datetime.now().isoformat()}")
results = {
"Memory Folders": check_memory_folders(),
"Log Files": check_log_files(),
"Truth Table Logging": check_truth_table_logging(),
"Socratic Reasoning": check_socratic_reasoning(),
"Autonomous Mode": check_autonomous_mode(),
"Memory Writing": test_memory_writing(),
}
check_recent_activity()
print("\n" + "="*60)
print("SUMMARY")
print("="*60)
all_passed = True
for check, passed in results.items():
status = "PASS" if passed else "FAIL"
print(f"{status}: {check}")
if not passed:
all_passed = False
print("\n" + "="*60)
if all_passed:
print("✓ ALL CHECKS PASSED")
else:
print("✗ SOME CHECKS FAILED - Review output above")
print("="*60)
return 0 if all_passed else 1
if __name__ == "__main__":
sys.exit(main())