@claude-flow/cli 3.5.55 → 3.5.56

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 (43) hide show
  1. package/.claude/helpers/hook-handler.cjs +2 -26
  2. package/dist/src/commands/config.d.ts.map +1 -1
  3. package/dist/src/commands/config.js +92 -20
  4. package/dist/src/commands/config.js.map +1 -1
  5. package/dist/src/commands/process.d.ts.map +1 -1
  6. package/dist/src/commands/process.js +117 -63
  7. package/dist/src/commands/process.js.map +1 -1
  8. package/dist/src/commands/status.js +2 -2
  9. package/dist/src/commands/status.js.map +1 -1
  10. package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -1
  11. package/dist/src/mcp-tools/agent-tools.js +4 -8
  12. package/dist/src/mcp-tools/agent-tools.js.map +1 -1
  13. package/dist/src/mcp-tools/claims-tools.d.ts.map +1 -1
  14. package/dist/src/mcp-tools/claims-tools.js +15 -0
  15. package/dist/src/mcp-tools/claims-tools.js.map +1 -1
  16. package/dist/src/mcp-tools/coordination-tools.d.ts.map +1 -1
  17. package/dist/src/mcp-tools/coordination-tools.js +15 -8
  18. package/dist/src/mcp-tools/coordination-tools.js.map +1 -1
  19. package/dist/src/mcp-tools/github-tools.d.ts.map +1 -1
  20. package/dist/src/mcp-tools/github-tools.js +35 -93
  21. package/dist/src/mcp-tools/github-tools.js.map +1 -1
  22. package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
  23. package/dist/src/mcp-tools/hooks-tools.js +152 -60
  24. package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
  25. package/dist/src/mcp-tools/neural-tools.d.ts.map +1 -1
  26. package/dist/src/mcp-tools/neural-tools.js +6 -38
  27. package/dist/src/mcp-tools/neural-tools.js.map +1 -1
  28. package/dist/src/mcp-tools/performance-tools.d.ts.map +1 -1
  29. package/dist/src/mcp-tools/performance-tools.js +15 -110
  30. package/dist/src/mcp-tools/performance-tools.js.map +1 -1
  31. package/dist/src/mcp-tools/session-tools.d.ts.map +1 -1
  32. package/dist/src/mcp-tools/session-tools.js +23 -1
  33. package/dist/src/mcp-tools/session-tools.js.map +1 -1
  34. package/dist/src/mcp-tools/system-tools.d.ts.map +1 -1
  35. package/dist/src/mcp-tools/system-tools.js +76 -30
  36. package/dist/src/mcp-tools/system-tools.js.map +1 -1
  37. package/dist/src/mcp-tools/task-tools.js +3 -3
  38. package/dist/src/mcp-tools/task-tools.js.map +1 -1
  39. package/dist/src/mcp-tools/workflow-tools.d.ts.map +1 -1
  40. package/dist/src/mcp-tools/workflow-tools.js +20 -31
  41. package/dist/src/mcp-tools/workflow-tools.js.map +1 -1
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
  * Hooks MCP Tools
3
3
  * Provides intelligent hooks functionality via MCP protocol
4
4
  */
5
- import { mkdirSync, writeFileSync, existsSync, readFileSync, statSync } from 'fs';
5
+ import { mkdirSync, writeFileSync, existsSync, readFileSync, statSync, unlinkSync, readdirSync } from 'fs';
6
6
  import { dirname, join, resolve } from 'path';
7
7
  import { getProjectCwd } from './types.js';
8
8
  // Real vector search functions - lazy loaded to avoid circular imports
@@ -878,31 +878,44 @@ export const hooksMetrics = {
878
878
  },
