moflo 4.8.32 → 4.8.34

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.
Files changed (40) hide show
  1. package/bin/generate-code-map.mjs +955 -955
  2. package/bin/index-guidance.mjs +905 -905
  3. package/bin/index-tests.mjs +728 -728
  4. package/bin/setup-project.mjs +252 -252
  5. package/package.json +10 -5
  6. package/src/@claude-flow/cli/dist/src/commands/doctor.js +1339 -1107
  7. package/src/@claude-flow/cli/dist/src/index.js +2 -18
  8. package/src/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +17 -0
  9. package/src/@claude-flow/cli/dist/src/memory/memory-initializer.js +4 -7
  10. package/src/@claude-flow/cli/dist/src/version.js +6 -0
  11. package/src/@claude-flow/cli/package.json +1 -1
  12. package/src/@claude-flow/neural/README.md +260 -0
  13. package/src/@claude-flow/neural/dist/algorithms/a2c.js +361 -0
  14. package/src/@claude-flow/neural/dist/algorithms/curiosity.js +392 -0
  15. package/src/@claude-flow/neural/dist/algorithms/decision-transformer.js +415 -0
  16. package/src/@claude-flow/neural/dist/algorithms/dqn.js +303 -0
  17. package/src/@claude-flow/neural/dist/algorithms/index.js +74 -0
  18. package/src/@claude-flow/neural/dist/algorithms/ppo.js +331 -0
  19. package/src/@claude-flow/neural/dist/algorithms/q-learning.js +259 -0
  20. package/src/@claude-flow/neural/dist/algorithms/sarsa.js +297 -0
  21. package/src/@claude-flow/neural/dist/application/index.js +7 -0
  22. package/src/@claude-flow/neural/dist/application/services/neural-application-service.js +161 -0
  23. package/src/@claude-flow/neural/dist/domain/entities/pattern.js +134 -0
  24. package/src/@claude-flow/neural/dist/domain/index.js +8 -0
  25. package/src/@claude-flow/neural/dist/domain/services/learning-service.js +195 -0
  26. package/src/@claude-flow/neural/dist/index.js +201 -0
  27. package/src/@claude-flow/neural/dist/modes/balanced.js +234 -0
  28. package/src/@claude-flow/neural/dist/modes/base.js +77 -0
  29. package/src/@claude-flow/neural/dist/modes/batch.js +316 -0
  30. package/src/@claude-flow/neural/dist/modes/edge.js +310 -0
  31. package/src/@claude-flow/neural/dist/modes/index.js +13 -0
  32. package/src/@claude-flow/neural/dist/modes/real-time.js +196 -0
  33. package/src/@claude-flow/neural/dist/modes/research.js +389 -0
  34. package/src/@claude-flow/neural/dist/pattern-learner.js +603 -0
  35. package/src/@claude-flow/neural/dist/reasoning-bank.js +993 -0
  36. package/src/@claude-flow/neural/dist/reasoningbank-adapter.js +463 -0
  37. package/src/@claude-flow/neural/dist/sona-integration.js +326 -0
  38. package/src/@claude-flow/neural/dist/sona-manager.js +695 -0
  39. package/src/@claude-flow/neural/dist/types.js +11 -0
  40. package/src/@claude-flow/neural/package.json +26 -0
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Neural Application Service - Application Layer
3
+ *
4
+ * Orchestrates neural learning operations.
5
+ *
6
+ * @module v3/neural/application/services
7
+ */
8
+ import { Pattern } from '../../domain/entities/pattern.js';
9
+ import { LearningDomainService } from '../../domain/services/learning-service.js';
10
+ /**
11
+ * Neural Application Service
12
+ */
13
+ export class NeuralApplicationService {
14
+ learningService;
15
+ constructor() {
16
+ this.learningService = new LearningDomainService();
17
+ }
18
+ // ============================================================================
19
+ // Learning Operations
20
+ // ============================================================================
21
+ /**
22
+ * Learn from a single trajectory
23
+ */
24
+ learn(trajectory) {
25
+ return this.learningService.updatePatterns(trajectory);
26
+ }
27
+ /**
28
+ * Train on batch of trajectories
29
+ */
30
+ train(trajectories) {
31
+ const start = Date.now();
32
+ let totalPatternsExtracted = 0;
33
+ let totalPatternsUpdated = 0;
34
+ let totalConfidenceChange = 0;
35
+ for (const trajectory of trajectories) {
36
+ const result = this.learningService.updatePatterns(trajectory);
37
+ totalPatternsExtracted += result.patternsExtracted;
38
+ totalPatternsUpdated += result.patternsUpdated;
39
+ totalConfidenceChange += result.confidenceChange;
40
+ }
41
+ return {
42
+ trajectoriesProcessed: trajectories.length,
43
+ patternsExtracted: totalPatternsExtracted,
44
+ patternsUpdated: totalPatternsUpdated,
45
+ averageConfidenceChange: trajectories.length > 0 ? totalConfidenceChange / trajectories.length : 0,
46
+ duration: Date.now() - start,
47
+ };
48
+ }
49
+ // ============================================================================
50
+ // Routing
51
+ // ============================================================================
52
+ /**
53
+ * Get route recommendation for task
54
+ */
55
+ route(taskDescription) {
56
+ return this.learningService.getRouteRecommendation(taskDescription);
57
+ }
58
+ /**
59
+ * Explain routing decision
60
+ */
61
+ explain(taskDescription) {
62
+ const recommendation = this.route(taskDescription);
63
+ const matchingPatterns = this.learningService
64
+ .getPatternsByType('task-routing')
65
+ .filter((p) => p.matches(taskDescription));
66
+ const reasoning = [];
67
+ if (matchingPatterns.length > 0) {
68
+ reasoning.push(`Found ${matchingPatterns.length} matching patterns`);
69
+ for (const p of matchingPatterns.slice(0, 3)) {
70
+ reasoning.push(`- Pattern "${p.name}": ${p.successRate.toFixed(2)} success rate, ${p.confidence.toFixed(2)} confidence`);
71
+ }
72
+ }
73
+ else {
74
+ reasoning.push('No matching patterns found, using keyword-based routing');
75
+ }
76
+ reasoning.push(`Recommended: ${recommendation.agentRole} (${(recommendation.confidence * 100).toFixed(0)}% confidence)`);
77
+ return {
78
+ recommendation,
79
+ matchingPatterns,
80
+ reasoning,
81
+ };
82
+ }
83
+ // ============================================================================
84
+ // Pattern Management
85
+ // ============================================================================
86
+ /**
87
+ * Get all patterns
88
+ */
89
+ getPatterns() {
90
+ return this.learningService.getPatterns();
91
+ }
92
+ /**
93
+ * Get patterns by type
94
+ */
95
+ getPatternsByType(type) {
96
+ return this.learningService.getPatternsByType(type);
97
+ }
98
+ /**
99
+ * Add custom pattern
100
+ */
101
+ addPattern(props) {
102
+ const pattern = Pattern.create({
103
+ type: props.type,
104
+ name: props.name,
105
+ description: props.description,
106
+ condition: props.condition,
107
+ action: props.action,
108
+ confidence: props.confidence ?? 0.5,
109
+ });
110
+ this.learningService.addPattern(pattern);
111
+ return pattern;
112
+ }
113
+ /**
114
+ * Remove pattern
115
+ */
116
+ removePattern(id) {
117
+ return this.learningService.removePattern(id);
118
+ }
119
+ /**
120
+ * Consolidate patterns
121
+ */
122
+ consolidate(minConfidence) {
123
+ return this.learningService.consolidate(minConfidence);
124
+ }
125
+ // ============================================================================
126
+ // Metrics
127
+ // ============================================================================
128
+ /**
129
+ * Get neural metrics
130
+ */
131
+ getMetrics() {
132
+ const patterns = this.learningService.getPatterns();
133
+ const patternsByType = {
134
+ 'task-routing': 0,
135
+ 'error-recovery': 0,
136
+ optimization: 0,
137
+ learning: 0,
138
+ };
139
+ let totalConfidence = 0;
140
+ let reliablePatterns = 0;
141
+ let totalSuccesses = 0;
142
+ let totalFailures = 0;
143
+ for (const pattern of patterns) {
144
+ patternsByType[pattern.type]++;
145
+ totalConfidence += pattern.confidence;
146
+ if (pattern.isReliable())
147
+ reliablePatterns++;
148
+ totalSuccesses += pattern.successCount;
149
+ totalFailures += pattern.failureCount;
150
+ }
151
+ return {
152
+ totalPatterns: patterns.length,
153
+ patternsByType,
154
+ averageConfidence: patterns.length > 0 ? totalConfidence / patterns.length : 0,
155
+ reliablePatterns,
156
+ totalSuccesses,
157
+ totalFailures,
158
+ };
159
+ }
160
+ }
161
+ //# sourceMappingURL=neural-application-service.js.map
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Pattern Entity - Domain Layer
3
+ *
4
+ * Represents a learned pattern for intelligent routing and optimization.
5
+ *
6
+ * @module v3/neural/domain/entities
7
+ */
8
+ import { randomUUID } from 'crypto';
9
+ /**
10
+ * Pattern Entity
11
+ */
12
+ export class Pattern {
13
+ _id;
14
+ _type;
15
+ _name;
16
+ _description;
17
+ _condition;
18
+ _action;
19
+ _confidence;
20
+ _successCount;
21
+ _failureCount;
22
+ _metadata;
23
+ _createdAt;
24
+ _updatedAt;
25
+ _lastMatchedAt;
26
+ constructor(props) {
27
+ const now = new Date();
28
+ this._id = props.id ?? randomUUID();
29
+ this._type = props.type;
30
+ this._name = props.name;
31
+ this._description = props.description;
32
+ this._condition = props.condition;
33
+ this._action = props.action;
34
+ this._confidence = props.confidence;
35
+ this._successCount = props.successCount ?? 0;
36
+ this._failureCount = props.failureCount ?? 0;
37
+ this._metadata = props.metadata ?? {};
38
+ this._createdAt = props.createdAt ?? now;
39
+ this._updatedAt = props.updatedAt ?? now;
40
+ this._lastMatchedAt = props.lastMatchedAt;
41
+ }
42
+ static create(props) {
43
+ return new Pattern(props);
44
+ }
45
+ static fromPersistence(props) {
46
+ return new Pattern(props);
47
+ }
48
+ get id() { return this._id; }
49
+ get type() { return this._type; }
50
+ get name() { return this._name; }
51
+ get description() { return this._description; }
52
+ get condition() { return this._condition; }
53
+ get action() { return this._action; }
54
+ get confidence() { return this._confidence; }
55
+ get successCount() { return this._successCount; }
56
+ get failureCount() { return this._failureCount; }
57
+ get metadata() { return { ...this._metadata }; }
58
+ get createdAt() { return new Date(this._createdAt); }
59
+ get updatedAt() { return new Date(this._updatedAt); }
60
+ get lastMatchedAt() { return this._lastMatchedAt ? new Date(this._lastMatchedAt) : undefined; }
61
+ /**
62
+ * Calculate success rate
63
+ */
64
+ get successRate() {
65
+ const total = this._successCount + this._failureCount;
66
+ return total > 0 ? this._successCount / total : 0;
67
+ }
68
+ /**
69
+ * Record successful match
70
+ */
71
+ recordSuccess() {
72
+ this._successCount++;
73
+ this._confidence = this.calculateConfidence();
74
+ this._lastMatchedAt = new Date();
75
+ this._updatedAt = new Date();
76
+ }
77
+ /**
78
+ * Record failed match
79
+ */
80
+ recordFailure() {
81
+ this._failureCount++;
82
+ this._confidence = this.calculateConfidence();
83
+ this._lastMatchedAt = new Date();
84
+ this._updatedAt = new Date();
85
+ }
86
+ /**
87
+ * Calculate confidence based on success rate
88
+ */
89
+ calculateConfidence() {
90
+ const total = this._successCount + this._failureCount;
91
+ if (total < 5)
92
+ return this._confidence; // Not enough data
93
+ const newConfidence = this.successRate;
94
+ // Weighted average with existing confidence
95
+ return this._confidence * 0.3 + newConfidence * 0.7;
96
+ }
97
+ /**
98
+ * Check if pattern matches input
99
+ */
100
+ matches(input) {
101
+ try {
102
+ const regex = new RegExp(this._condition, 'i');
103
+ return regex.test(input);
104
+ }
105
+ catch {
106
+ return input.toLowerCase().includes(this._condition.toLowerCase());
107
+ }
108
+ }
109
+ /**
110
+ * Check if pattern is reliable (high confidence, sufficient data)
111
+ */
112
+ isReliable() {
113
+ const total = this._successCount + this._failureCount;
114
+ return total >= 10 && this._confidence >= 0.7;
115
+ }
116
+ toPersistence() {
117
+ return {
118
+ id: this._id,
119
+ type: this._type,
120
+ name: this._name,
121
+ description: this._description,
122
+ condition: this._condition,
123
+ action: this._action,
124
+ confidence: this._confidence,
125
+ successCount: this._successCount,
126
+ failureCount: this._failureCount,
127
+ metadata: this._metadata,
128
+ createdAt: this._createdAt.toISOString(),
129
+ updatedAt: this._updatedAt.toISOString(),
130
+ lastMatchedAt: this._lastMatchedAt?.toISOString(),
131
+ };
132
+ }
133
+ }
134
+ //# sourceMappingURL=pattern.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Neural Domain Layer - Public Exports
3
+ *
4
+ * @module v3/neural/domain
5
+ */
6
+ export { Pattern, } from './entities/pattern.js';
7
+ export { LearningDomainService, } from './services/learning-service.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Learning Domain Service - Domain Layer
3
+ *
4
+ * Contains learning logic for pattern recognition and optimization.
5
+ *
6
+ * @module v3/neural/domain/services
7
+ */
8
+ import { Pattern } from '../entities/pattern.js';
9
+ /**
10
+ * Learning Domain Service
11
+ */
12
+ export class LearningDomainService {
13
+ patterns = new Map();
14
+ /**
15
+ * Extract patterns from trajectory
16
+ */
17
+ extractPatterns(trajectory) {
18
+ const extracted = [];
19
+ // Extract task-routing pattern
20
+ if (trajectory.outcome === 'success') {
21
+ const taskPattern = Pattern.create({
22
+ type: 'task-routing',
23
+ name: `route_${trajectory.id}`,
24
+ description: `Learned from successful trajectory`,
25
+ condition: this.extractCondition(trajectory.input),
26
+ action: trajectory.actions[0] ?? 'default',
27
+ confidence: 0.6 + trajectory.reward * 0.2,
28
+ metadata: { source: trajectory.id },
29
+ });
30
+ extracted.push(taskPattern);
31
+ }
32
+ // Extract error recovery pattern if failure
33
+ if (trajectory.outcome === 'failure' && trajectory.actions.length > 1) {
34
+ const lastAction = trajectory.actions[trajectory.actions.length - 1];
35
+ const recoveryPattern = Pattern.create({
36
+ type: 'error-recovery',
37
+ name: `recovery_${trajectory.id}`,
38
+ description: `Recovery action from failure`,
39
+ condition: `error:${trajectory.actions[0]}`,
40
+ action: lastAction,
41
+ confidence: 0.5,
42
+ metadata: { source: trajectory.id },
43
+ });
44
+ extracted.push(recoveryPattern);
45
+ }
46
+ return extracted;
47
+ }
48
+ /**
49
+ * Update patterns based on trajectory outcome
50
+ */
51
+ updatePatterns(trajectory) {
52
+ let patternsUpdated = 0;
53
+ let totalConfidenceChange = 0;
54
+ for (const pattern of this.patterns.values()) {
55
+ if (pattern.matches(trajectory.input)) {
56
+ const oldConfidence = pattern.confidence;
57
+ if (trajectory.outcome === 'success') {
58
+ pattern.recordSuccess();
59
+ }
60
+ else {
61
+ pattern.recordFailure();
62
+ }
63
+ totalConfidenceChange += pattern.confidence - oldConfidence;
64
+ patternsUpdated++;
65
+ }
66
+ }
67
+ // Extract and add new patterns
68
+ const newPatterns = this.extractPatterns(trajectory);
69
+ for (const pattern of newPatterns) {
70
+ this.patterns.set(pattern.id, pattern);
71
+ }
72
+ return {
73
+ patternsExtracted: newPatterns.length,
74
+ patternsUpdated,
75
+ confidenceChange: totalConfidenceChange,
76
+ };
77
+ }
78
+ /**
79
+ * Get route recommendation for task
80
+ */
81
+ getRouteRecommendation(taskDescription) {
82
+ const matchingPatterns = [];
83
+ for (const pattern of this.patterns.values()) {
84
+ if (pattern.type !== 'task-routing')
85
+ continue;
86
+ if (pattern.matches(taskDescription)) {
87
+ const score = pattern.confidence * (pattern.isReliable() ? 1.2 : 1.0);
88
+ matchingPatterns.push({ pattern, score });
89
+ }
90
+ }
91
+ // Sort by score
92
+ matchingPatterns.sort((a, b) => b.score - a.score);
93
+ if (matchingPatterns.length === 0) {
94
+ return this.getDefaultRecommendation(taskDescription);
95
+ }
96
+ const best = matchingPatterns[0];
97
+ const alternates = matchingPatterns.slice(1, 4).map((m) => ({
98
+ role: m.pattern.action,
99
+ confidence: m.score,
100
+ }));
101
+ return {
102
+ agentRole: best.pattern.action,
103
+ confidence: best.score,
104
+ reasoning: `Based on pattern "${best.pattern.name}" with ${best.pattern.successCount} successes`,
105
+ alternates,
106
+ };
107
+ }
108
+ /**
109
+ * Get default recommendation based on keywords
110
+ */
111
+ getDefaultRecommendation(task) {
112
+ const taskLower = task.toLowerCase();
113
+ const keywordMap = {
114
+ code: 'coder',
115
+ implement: 'coder',
116
+ write: 'coder',
117
+ test: 'tester',
118
+ review: 'reviewer',
119
+ plan: 'planner',
120
+ research: 'researcher',
121
+ security: 'security-architect',
122
+ performance: 'performance-engineer',
123
+ memory: 'memory-specialist',
124
+ };
125
+ for (const [keyword, role] of Object.entries(keywordMap)) {
126
+ if (taskLower.includes(keyword)) {
127
+ return {
128
+ agentRole: role,
129
+ confidence: 0.5,
130
+ reasoning: `Keyword match: "${keyword}"`,
131
+ alternates: [],
132
+ };
133
+ }
134
+ }
135
+ return {
136
+ agentRole: 'coder',
137
+ confidence: 0.3,
138
+ reasoning: 'Default fallback',
139
+ alternates: [],
140
+ };
141
+ }
142
+ /**
143
+ * Extract condition from input
144
+ */
145
+ extractCondition(input) {
146
+ // Extract key terms from input
147
+ const words = input.toLowerCase().split(/\s+/);
148
+ const keyWords = words.filter((w) => w.length > 4).slice(0, 5);
149
+ return keyWords.join('|');
150
+ }
151
+ /**
152
+ * Consolidate patterns (merge duplicates, prune low-confidence)
153
+ */
154
+ consolidate(minConfidence = 0.3) {
155
+ let merged = 0;
156
+ let pruned = 0;
157
+ const toRemove = [];
158
+ for (const [id, pattern] of this.patterns) {
159
+ // Prune low confidence patterns with enough data
160
+ if (pattern.confidence < minConfidence && pattern.successCount + pattern.failureCount > 20) {
161
+ toRemove.push(id);
162
+ pruned++;
163
+ }
164
+ }
165
+ for (const id of toRemove) {
166
+ this.patterns.delete(id);
167
+ }
168
+ return { merged, pruned };
169
+ }
170
+ /**
171
+ * Get all patterns
172
+ */
173
+ getPatterns() {
174
+ return Array.from(this.patterns.values());
175
+ }
176
+ /**
177
+ * Get patterns by type
178
+ */
179
+ getPatternsByType(type) {
180
+ return Array.from(this.patterns.values()).filter((p) => p.type === type);
181
+ }
182
+ /**
183
+ * Add pattern
184
+ */
185
+ addPattern(pattern) {
186
+ this.patterns.set(pattern.id, pattern);
187
+ }
188
+ /**
189
+ * Remove pattern
190
+ */
191
+ removePattern(id) {
192
+ return this.patterns.delete(id);
193
+ }
194
+ }
195
+ //# sourceMappingURL=learning-service.js.map
@@ -0,0 +1,201 @@
1
+ /**
2
+ * V3 Neural/Learning System
3
+ *
4
+ * Complete neural learning module with SONA learning modes,
5
+ * ReasoningBank integration, pattern learning, and RL algorithms.
6
+ *
7
+ * Performance Targets:
8
+ * - SONA adaptation: <0.05ms
9
+ * - Pattern matching: <1ms
10
+ * - Learning step: <10ms
11
+ *
12
+ * @module @claude-flow/neural
13
+ */
14
+ // =============================================================================
15
+ // SONA Manager
16
+ // =============================================================================
17
+ export { SONAManager, createSONAManager, getModeConfig, getModeOptimizations, } from './sona-manager.js';
18
+ export { BaseModeImplementation, RealTimeMode, BalancedMode, ResearchMode, EdgeMode, BatchMode, } from './modes/index.js';
19
+ // =============================================================================
20
+ // SONA Integration (@ruvector/sona)
21
+ // =============================================================================
22
+ export { SONALearningEngine, createSONALearningEngine, } from './sona-integration.js';
23
+ // =============================================================================
24
+ // ReasoningBank
25
+ // =============================================================================
26
+ export { ReasoningBank, createReasoningBank, createInitializedReasoningBank, } from './reasoning-bank.js';
27
+ // =============================================================================
28
+ // Pattern Learner
29
+ // =============================================================================
30
+ export { PatternLearner, createPatternLearner, } from './pattern-learner.js';
31
+ // =============================================================================
32
+ // RL Algorithms
33
+ // =============================================================================
34
+ export {
35
+ // PPO
36
+ PPOAlgorithm, createPPO, DEFAULT_PPO_CONFIG,
37
+ // DQN
38
+ DQNAlgorithm, createDQN, DEFAULT_DQN_CONFIG,
39
+ // A2C
40
+ A2CAlgorithm, createA2C, DEFAULT_A2C_CONFIG,
41
+ // Decision Transformer
42
+ DecisionTransformer, createDecisionTransformer, DEFAULT_DT_CONFIG,
43
+ // Q-Learning
44
+ QLearning, createQLearning, DEFAULT_QLEARNING_CONFIG,
45
+ // SARSA
46
+ SARSAAlgorithm, createSARSA, DEFAULT_SARSA_CONFIG,
47
+ // Curiosity
48
+ CuriosityModule, createCuriosity, DEFAULT_CURIOSITY_CONFIG,
49
+ // Factory functions
50
+ createAlgorithm, getDefaultConfig, } from './algorithms/index.js';
51
+ // =============================================================================
52
+ // Convenience Factory
53
+ // =============================================================================
54
+ import { SONAManager, createSONAManager } from './sona-manager.js';
55
+ import { ReasoningBank, createReasoningBank } from './reasoning-bank.js';
56
+ import { PatternLearner, createPatternLearner } from './pattern-learner.js';
57
+ import { SONALearningEngine, createSONALearningEngine } from './sona-integration.js';
58
+ /**
59
+ * Neural Learning System - Complete integrated learning module
60
+ */
61
+ export class NeuralLearningSystem {
62
+ sona;
63
+ reasoningBank;
64
+ patternLearner;
65
+ initialized = false;
66
+ constructor(mode = 'balanced') {
67
+ this.sona = createSONAManager(mode);
68
+ this.reasoningBank = createReasoningBank();
69
+ this.patternLearner = createPatternLearner();
70
+ }
71
+ /**
72
+ * Initialize the learning system
73
+ */
74
+ async initialize() {
75
+ if (this.initialized)
76
+ return;
77
+ await this.sona.initialize();
78
+ this.initialized = true;
79
+ }
80
+ /**
81
+ * Get SONA manager
82
+ */
83
+ getSONAManager() {
84
+ return this.sona;
85
+ }
86
+ /**
87
+ * Get ReasoningBank
88
+ */
89
+ getReasoningBank() {
90
+ return this.reasoningBank;
91
+ }
92
+ /**
93
+ * Get Pattern Learner
94
+ */
95
+ getPatternLearner() {
96
+ return this.patternLearner;
97
+ }
98
+ /**
99
+ * Change learning mode
100
+ */
101
+ async setMode(mode) {
102
+ await this.sona.setMode(mode);
103
+ }
104
+ /**
105
+ * Begin tracking a task
106
+ */
107
+ beginTask(context, domain = 'general') {
108
+ return this.sona.beginTrajectory(context, domain);
109
+ }
110
+ /**
111
+ * Record a step in the current task
112
+ */
113
+ recordStep(trajectoryId, action, reward, stateEmbedding) {
114
+ this.sona.recordStep(trajectoryId, action, reward, stateEmbedding);
115
+ }
116
+ /**
117
+ * Complete a task and trigger learning
118
+ */
119
+ async completeTask(trajectoryId, quality) {
120
+ const trajectory = this.sona.completeTrajectory(trajectoryId, quality);
121
+ if (trajectory) {
122
+ // Store in reasoning bank
123
+ this.reasoningBank.storeTrajectory(trajectory);
124
+ // Judge and potentially distill
125
+ await this.reasoningBank.judge(trajectory);
126
+ const memory = await this.reasoningBank.distill(trajectory);
127
+ // Extract pattern if successful
128
+ if (memory) {
129
+ this.patternLearner.extractPattern(trajectory, memory);
130
+ }
131
+ }
132
+ }
133
+ /**
134
+ * Find similar patterns for a task
135
+ */
136
+ async findPatterns(queryEmbedding, k = 3) {
137
+ return this.patternLearner.findMatches(queryEmbedding, k);
138
+ }
139
+ /**
140
+ * Retrieve relevant memories
141
+ */
142
+ async retrieveMemories(queryEmbedding, k = 3) {
143
+ return this.reasoningBank.retrieve(queryEmbedding, k);
144
+ }
145
+ /**
146
+ * Trigger learning cycle
147
+ */
148
+ async triggerLearning() {
149
+ await this.sona.triggerLearning('manual');
150
+ await this.reasoningBank.consolidate();
151
+ }
152
+ /**
153
+ * Get comprehensive statistics
154
+ */
155
+ getStats() {
156
+ return {
157
+ sona: this.sona.getStats(),
158
+ reasoningBank: this.reasoningBank.getStats(),
159
+ patternLearner: this.patternLearner.getStats(),
160
+ };
161
+ }
162
+ /**
163
+ * Add event listener
164
+ */
165
+ addEventListener(listener) {
166
+ this.sona.addEventListener(listener);
167
+ this.reasoningBank.addEventListener(listener);
168
+ this.patternLearner.addEventListener(listener);
169
+ }
170
+ /**
171
+ * Cleanup resources
172
+ */
173
+ async cleanup() {
174
+ await this.sona.cleanup();
175
+ this.initialized = false;
176
+ }
177
+ }
178
+ /**
179
+ * Create a complete neural learning system
180
+ */
181
+ export function createNeuralLearningSystem(mode = 'balanced') {
182
+ return new NeuralLearningSystem(mode);
183
+ }
184
+ // =============================================================================
185
+ // Default Export
186
+ // =============================================================================
187
+ export default {
188
+ // Factories
189
+ createSONAManager,
190
+ createReasoningBank,
191
+ createPatternLearner,
192
+ createNeuralLearningSystem,
193
+ createSONALearningEngine,
194
+ // Classes
195
+ SONAManager,
196
+ ReasoningBank,
197
+ PatternLearner,
198
+ NeuralLearningSystem,
199
+ SONALearningEngine,
200
+ };
201
+ //# sourceMappingURL=index.js.map