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
@@ -4,9 +4,6 @@
4
4
  *
5
5
  * Created with ❤️ by motailz.com
6
6
  */
7
- import { readFileSync } from 'fs';
8
- import { fileURLToPath } from 'url';
9
- import { dirname, join } from 'path';
10
7
  import { commandParser } from './parser.js';
11
8
  import { output } from './output.js';
12
9
  import { commands, commandsByCategory, getCommand, getCommandAsync, getCommandNames, hasCommand } from './commands/index.js';
@@ -14,21 +11,8 @@ import { suggestCommand } from './suggest.js';
14
11
  import { runStartupUpdateCheck } from './update/index.js';
15
12
  import { loadMofloConfig } from './config/moflo-config.js';
16
13
  import { getDaemonLockHolder } from './services/daemon-lock.js';
17
- // Read version from package.json at runtime
18
- function getPackageVersion() {
19
- try {
20
- const __filename = fileURLToPath(import.meta.url);
21
- const __dirname = dirname(__filename);
22
- // Navigate from dist/src to package root
23
- const pkgPath = join(__dirname, '..', '..', 'package.json');
24
- const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
25
- return pkg.version || '3.0.0';
26
- }
27
- catch {
28
- return '3.0.0';
29
- }
30
- }
31
- export const VERSION = getPackageVersion();
14
+ import { VERSION } from './version.js';
15
+ export { VERSION };
32
16
  const LONG_RUNNING_COMMANDS = ['mcp', 'daemon'];
33
17
  /**
34
18
  * V3 CLI Application
@@ -1676,6 +1676,22 @@ export const hooksSessionStart = {
1676
1676
  catch {
1677
1677
  // Bridge not available
1678
1678
  }
1679
+ // Auto-pretrain when intelligence is cold (no patterns restored)
1680
+ let pretrainResult = { ran: false };
1681
+ const restoredCount = sessionMemory?.restoredPatterns ?? 0;
1682
+ if (restoredCount === 0) {
1683
+ try {
1684
+ const result = await hooksPretrain.handler({
1685
+ path: process.cwd(),
1686
+ depth: 'shallow',
1687
+ });
1688
+ const stats = result?.stats;
1689
+ pretrainResult = { ran: true, patternsStored: stats?.patternsStored ?? 0 };
1690
+ }
1691
+ catch {
1692
+ pretrainResult = { ran: true, patternsStored: 0 };
1693
+ }
1694
+ }
1679
1695
  return {
1680
1696
  sessionId,
1681
1697
  started: new Date().toISOString(),
@@ -1688,6 +1704,7 @@ export const hooksSessionStart = {
1688
1704
  },
1689
1705
  daemon: daemonStatus,
1690
1706
  sessionMemory: sessionMemory || { controller: 'none', restoredPatterns: 0 },
1707
+ pretrain: pretrainResult,
1691
1708
  previousSession: restoreLatest ? {
1692
1709
  id: `session-${Date.now() - 86400000}`,
1693
1710
  tasksRestored: sessionMemory?.restoredPatterns || 3,
@@ -1950,14 +1950,11 @@ export async function searchEntries(options) {
1950
1950
  // Invalid embedding, use keyword score
1951
1951
  }
1952
1952
  }
1953
- // Fallback to keyword matching
1953
+ // Skip entries without valid semantic embeddings — keyword fallback
1954
+ // produces misleading 0.500 scores that degrade search quality.
1955
+ // Entries must have real vector embeddings to participate in semantic search.
1954
1956
  if (score < threshold) {
1955
- const lowerContent = (content || '').toLowerCase();
1956
- const lowerQuery = query.toLowerCase();
1957
- const words = lowerQuery.split(/\s+/);
1958
- const matchCount = words.filter(w => lowerContent.includes(w)).length;
1959
- const keywordScore = matchCount / words.length * 0.5;
1960
- score = Math.max(score, keywordScore);
1957
+ continue;
1961
1958
  }
1962
1959
  if (score >= threshold) {
1963
1960
  results.push({
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Auto-generated by build. Do not edit manually.
3
+ * Source of truth: root package.json → scripts/sync-version.mjs
4
+ */
5
+ export const VERSION = '4.8.34';
6
+ //# sourceMappingURL=version.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moflo/cli",
3
- "version": "4.8.32",
3
+ "version": "4.8.34",
4
4
  "type": "module",
5
5
  "description": "MoFlo CLI — AI agent orchestration with specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",