879
879
  handler: async (params) => {
880
880
  const period = params.period || '24h';
881
+ // Try to read real counts from memory store
882
+ const store = loadMemoryStore();
883
+ const entries = Object.values(store.entries);
884
+ // Count patterns by looking at stored pattern entries
885
+ const patternEntries = entries.filter(e => e.key.includes('pattern'));
886
+ const routingEntries = entries.filter(e => e.key.includes('route') || e.key.includes('routing'));
887
+ const taskEntries = entries.filter(e => e.key.includes('task'));
888
+ if (entries.length === 0) {
889
+ return {
890
+ _stub: true,
891
+ message: 'No metrics data available. Metrics are collected from hooks_post-task and hooks_route calls.',
892
+ period,
893
+ patterns: { total: 0, successful: 0, failed: 0, avgConfidence: null },
894
+ agents: { routingAccuracy: null, totalRoutes: 0, topAgent: null },
895
+ commands: { totalExecuted: 0, successRate: null, avgRiskScore: null },
896
+ lastUpdated: new Date().toISOString(),
897
+ };
898
+ }
881
899
  return {
882
900
  period,
883
901
  patterns: {
884
- total: 15,
885
- successful: 12,
886
- failed: 3,
887
- avgConfidence: 0.85,
902
+ total: patternEntries.length,
903
+ successful: null,
904
+ failed: null,
905
+ avgConfidence: null,
888
906
  },
889
907
  agents: {
890
- routingAccuracy: 0.87,
891
- totalRoutes: 42,
892
- topAgent: 'coder',
908
+ routingAccuracy: null,
909
+ totalRoutes: routingEntries.length,
910
+ topAgent: null,
893
911
  },
894
912
  commands: {
895
- totalExecuted: 128,
896
- successRate: 0.94,
897
- avgRiskScore: 0.15,
898
- },
899
- performance: {
900
- flashAttention: '2.49x-7.47x speedup',
901
- memoryReduction: '50-75% reduction',
902
- searchImprovement: '150x-12,500x faster',
903
- tokenReduction: '32.3% fewer tokens',
913
+ totalExecuted: taskEntries.length,
914
+ successRate: null,
915
+ avgRiskScore: null,
904
916
  },
905
- status: 'healthy',
917
+ dataSource: 'memory-store',
918
+ entriesFound: entries.length,
906
919
  lastUpdated: new Date().toISOString(),
907
920
  };
908
921
  },
@@ -1172,14 +1185,31 @@ export const hooksExplain = {
1172
1185
  });
1173
1186
  }
1174
1187
  }
1188
+ // Calculate real historical success rate from routing outcomes file
1189
+ let historicalSuccess = null;
1190
+ let historicalNote = 'No historical data yet';
1191
+ try {
1192
+ const outcomesPath = join(resolve('.'), '.claude-flow/routing-outcomes.json');
1193
+ if (existsSync(outcomesPath)) {
1194
+ const data = JSON.parse(readFileSync(outcomesPath, 'utf-8'));
1195
+ const outcomes = data.outcomes || [];
1196
+ if (outcomes.length > 0) {
1197
+ historicalSuccess = outcomes.filter(o => o.success).length / outcomes.length;
1198
+ historicalNote = `Calculated from ${outcomes.length} recorded outcomes`;
1199
+ }
1200
+ }
1201
+ }
1202
+ catch {
1203
+ // File unreadable; leave as null
1204
+ }
1175
1205
  return {
1176
1206
  task,
1177
1207
  explanation: `The routing decision was made based on keyword analysis of the task description. ` +
1178
1208
  `The task contains keywords that match the "${suggestion.agents[0]}" specialization with ${(suggestion.confidence * 100).toFixed(0)}% confidence.`,
1179
1209
  factors: [
1180
1210
  { factor: 'Keyword Match', weight: 0.4, value: suggestion.confidence, impact: 'Primary routing signal' },
1181
- { factor: 'Historical Success', weight: 0.3, value: 0.87, impact: 'Past task success rate' },
1182
- { factor: 'Agent Availability', weight: 0.2, value: 0.95, impact: 'All suggested agents available' },
1211
+ { factor: 'Historical Success', weight: 0.3, value: historicalSuccess, impact: historicalNote },
1212
+ { factor: 'Agent Availability', weight: 0.2, value: null, impact: 'Agent availability tracking not implemented' },
1183
1213
  { factor: 'Task Complexity', weight: 0.1, value: task.length > 100 ? 0.8 : 0.3, impact: 'Complexity assessment' },
1184
1214
  ],
1185
1215
  patterns: matchedPatterns.length > 0 ? matchedPatterns : [
@@ -1191,7 +1221,9 @@ export const hooksExplain = {
1191
1221
  reasoning: [
1192
1222
  `Task analysis identified ${matchedPatterns.length || 1} relevant patterns`,
1193
1223
  `"${suggestion.agents[0]}" has highest capability match for this task type`,
1194
- `Historical success rate for similar tasks: 87%`,
1224
+ historicalSuccess !== null
1225
+ ? `Historical success rate for similar tasks: ${(historicalSuccess * 100).toFixed(0)}%`
1226
+ : `No historical outcome data available yet`,
1195
1227
  `Confidence threshold met (${(suggestion.confidence * 100).toFixed(0)}% >= 70%)`,
1196
1228
  ],
1197
1229
  },
@@ -1211,28 +1243,21 @@ export const hooksPretrain = {
1211
1243
  },
1212
1244
  },
1213
1245
  handler: async (params) => {
1214
- const path = params.path || '.';
1246
+ const repoPath = params.path || '.';
1215
1247
  const depth = params.depth || 'medium';
1216
- const startTime = Date.now();
1217
- // Scale analysis results by depth level
1218
- const multiplier = depth === 'deep' ? 3 : depth === 'shallow' ? 1 : 2;
1219
1248
  return {
1220
- path,
1249
+ success: true,
1250
+ _stub: true,
1251
+ message: 'Pre-training requires running the pretrain CLI command. This hook provides status only.',
1252
+ path: repoPath,
1221
1253
  depth,
1222
1254
  stats: {
1223
- filesAnalyzed: 42 * multiplier,
1224
- patternsExtracted: 15 * multiplier,
1225
- strategiesLearned: 8 * multiplier,
1226
- trajectoriesEvaluated: 23 * multiplier,
1227
- contradictionsResolved: 3,
1228
- },
1229
- pipeline: {
1230
- retrieve: { status: 'completed', duration: 120 * multiplier },
1231
- judge: { status: 'completed', duration: 180 * multiplier },
1232
- distill: { status: 'completed', duration: 90 * multiplier },
1233
- consolidate: { status: 'completed', duration: 60 * multiplier },
1255
+ filesAnalyzed: null,
1256
+ patternsExtracted: null,
1257
+ strategiesLearned: null,
1258
+ trajectoriesEvaluated: null,
1259
+ contradictionsResolved: null,
1234
1260
  },
1235
- duration: Date.now() - startTime + (500 * multiplier),
1236
1261
  };
1237
1262
  },
1238
1263
  };
