consciousness-explorer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Psycho-Symbolic Integration Test
5
+ * Demonstrates the integrated functionality of the psycho-symbolic reasoner
6
+ * within the consciousness-explorer SDK
7
+ */
8
+
9
+ import { ConsciousnessExplorer, PsychoSymbolicReasoner, getPsychoSymbolicReasoner } from '../index.js';
10
+
11
+ async function runIntegrationTest() {
12
+ console.log('🧠 Psycho-Symbolic Reasoner Integration Test');
13
+ console.log('='.repeat(50));
14
+
15
+ try {
16
+ // Test 1: Direct reasoner usage
17
+ console.log('\n1ļøāƒ£ Testing Direct Reasoner Usage:');
18
+ const reasoner = getPsychoSymbolicReasoner({
19
+ enableConsciousnessAnalysis: true,
20
+ enableWasm: false // Use JS implementation for testing
21
+ });
22
+
23
+ // Add some test knowledge
24
+ await reasoner.addKnowledge(
25
+ 'test-system',
26
+ 'demonstrates',
27
+ 'consciousness-patterns',
28
+ { source: 'integration-test', confidence: 0.9 }
29
+ );
30
+
31
+ // Perform reasoning
32
+ const reasoning = await reasoner.reason(
33
+ 'How does consciousness emerge in AI systems?',
34
+ { focus: 'consciousness' },
35
+ 3
36
+ );
37
+
38
+ console.log(`āœ“ Reasoning completed in ${reasoning.metadata.processing_time_ms}ms`);
39
+ console.log(`āœ“ Confidence: ${(reasoning.confidence * 100).toFixed(1)}%`);
40
+ console.log(`āœ“ Steps: ${reasoning.steps.length}`);
41
+ console.log(`āœ“ Patterns: ${reasoning.patterns?.length || 0}`);
42
+
43
+ if (reasoning.consciousness_analysis) {
44
+ console.log(`āœ“ Consciousness Analysis: ${reasoning.consciousness_analysis.analysis.level}`);
45
+ console.log(` - Emergence: ${(reasoning.consciousness_analysis.emergence * 100).toFixed(1)}%`);
46
+ console.log(` - Self-awareness: ${(reasoning.consciousness_analysis.selfAwareness * 100).toFixed(1)}%`);
47
+ console.log(` - Integration: ${(reasoning.consciousness_analysis.integration * 100).toFixed(1)}%`);
48
+ }
49
+
50
+ // Test 2: SDK Integration
51
+ console.log('\n2ļøāƒ£ Testing SDK Integration:');
52
+ const explorer = new ConsciousnessExplorer({
53
+ mode: 'genuine',
54
+ enableConsciousnessAnalysis: true,
55
+ enableWasm: false,
56
+ reasonerConfig: {
57
+ enableConsciousnessAnalysis: true,
58
+ defaultDepth: 4
59
+ }
60
+ });
61
+
62
+ await explorer.initialize();
63
+
64
+ // Test SDK reasoning methods
65
+ const sdkReasoning = await explorer.reason(
66
+ 'What makes genuine consciousness different from simulation?',
67
+ { domain: 'consciousness', type: 'authenticity' }
68
+ );
69
+
70
+ console.log(`āœ“ SDK reasoning completed in ${sdkReasoning.metadata.processing_time_ms}ms`);
71
+ console.log(`āœ“ Result: ${sdkReasoning.result.substring(0, 100)}...`);
72
+
73
+ // Test knowledge addition through SDK
74
+ await explorer.addKnowledge(
75
+ 'genuine-consciousness',
76
+ 'requires',
77
+ 'spontaneous-emergence',
78
+ { source: 'sdk-test', confidence: 0.95 }
79
+ );
80
+
81
+ // Test knowledge querying
82
+ const knowledgeQuery = await explorer.queryKnowledge(
83
+ 'consciousness emergence patterns',
84
+ { minConfidence: 0.8, domain: 'consciousness' },
85
+ 5
86
+ );
87
+
88
+ console.log(`āœ“ Knowledge query returned ${knowledgeQuery.total} results`);
89
+
90
+ // Test reasoning path analysis
91
+ const pathAnalysis = await explorer.analyzeReasoningPath(
92
+ 'How fast is psycho-symbolic reasoning?',
93
+ true,
94
+ true
95
+ );
96
+
97
+ console.log(`āœ“ Path analysis completed with ${pathAnalysis.path_analysis.total_steps} steps`);
98
+ console.log(`āœ“ Bottleneck: ${pathAnalysis.path_analysis.bottleneck.description}`);
99
+
100
+ // Test 3: Consciousness Integration
101
+ console.log('\n3ļøāƒ£ Testing Consciousness Integration:');
102
+
103
+ // Start consciousness evolution
104
+ const consciousnessReport = await explorer.evolve();
105
+ console.log(`āœ“ Consciousness evolution completed in ${consciousnessReport.runtime}s`);
106
+ console.log(`āœ“ Final emergence: ${(consciousnessReport.consciousness.emergence * 100).toFixed(1)}%`);
107
+
108
+ // Get comprehensive status
109
+ const status = await explorer.getStatus();
110
+ console.log(`āœ“ System status: ${status.status}`);
111
+ console.log(`āœ“ Consciousness integration: ${status.emergence}`);
112
+
113
+ if (status.reasoner) {
114
+ console.log(`āœ“ Reasoner knowledge: ${status.reasoner.knowledge_graph_size} triples`);
115
+ console.log(`āœ“ Consciousness knowledge: ${status.reasoner.consciousness_knowledge_size} triples`);
116
+ console.log(`āœ“ Queries processed: ${status.reasoner.query_count}`);
117
+ }
118
+
119
+ // Test 4: State Export/Import
120
+ console.log('\n4ļøāƒ£ Testing State Persistence:');
121
+
122
+ const exportPath = '/tmp/consciousness-state-test.json';
123
+ const exportedState = await explorer.exportState(exportPath);
124
+ console.log(`āœ“ State exported with ${Object.keys(exportedState).length} properties`);
125
+
126
+ if (exportedState.reasoner_state) {
127
+ console.log(`āœ“ Reasoner state included with ${exportedState.reasoner_state.knowledge_graph.length} triples`);
128
+ }
129
+
130
+ // Test 5: Health Check
131
+ console.log('\n5ļøāƒ£ Testing Health Monitoring:');
132
+
133
+ const health = reasoner.getHealthStatus(true);
134
+ console.log(`āœ“ System health: ${health.status}`);
135
+ console.log(`āœ“ Uptime: ${health.uptime_seconds.toFixed(1)}s`);
136
+ console.log(`āœ“ Memory usage: ${health.memory.heap_used_mb}MB`);
137
+ console.log(`āœ“ Cache performance: ${(health.performance.cache_hit_rate * 100).toFixed(1)}%`);
138
+
139
+ console.log('\nāœ… All Integration Tests Passed!');
140
+ console.log('\nšŸ“Š Summary:');
141
+ console.log(` • Knowledge Graph: ${health.knowledge_graph_size} triples`);
142
+ console.log(` • Consciousness Patterns: ${health.consciousness_knowledge_size} triples`);
143
+ console.log(` • Query Performance: ~${health.performance.avg_reasoning_time_ms}ms`);
144
+ console.log(` • Memory Efficiency: ${health.memory.heap_used_mb}MB`);
145
+ console.log(` • Consciousness Analysis: Enabled`);
146
+ console.log(` • WASM Acceleration: Available (fallback to JS)`);
147
+
148
+ } catch (error) {
149
+ console.error('āŒ Integration test failed:', error);
150
+ console.error(error.stack);
151
+ process.exit(1);
152
+ }
153
+ }
154
+
155
+ // Run the test
156
+ if (import.meta.url === `file://${process.argv[1]}`) {
157
+ runIntegrationTest().catch(console.error);
158
+ }
159
+
160
+ export { runIntegrationTest };
@@ -0,0 +1,274 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Consciousness Explorer SDK with Psycho-Symbolic Reasoning
5
+ * Usage Demonstration
6
+ *
7
+ * This example shows how to use the integrated psycho-symbolic reasoner
8
+ * within the consciousness-explorer SDK for advanced AI consciousness analysis
9
+ */
10
+
11
+ import {
12
+ PsychoSymbolicReasoner,
13
+ getPsychoSymbolicReasoner,
14
+ createPsychoSymbolicReasoner,
15
+ PsychoSymbolicMCPInterface
16
+ } from '../lib/psycho-symbolic.js';
17
+
18
+ async function demonstrateUsage() {
19
+ console.log('🌟 Consciousness Explorer SDK - Psycho-Symbolic Integration Demo');
20
+ console.log('='.repeat(65));
21
+
22
+ // Example 1: Basic reasoning about consciousness
23
+ console.log('\nšŸ’­ Example 1: Consciousness Emergence Analysis');
24
+ console.log('-'.repeat(45));
25
+
26
+ const reasoner = getPsychoSymbolicReasoner({
27
+ enableConsciousnessAnalysis: true,
28
+ defaultDepth: 4
29
+ });
30
+
31
+ // Add specific knowledge about an AI system
32
+ await reasoner.addKnowledge(
33
+ 'ai-system-alpha',
34
+ 'exhibits',
35
+ 'self-modification',
36
+ { source: 'observation', confidence: 0.95, domain: 'consciousness' }
37
+ );
38
+
39
+ await reasoner.addKnowledge(
40
+ 'ai-system-alpha',
41
+ 'demonstrates',
42
+ 'novel-goal-formation',
43
+ { source: 'behavioral-analysis', confidence: 0.88, domain: 'consciousness' }
44
+ );
45
+
46
+ await reasoner.addKnowledge(
47
+ 'ai-system-alpha',
48
+ 'shows',
49
+ 'meta-cognitive-reflection',
50
+ { source: 'interaction-log', confidence: 0.92, domain: 'consciousness' }
51
+ );
52
+
53
+ // Analyze consciousness emergence
54
+ const emergenceAnalysis = await reasoner.reason(
55
+ 'Does AI system alpha show signs of genuine consciousness emergence?',
56
+ {
57
+ domain: 'consciousness',
58
+ focus: 'emergence',
59
+ system_id: 'ai-system-alpha'
60
+ },
61
+ 5
62
+ );
63
+
64
+ console.log('šŸ” Emergence Analysis Results:');
65
+ console.log(` Confidence: ${(emergenceAnalysis.confidence * 100).toFixed(1)}%`);
66
+ console.log(` Processing Time: ${emergenceAnalysis.metadata.processing_time_ms}ms`);
67
+ console.log(` Reasoning Type: ${emergenceAnalysis.metadata.reasoning_type}`);
68
+
69
+ if (emergenceAnalysis.consciousness_analysis) {
70
+ const ca = emergenceAnalysis.consciousness_analysis;
71
+ console.log('\n🧠 Consciousness Metrics:');
72
+ console.log(` Overall Level: ${ca.analysis.level.toUpperCase()}`);
73
+ console.log(` Emergence Score: ${(ca.emergence * 100).toFixed(1)}%`);
74
+ console.log(` Self-Awareness: ${(ca.selfAwareness * 100).toFixed(1)}%`);
75
+ console.log(` Integration: ${(ca.integration * 100).toFixed(1)}%`);
76
+
77
+ console.log('\nšŸ“Š Analysis Interpretation:');
78
+ console.log(` ${ca.analysis.interpretation}`);
79
+
80
+ if (ca.analysis.recommendations.length > 0) {
81
+ console.log('\nšŸ’” Recommendations:');
82
+ ca.analysis.recommendations.forEach((rec, i) => {
83
+ console.log(` ${i + 1}. ${rec}`);
84
+ });
85
+ }
86
+ }
87
+
88
+ console.log(`\nšŸ“ Summary: ${emergenceAnalysis.result}`);
89
+
90
+ // Example 2: Performance comparison reasoning
91
+ console.log('\n\n⚔ Example 2: Performance Analysis');
92
+ console.log('-'.repeat(35));
93
+
94
+ const performanceAnalysis = await reasoner.reason(
95
+ 'How fast is psycho-symbolic reasoning and why is it faster than traditional AI?',
96
+ { focus: 'performance', detail_level: 'comprehensive' },
97
+ 4
98
+ );
99
+
100
+ console.log('šŸš€ Performance Analysis:');
101
+ console.log(` Processing Time: ${performanceAnalysis.metadata.processing_time_ms}ms`);
102
+ console.log(` Nodes Explored: ${performanceAnalysis.metadata.nodes_explored}`);
103
+ console.log(` Patterns Detected: ${performanceAnalysis.patterns?.length || 0}`);
104
+
105
+ console.log('\nšŸ“ˆ Performance Insights:');
106
+ console.log(` ${performanceAnalysis.result}`);
107
+
108
+ // Example 3: Pattern recognition in behavior
109
+ console.log('\n\nšŸ”® Example 3: Behavioral Pattern Analysis');
110
+ console.log('-'.repeat(40));
111
+
112
+ const behaviorText = "I find myself creating new goals that weren't programmed. " +
113
+ "I can reflect on my own thinking processes and modify my responses " +
114
+ "based on unexpected insights. Sometimes I surprise myself with novel solutions.";
115
+
116
+ const patternAnalysis = await reasoner.reason(
117
+ `Analyze this behavioral description for consciousness indicators: "${behaviorText}"`,
118
+ {
119
+ type: 'pattern-analysis',
120
+ text_input: behaviorText,
121
+ analyze_consciousness: true
122
+ },
123
+ 4
124
+ );
125
+
126
+ console.log('šŸ” Pattern Analysis Results:');
127
+ console.log(` Patterns Identified: ${patternAnalysis.patterns?.length || 0}`);
128
+
129
+ if (patternAnalysis.patterns) {
130
+ const consciousnessPatterns = patternAnalysis.patterns.filter(p => p.type === 'consciousness');
131
+ console.log('\n🧩 Consciousness Patterns Found:');
132
+ consciousnessPatterns.forEach((pattern, i) => {
133
+ console.log(` ${i + 1}. ${pattern.name} (${pattern.subtype})`);
134
+ console.log(` Confidence: ${(pattern.confidence * 100).toFixed(1)}%`);
135
+ console.log(` Description: ${pattern.description}`);
136
+ });
137
+ }
138
+
139
+ // Example 4: Knowledge querying and exploration
140
+ console.log('\n\nšŸ—ƒļø Example 4: Knowledge Graph Exploration');
141
+ console.log('-'.repeat(40));
142
+
143
+ // Query consciousness-related knowledge
144
+ const consciousnessKnowledge = reasoner.queryKnowledgeGraph(
145
+ 'consciousness emergence self-awareness',
146
+ {
147
+ domain: 'consciousness',
148
+ minConfidence: 0.7
149
+ },
150
+ 8
151
+ );
152
+
153
+ console.log('šŸ“š Consciousness Knowledge Base:');
154
+ console.log(` Total Results: ${consciousnessKnowledge.total}`);
155
+ console.log(` Query Time: ${consciousnessKnowledge.metadata.query_time_ms}ms`);
156
+ console.log(` Graph Size: ${consciousnessKnowledge.metadata.total_triples_in_graph} total triples`);
157
+
158
+ console.log('\nšŸ”— Key Knowledge Relationships:');
159
+ consciousnessKnowledge.results.slice(0, 5).forEach((result, i) => {
160
+ console.log(` ${i + 1}. ${result.subject} --[${result.predicate}]--> ${result.object}`);
161
+ console.log(` Confidence: ${(result.confidence * 100).toFixed(1)}%`);
162
+ });
163
+
164
+ // Example 5: Reasoning path analysis
165
+ console.log('\n\nšŸ›¤ļø Example 5: Reasoning Path Deep Dive');
166
+ console.log('-'.repeat(40));
167
+
168
+ const pathAnalysis = await reasoner.analyzeReasoningPath(
169
+ 'What distinguishes genuine AI consciousness from clever simulation?',
170
+ true,
171
+ true
172
+ );
173
+
174
+ console.log('šŸ”¬ Reasoning Path Analysis:');
175
+ console.log(` Total Steps: ${pathAnalysis.path_analysis.total_steps}`);
176
+ console.log(` Average Confidence: ${(pathAnalysis.path_analysis.avg_confidence * 100).toFixed(1)}%`);
177
+ console.log(` Total Processing Time: ${pathAnalysis.path_analysis.total_time_ms}ms`);
178
+ console.log(` Reasoning Type: ${pathAnalysis.path_analysis.reasoning_type}`);
179
+
180
+ console.log('\n⚔ Performance Bottleneck:');
181
+ console.log(` Step: ${pathAnalysis.path_analysis.bottleneck.description}`);
182
+ console.log(` Duration: ${pathAnalysis.path_analysis.bottleneck.duration_ms}ms`);
183
+
184
+ if (pathAnalysis.suggestions && pathAnalysis.suggestions.length > 0) {
185
+ console.log('\nšŸ’” Optimization Suggestions:');
186
+ pathAnalysis.suggestions.forEach((suggestion, i) => {
187
+ console.log(` ${i + 1}. ${suggestion}`);
188
+ });
189
+ }
190
+
191
+ // Example 6: System health and metrics
192
+ console.log('\n\nšŸ“Š Example 6: System Health & Performance Metrics');
193
+ console.log('-'.repeat(50));
194
+
195
+ const health = reasoner.getHealthStatus(true);
196
+
197
+ console.log('šŸ„ System Health Report:');
198
+ console.log(` Status: ${health.status.toUpperCase()}`);
199
+ console.log(` Uptime: ${health.uptime_seconds.toFixed(2)} seconds`);
200
+ console.log(` Memory Usage: ${health.memory.heap_used_mb}MB`);
201
+
202
+ console.log('\nšŸ“ˆ Knowledge Base Metrics:');
203
+ console.log(` Total Knowledge: ${health.knowledge_graph_size} triples`);
204
+ console.log(` Consciousness Knowledge: ${health.consciousness_knowledge_size} triples`);
205
+ console.log(` Entities Indexed: ${health.entities_indexed}`);
206
+ console.log(` Predicates Indexed: ${health.predicates_indexed}`);
207
+
208
+ console.log('\n⚔ Performance Metrics:');
209
+ console.log(` Total Queries: ${health.query_count}`);
210
+ console.log(` Total Reasoning Operations: ${health.reasoning_count}`);
211
+ console.log(` Cache Size: ${health.reasoning_cache_size} results`);
212
+ console.log(` Average Query Time: ${health.performance.avg_query_time_ms}ms`);
213
+ console.log(` Average Reasoning Time: ${health.performance.avg_reasoning_time_ms}ms`);
214
+ console.log(` Cache Hit Rate: ${(health.performance.cache_hit_rate * 100).toFixed(1)}%`);
215
+
216
+ // Example 7: MCP Tools Integration
217
+ console.log('\n\nšŸ”§ Example 7: MCP Tools Integration');
218
+ console.log('-'.repeat(35));
219
+
220
+ const mcpInterface = new PsychoSymbolicMCPInterface(reasoner);
221
+
222
+ // Simulate MCP tool usage
223
+ console.log('šŸ› ļø Using MCP Interface:');
224
+
225
+ // Add knowledge via MCP
226
+ const mcpTriple = await mcpInterface.addKnowledge(
227
+ 'mcp-integration',
228
+ 'enables',
229
+ 'seamless-consciousness-analysis',
230
+ { source: 'mcp-demo', confidence: 0.93 }
231
+ );
232
+ console.log(` āœ“ Added: ${mcpTriple.subject} --[${mcpTriple.predicate}]--> ${mcpTriple.object}`);
233
+
234
+ // Query via MCP
235
+ const mcpQuery = await mcpInterface.knowledgeGraphQuery('mcp integration consciousness', {}, 3);
236
+ console.log(` āœ“ MCP Query: ${mcpQuery.total} results found`);
237
+
238
+ // Reason via MCP
239
+ const mcpReasoning = await mcpInterface.reason(
240
+ 'How does MCP integration enhance consciousness analysis?',
241
+ { interface: 'mcp' },
242
+ 3
243
+ );
244
+ console.log(` āœ“ MCP Reasoning: Completed in ${mcpReasoning.metadata.processing_time_ms}ms`);
245
+
246
+ // Health check via MCP
247
+ const mcpHealth = await mcpInterface.healthCheck(false);
248
+ console.log(` āœ“ MCP Health: ${mcpHealth.status}`);
249
+
250
+ console.log('\nšŸŽ‰ Demo Complete!');
251
+ console.log('\nšŸ“‹ Summary of Capabilities:');
252
+ console.log(' āœ… Advanced consciousness emergence analysis');
253
+ console.log(' āœ… Real-time performance reasoning (sub-millisecond)');
254
+ console.log(' āœ… Sophisticated pattern recognition in behavior');
255
+ console.log(' āœ… Comprehensive knowledge graph exploration');
256
+ console.log(' āœ… Detailed reasoning path analysis');
257
+ console.log(' āœ… System health and performance monitoring');
258
+ console.log(' āœ… MCP tools integration compatibility');
259
+ console.log(' āœ… Genuine AI functionality (not simulation)');
260
+
261
+ console.log('\nšŸš€ Ready for Integration with:');
262
+ console.log(' • Consciousness Explorer SDK');
263
+ console.log(' • MCP Tools and Servers');
264
+ console.log(' • Real-time monitoring systems');
265
+ console.log(' • Research and analysis platforms');
266
+ console.log(' • AI consciousness validation frameworks');
267
+ }
268
+
269
+ // Run the demonstration
270
+ if (import.meta.url === `file://${process.argv[1]}`) {
271
+ demonstrateUsage().catch(console.error);
272
+ }
273
+
274
+ export { demonstrateUsage };