@@ -0,0 +1,260 @@
1
+ # @claude-flow/neural
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@claude-flow/neural.svg)](https://www.npmjs.com/package/@claude-flow/neural)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@claude-flow/neural.svg)](https://www.npmjs.com/package/@claude-flow/neural)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
7
+ [![AI Learning](https://img.shields.io/badge/AI-Self--Learning-purple.svg)](https://github.com/eric-cielo/moflo)
8
+
9
+ > Self-Optimizing Neural Architecture (SONA) module for Claude Flow V3 - adaptive learning, trajectory tracking, and pattern-based optimization.
10
+
11
+ ## Features
12
+
13
+ - **SONA Learning** - Self-Optimizing Neural Architecture with <0.05ms adaptation time
14
+ - **5 Learning Modes** - Real-time, Balanced, Research, Edge, and Batch modes
15
+ - **9 RL Algorithms** - PPO, A2C, DQN, Q-Learning, SARSA, Decision Transformer, and more
16
+ - **LoRA Integration** - Low-Rank Adaptation for efficient fine-tuning
17
+ - **EWC++ Memory** - Elastic Weight Consolidation for continual learning without forgetting
18
+ - **Trajectory Tracking** - Record and learn from agent execution paths
19
+ - **Pattern Recognition** - Automatic pattern extraction and reuse
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @claude-flow/neural
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { SONAManager, createSONAManager } from '@claude-flow/neural';
31
+
32
+ // Create SONA manager
33
+ const sona = createSONAManager('balanced');
34
+ await sona.initialize();
35
+
36
+ // Begin trajectory tracking
37
+ const trajectoryId = sona.beginTrajectory('code-review-task', 'development');
38
+
39
+ // Record steps
40
+ sona.recordStep(trajectoryId, 'analyze-code', 0.8, stateEmbedding, {
41
+ filesAnalyzed: 5,
42
+ issuesFound: 2
43
+ });
44
+
45
+ sona.recordStep(trajectoryId, 'generate-feedback', 0.9, newStateEmbedding);
46
+
47
+ // Complete trajectory
48
+ const trajectory = sona.completeTrajectory(trajectoryId);
49
+
50
+ // Find similar patterns for guidance
51
+ const patterns = await sona.findSimilarPatterns(contextEmbedding, 3);
52
+ ```
53
+
54
+ ## Learning Modes
55
+
56
+ | Mode | Adaptation | Quality | Memory | Use Case |
57
+ |------|------------|---------|--------|----------|
58
+ | **real-time** | <0.5ms | 70%+ | 25MB | Production, low-latency |
59
+ | **balanced** | <18ms | 75%+ | 50MB | General purpose |
60
+ | **research** | <100ms | 95%+ | 100MB | Deep exploration |
61
+ | **edge** | <1ms | 80%+ | 5MB | Resource-constrained |
62
+ | **batch** | <50ms | 85%+ | 75MB | High-throughput |
63
+
64
+ ```typescript
65
+ // Switch modes dynamically
66
+ await sona.setMode('research');
67
+
68
+ // Get current configuration
69
+ const { mode, config, optimizations } = sona.getConfig();
70
+ ```
71
+
72
+ ## API Reference
73
+
74
+ ### SONA Manager
75
+
76
+ ```typescript
77
+ import { SONAManager } from '@claude-flow/neural';
78
+
79
+ const sona = new SONAManager('balanced');
80
+ await sona.initialize();
81
+
82
+ // Trajectory Management
83
+ const trajectoryId = sona.beginTrajectory(context, domain);
84
+ sona.recordStep(trajectoryId, action, reward, stateEmbedding, metadata);
85
+ const trajectory = sona.completeTrajectory(trajectoryId, finalQuality);
86
+
87
+ // Pattern Matching
88
+ const patterns = await sona.findSimilarPatterns(embedding, k);
89
+ const pattern = sona.storePattern({ name, strategy, embedding, domain });
90
+ sona.updatePatternUsage(patternId, quality);
91
+
92
+ // Learning
93
+ await sona.triggerLearning('manual');
94
+ const output = await sona.applyAdaptations(input, domain);
95
+
96
+ // Statistics
97
+ const stats = sona.getStats();
98
+ ```
99
+
100
+ ### RL Algorithms
101
+
102
+ ```typescript
103
+ import { PPO, A2C, DQN, QLearning, SARSA, DecisionTransformer } from '@claude-flow/neural';
104
+
105
+ // Proximal Policy Optimization
106
+ const ppo = new PPO({
107
+ learningRate: 0.0003,
108
+ epsilon: 0.2,
109
+ valueCoef: 0.5
110
+ });
111
+
112
+ // Advantage Actor-Critic
113
+ const a2c = new A2C({
114
+ learningRate: 0.001,
115
+ gamma: 0.99,
116
+ entropyCoef: 0.01
117
+ });
118
+
119
+ // Deep Q-Network
120
+ const dqn = new DQN({
121
+ learningRate: 0.001,
122
+ gamma: 0.99,
123
+ epsilon: 0.1,
124
+ targetUpdateFreq: 100
125
+ });
126
+
127
+ // Decision Transformer
128
+ const dt = new DecisionTransformer({
129
+ contextLength: 20,
130
+ embeddingDim: 256,
131
+ numHeads: 4
132
+ });
133
+ ```
134
+
135
+ ### LoRA Configuration
136
+
137
+ ```typescript
138
+ // Get LoRA config for current mode
139
+ const loraConfig = sona.getLoRAConfig();
140
+ // {
141
+ // rank: 4,
142
+ // alpha: 8,
143
+ // dropout: 0.05,
144
+ // targetModules: ['q_proj', 'v_proj', 'k_proj', 'o_proj'],
145
+ // microLoRA: false
146
+ // }
147
+
148
+ // Initialize LoRA weights for a domain
149
+ const weights = sona.initializeLoRAWeights('code-generation');
150
+ ```
151
+
152
+ ### EWC++ (Elastic Weight Consolidation)
153
+
154
+ ```typescript
155
+ // Get EWC config
156
+ const ewcConfig = sona.getEWCConfig();
157
+ // {
158
+ // lambda: 2000,
159
+ // decay: 0.9,
160
+ // fisherSamples: 100,
161
+ // minFisher: 1e-8,
162
+ // online: true
163
+ // }
164
+
165
+ // Consolidate after learning a new task
166
+ sona.consolidateEWC();
167
+ ```
168
+
169
+ ### Event System
170
+
171
+ ```typescript
172
+ // Subscribe to neural events
173
+ sona.addEventListener((event) => {
174
+ switch (event.type) {
175
+ case 'trajectory_started':
176
+ console.log(`Started: ${event.trajectoryId}`);
177
+ break;
178
+ case 'trajectory_completed':
179
+ console.log(`Completed with quality: ${event.qualityScore}`);
180
+ break;
181
+ case 'pattern_matched':
182
+ console.log(`Pattern ${event.patternId} matched`);
183
+ break;
184
+ case 'learning_triggered':
185
+ console.log(`Learning: ${event.reason}`);
186
+ break;
187
+ case 'mode_changed':
188
+ console.log(`Mode: ${event.fromMode} -> ${event.toMode}`);
189
+ break;
190
+ }
191
+ });
192
+ ```
193
+
194
+ ## Mode Configurations
195
+
196
+ ```typescript
197
+ // Real-time mode (ultra-fast)
198
+ {
199
+ loraRank: 2,
200
+ learningRate: 0.001,
201
+ batchSize: 32,
202
+ trajectoryCapacity: 1000,
203
+ qualityThreshold: 0.7,
204
+ maxLatencyMs: 0.5
205
+ }
206
+
207
+ // Research mode (high quality)
208
+ {
209
+ loraRank: 16,
210
+ learningRate: 0.002,
211
+ batchSize: 64,
212
+ trajectoryCapacity: 10000,
213
+ qualityThreshold: 0.2,
214
+ maxLatencyMs: 100
215
+ }
216
+ ```
217
+
218
+ ## Performance Targets
219
+
220
+ | Metric | Target | Typical |
221
+ |--------|--------|---------|
222
+ | Adaptation latency | <0.05ms | 0.02ms |
223
+ | Pattern retrieval | <1ms | 0.5ms |
224
+ | Learning step | <10ms | 5ms |
225
+ | Quality improvement | +55% | +40-60% |
226
+ | Memory overhead | <50MB | 25-75MB |
227
+
228
+ ## TypeScript Types
229
+
230
+ ```typescript
231
+ import type {
232
+ SONAMode,
233
+ SONAModeConfig,
234
+ Trajectory,
235
+ TrajectoryStep,
236
+ Pattern,
237
+ PatternMatch,
238
+ NeuralStats,
239
+ NeuralEvent,
240
+ LoRAConfig,
241
+ LoRAWeights,
242
+ EWCConfig,
243
+ RLAlgorithm
244
+ } from '@claude-flow/neural';
245
+ ```
246
+
247
+ ## Dependencies
248
+
249
+ - [@claude-flow/memory](../memory) - Memory integration
250
+ - `@ruvector/sona` - SONA learning engine
251
+
252
+ ## Related Packages
253
+
254
+ - [@claude-flow/memory](../memory) - Vector memory for patterns
255
+ - [@claude-flow/integration](../integration) - agentic-flow integration
256
+ - [@claude-flow/performance](../performance) - Benchmarking
257
+
258
+ ## License
259
+
260
+ MIT