@@ -1335,12 +1360,14 @@ export const hooksTransfer = {
1335
1360
  'command-risk': sourceEntries.filter(e => e.key.includes('command') || e.metadata?.type === 'command-risk').length,
1336
1361
  'agent-success': sourceEntries.filter(e => e.key.includes('agent') || e.metadata?.type === 'agent-success').length,
1337
1362
  };
1338
- // If source has no patterns, provide demo data
1363
+ // If source has no patterns, report honestly instead of substituting demo data
1339
1364
  if (Object.values(byType).every(v => v === 0)) {
1340
- byType['file-patterns'] = 8;
1341
- byType['task-routing'] = 12;
1342
- byType['command-risk'] = 5;
1343
- byType['agent-success'] = 15;
1365
+ return {
1366
+ success: false,
1367
+ message: 'No patterns found in source project',
1368
+ sourcePath,
1369
+ transferred: 0,
1370
+ };
1344
1371
  }
1345
1372
  if (filter) {
1346
1373
  Object.keys(byType).forEach(key => {
@@ -1350,6 +1377,7 @@ export const hooksTransfer = {
1350
1377
  }
1351
1378
  const total = Object.values(byType).reduce((a, b) => a + b, 0);
1352
1379
  return {
1380
+ success: true,
1353
1381
  sourcePath,
1354
1382
  transferred: {
1355
1383
  total,
@@ -1364,7 +1392,7 @@ export const hooksTransfer = {
1364
1392
  avgConfidence: 0.82 + (minConfidence > 0.8 ? 0.1 : 0),
1365
1393
  avgAge: '3 days',
1366
1394
  },
1367
- dataSource: Object.values(sourceStore.entries).length > 0 ? 'source-project' : 'demo-data',
1395
+ dataSource: 'source-project',
1368
1396
  };
1369
1397
  },
1370
1398
  };
@@ -1470,6 +1498,25 @@ export const hooksSessionEnd = {
1470
1498
  // Daemon may not be running
1471
1499
  }
1472
1500
  }
1501
+ // Read actual counts from stores
1502
+ const store = loadMemoryStore();
1503
+ const allEntries = Object.values(store.entries);
1504
+ const taskCount = allEntries.filter(e => e.key.includes('task')).length;
1505
+ const agentCount = allEntries.filter(e => e.key.includes('agent')).length;
1506
+ const patternCount = allEntries.filter(e => e.key.includes('pattern')).length;
1507
+ const trajectoryCount = activeTrajectories.size;
1508
+ // Check for pending-insights.jsonl
1509
+ let insightCount = 0;
1510
+ try {
1511
+ const insightsPath = resolve(join('.claude-flow', 'data', 'pending-insights.jsonl'));
1512
+ if (existsSync(insightsPath)) {
1513
+ const content = readFileSync(insightsPath, 'utf-8').trim();
1514
+ insightCount = content ? content.split('\n').length : 0;
1515
+ }
1516
+ }
1517
+ catch {
1518
+ // File not available
1519
+ }
1473
1520
  // Phase 5: Wire ReflexionMemory session end + NightlyLearner consolidation via bridge
1474
1521
  let sessionPersistence = null;
1475
1522
  try {
@@ -1477,8 +1524,8 @@ export const hooksSessionEnd = {
1477
1524
  const result = await bridge.bridgeSessionEnd({
1478
1525
  sessionId,
1479
1526
  summary: saveState ? 'Session ended with state saved' : 'Session ended',
1480
- tasksCompleted: 12,
1481
- patternsLearned: 8,
1527
+ tasksCompleted: taskCount,
1528
+ patternsLearned: patternCount,
1482
1529
  });
1483
1530
  if (result) {
1484
1531
  sessionPersistence = {
@@ -1497,17 +1544,15 @@ export const hooksSessionEnd = {
1497
1544
  daemon: { stopped: daemonStopped },
1498
1545
  sessionPersistence: sessionPersistence || { controller: 'none', persisted: false },
1499
1546
  summary: {
1500
- tasksExecuted: 12,
1501
- tasksSucceeded: 10,
1502
- tasksFailed: 2,
1503
- commandsExecuted: 45,
1504
- filesModified: 23,
1505
- agentsSpawned: 5,
1547
+ tasksExecuted: taskCount,
1548
+ filesModified: 0,
1549
+ agentsSpawned: agentCount,
1550
+ pendingInsights: insightCount,
1551
+ memoryEntries: allEntries.length,
1506
1552
  },
1507
1553
  learningUpdates: {
1508
- patternsLearned: 8,
1509
- trajectoriesRecorded: 12,
1510
- confidenceImproved: 0.05,
1554
+ patternsLearned: patternCount,
1555
+ trajectoriesRecorded: trajectoryCount,
1511
1556
  },
1512
1557
  };
1513
1558
  },
@@ -1726,13 +1771,60 @@ export const hooksIntelligenceReset = {
1726
1771
  properties: {},
1727
1772
  },
1728
1773
  handler: async () => {
1774
+ const cwd = getProjectCwd();
1775
+ const cleared = {
1776
+ trajectories: 0,
1777
+ patterns: 0,
1778
+ dataFiles: 0,
1779
+ neuralFiles: 0,
1780
+ };
1781
+ const deletedFiles = [];
1782
+ // Clear intelligence data files if they exist
1783
+ const dataFiles = [
1784
+ join(cwd, '.claude-flow', 'data', 'auto-memory-store.json'),
1785
+ join(cwd, '.claude-flow', 'data', 'graph-state.json'),
1786
+ join(cwd, '.claude-flow', 'data', 'ranked-context.json'),
1787
+ ];
1788
+ for (const filePath of dataFiles) {
1789
+ if (existsSync(filePath)) {
1790
+ try {
1791
+ unlinkSync(filePath);
1792
+ cleared.dataFiles++;
1793
+ deletedFiles.push(filePath);
1794
+ }
1795
+ catch {
1796
+ // Skip files that cannot be deleted
1797
+ }
1798
+ }
1799
+ }
1800
+ // Clear neural directory if it exists
1801
+ const neuralDir = join(cwd, '.claude-flow', 'neural');
1802
+ if (existsSync(neuralDir)) {
1803
+ try {
1804
+ const files = readdirSync(neuralDir);
1805
+ for (const file of files) {
1806
+ try {
1807
+ const filePath = join(neuralDir, file);
1808
+ unlinkSync(filePath);
1809
+ cleared.neuralFiles++;
1810
+ deletedFiles.push(filePath);
1811
+ }
1812
+ catch {
1813
+ // Skip files that cannot be deleted
1814
+ }
1815
+ }
1816
+ }
1817
+ catch {
1818
+ // Directory read failed
1819
+ }
1820
+ }
1821
+ // Clear in-memory trajectories
1822
+ cleared.trajectories = activeTrajectories.size;
1823
+ activeTrajectories.clear();
1729
1824
  return {
1730
1825
  reset: true,
1731
- cleared: {
1732
- trajectories: 156,
1733
- patterns: 89,
1734
- hnswIndex: 12500,
1735
- },
1826
+ cleared,
1827
+ deletedFiles,
1736
1828
  timestamp: new Date().toISOString(),
1737
1829
  };
1738
1830
  },