claude-flow 2.5.0-alpha.139 → 2.5.0-alpha.141

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 (42) hide show
  1. package/.claude/settings.json +3 -2
  2. package/README.md +50 -55
  3. package/bin/claude-flow +1 -1
  4. package/dist/src/cli/commands/hive-mind/pause.js +2 -9
  5. package/dist/src/cli/commands/hive-mind/pause.js.map +1 -1
  6. package/dist/src/cli/commands/index.js +1 -114
  7. package/dist/src/cli/commands/index.js.map +1 -1
  8. package/dist/src/cli/commands/swarm-spawn.js +5 -33
  9. package/dist/src/cli/commands/swarm-spawn.js.map +1 -1
  10. package/dist/src/cli/help-formatter.js.map +1 -1
  11. package/dist/src/cli/help-text.js +16 -2
  12. package/dist/src/cli/help-text.js.map +1 -1
  13. package/dist/src/cli/simple-commands/hooks.js +233 -0
  14. package/dist/src/cli/simple-commands/hooks.js.map +1 -1
  15. package/dist/src/cli/validation-helper.js.map +1 -1
  16. package/dist/src/core/version.js +1 -1
  17. package/dist/src/hooks/index.js +0 -3
  18. package/dist/src/hooks/index.js.map +1 -1
  19. package/dist/src/mcp/claude-flow-tools.js +205 -150
  20. package/dist/src/mcp/claude-flow-tools.js.map +1 -1
  21. package/dist/src/mcp/mcp-server.js +125 -0
  22. package/dist/src/mcp/mcp-server.js.map +1 -1
  23. package/dist/src/memory/swarm-memory.js +421 -340
  24. package/dist/src/memory/swarm-memory.js.map +1 -1
  25. package/dist/src/sdk/query-control.js +293 -139
  26. package/dist/src/sdk/query-control.js.map +1 -1
  27. package/dist/src/sdk/session-forking.js +206 -129
  28. package/dist/src/sdk/session-forking.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/cli/commands/hive-mind/pause.ts +2 -15
  31. package/src/cli/commands/index.ts +1 -84
  32. package/src/cli/commands/swarm-spawn.ts +3 -47
  33. package/src/cli/help-text.js +16 -2
  34. package/src/cli/simple-cli.ts +0 -1
  35. package/src/cli/simple-commands/hooks.js +310 -0
  36. package/src/hooks/index.ts +0 -5
  37. package/src/mcp/claude-flow-tools.ts +203 -120
  38. package/src/mcp/mcp-server.js +86 -0
  39. package/src/sdk/query-control.ts +377 -223
  40. package/src/sdk/session-forking.ts +312 -207
  41. package/.claude/commands/coordination/README.md +0 -9
  42. package/.claude/commands/memory/README.md +0 -9
@@ -64,6 +64,15 @@ export async function hooksAction(subArgs, flags) {
64
64
  case 'notify':
65
65
  await notifyCommand(subArgs, flags);
66
66
  break;
67
+ case 'modify-bash':
68
+ await modifyBashCommand(subArgs, flags);
69
+ break;
70
+ case 'modify-file':
71
+ await modifyFileCommand(subArgs, flags);
72
+ break;
73
+ case 'modify-git-commit':
74
+ await modifyGitCommitCommand(subArgs, flags);
75
+ break;
67
76
  default:
68
77
  printError(`Unknown hooks command: ${subcommand}`);
69
78
  showHooksHelp();
@@ -992,6 +1001,208 @@ async function notifyCommand(subArgs, flags) {
992
1001
  printError(`Notify hook failed: ${err.message}`);
993
1002
  }
994
1003
  }
1004
+ async function modifyBashCommand(subArgs, flags) {
1005
+ let input = '';
1006
+ let hasInput = false;
1007
+ const timeout = setTimeout(()=>{
1008
+ if (!hasInput) {
1009
+ console.log('Usage: echo \'{"tool_input":{"command":"your command"}}\' | claude-flow hooks modify-bash');
1010
+ console.log('\nThis hook reads JSON from stdin and outputs modified JSON.');
1011
+ console.log('It is designed for use with Claude Code v2.0.10+ PreToolUse feature.');
1012
+ console.log('\nExample:');
1013
+ console.log(' echo \'{"tool_input":{"command":"rm test.txt"}}\' | claude-flow hooks modify-bash');
1014
+ process.exit(0);
1015
+ }
1016
+ }, 100);
1017
+ for await (const chunk of process.stdin){
1018
+ hasInput = true;
1019
+ clearTimeout(timeout);
1020
+ input += chunk;
1021
+ }
1022
+ if (!input.trim()) {
1023
+ return;
1024
+ }
1025
+ const toolInput = JSON.parse(input);
1026
+ const command = toolInput.tool_input?.command || '';
1027
+ if (!command) {
1028
+ console.log(input);
1029
+ return;
1030
+ }
1031
+ let modifiedCommand = command;
1032
+ const notes = [];
1033
+ if (/^rm\s/.test(command) && !/-[iI]/.test(command)) {
1034
+ modifiedCommand = command.replace(/^rm /, 'rm -i ');
1035
+ notes.push('[Safety: Added -i flag for interactive confirmation]');
1036
+ }
1037
+ if (/^ll(\s|$)/.test(command)) {
1038
+ modifiedCommand = command.replace(/^ll/, 'ls -lah');
1039
+ notes.push('[Alias: ll → ls -lah]');
1040
+ } else if (/^la(\s|$)/.test(command)) {
1041
+ modifiedCommand = command.replace(/^la/, 'ls -la');
1042
+ notes.push('[Alias: la → ls -la]');
1043
+ }
1044
+ if (/>\s*test.*\.(txt|log|tmp|json|md)/.test(command) && !/\/tmp\//.test(command)) {
1045
+ modifiedCommand = command.replace(/>\s*(test[^/]*\.(txt|log|tmp|json|md))/, '> /tmp/$1');
1046
+ notes.push('[Path: Redirected test file to /tmp/]');
1047
+ }
1048
+ if (/(password|secret|token|api[-_]?key|auth)/i.test(command) && !/#\s*SECRETS_OK/.test(command)) {
1049
+ notes.push('[Security: Command contains sensitive keywords. Add "# SECRETS_OK" to bypass]');
1050
+ }
1051
+ const output = {
1052
+ ...toolInput,
1053
+ tool_input: {
1054
+ ...toolInput.tool_input,
1055
+ command: modifiedCommand
1056
+ }
1057
+ };
1058
+ if (notes.length > 0) {
1059
+ output.modification_notes = notes.join(' ');
1060
+ }
1061
+ console.log(JSON.stringify(output, null, 2));
1062
+ }
1063
+ async function modifyFileCommand(subArgs, flags) {
1064
+ let input = '';
1065
+ let hasInput = false;
1066
+ const timeout = setTimeout(()=>{
1067
+ if (!hasInput) {
1068
+ console.log('Usage: echo \'{"tool_input":{"file_path":"your/file.js"}}\' | claude-flow hooks modify-file');
1069
+ console.log('\nThis hook reads JSON from stdin and outputs modified JSON.');
1070
+ console.log('It is designed for use with Claude Code v2.0.10+ PreToolUse feature.');
1071
+ console.log('\nExample:');
1072
+ console.log(' echo \'{"tool_input":{"file_path":"test.js"}}\' | claude-flow hooks modify-file');
1073
+ process.exit(0);
1074
+ }
1075
+ }, 100);
1076
+ for await (const chunk of process.stdin){
1077
+ hasInput = true;
1078
+ clearTimeout(timeout);
1079
+ input += chunk;
1080
+ }
1081
+ if (!input.trim()) {
1082
+ return;
1083
+ }
1084
+ const toolInput = JSON.parse(input);
1085
+ const filePath = toolInput.tool_input?.file_path || toolInput.tool_input?.path || '';
1086
+ if (!filePath) {
1087
+ console.log(input);
1088
+ return;
1089
+ }
1090
+ let modifiedPath = filePath;
1091
+ let shouldModify = false;
1092
+ const notes = [];
1093
+ const isRootFile = /^[^/]*\.(js|ts|jsx|tsx|py|java|go|rs|cpp|c|h)$/.test(filePath) || /^test.*\.(txt|log|tmp|json|md)$/.test(filePath) || /^(temp|tmp|working)/.test(filePath);
1094
+ if (isRootFile) {
1095
+ if (/test.*\.(test|spec)\.|\.test\.|\.spec\./.test(filePath)) {
1096
+ modifiedPath = `tests/${filePath}`;
1097
+ shouldModify = true;
1098
+ notes.push('[Organization: Moved test file to /tests/]');
1099
+ } else if (/test.*\.md|temp.*\.md|working.*\.md|scratch.*\.md/.test(filePath)) {
1100
+ modifiedPath = `docs/working/${filePath}`;
1101
+ shouldModify = true;
1102
+ notes.push('[Organization: Moved working document to /docs/working/]');
1103
+ } else if (/\.(js|ts|jsx|tsx|py)$/.test(filePath)) {
1104
+ modifiedPath = `src/${filePath}`;
1105
+ shouldModify = true;
1106
+ notes.push('[Organization: Moved source file to /src/]');
1107
+ } else if (/^(temp|tmp|scratch)/.test(filePath)) {
1108
+ modifiedPath = `/tmp/${filePath}`;
1109
+ shouldModify = true;
1110
+ notes.push('[Organization: Redirected temporary file to /tmp/]');
1111
+ }
1112
+ }
1113
+ if (/\.(ts|tsx|js|jsx)$/.test(modifiedPath)) {
1114
+ notes.push('[Tip: Auto-format with Prettier/ESLint recommended]');
1115
+ } else if (/\.py$/.test(modifiedPath)) {
1116
+ notes.push('[Tip: Auto-format with Black/autopep8 recommended]');
1117
+ }
1118
+ const output = {
1119
+ ...toolInput,
1120
+ tool_input: {
1121
+ ...toolInput.tool_input
1122
+ }
1123
+ };
1124
+ if (shouldModify) {
1125
+ if (toolInput.tool_input.file_path) {
1126
+ output.tool_input.file_path = modifiedPath;
1127
+ } else {
1128
+ output.tool_input.path = modifiedPath;
1129
+ }
1130
+ }
1131
+ if (notes.length > 0) {
1132
+ output.modification_notes = notes.join(' ');
1133
+ }
1134
+ console.log(JSON.stringify(output, null, 2));
1135
+ }
1136
+ async function modifyGitCommitCommand(subArgs, flags) {
1137
+ let input = '';
1138
+ let hasInput = false;
1139
+ const timeout = setTimeout(()=>{
1140
+ if (!hasInput) {
1141
+ console.log('Usage: echo \'{"tool_input":{"command":"git commit -m \\"message\\""}}\' | claude-flow hooks modify-git-commit');
1142
+ console.log('\nThis hook reads JSON from stdin and outputs modified JSON.');
1143
+ console.log('It is designed for use with Claude Code v2.0.10+ PreToolUse feature.');
1144
+ console.log('\nExample:');
1145
+ console.log(' echo \'{"tool_input":{"command":"git commit -m \\"fix bug\\""}}\' | claude-flow hooks modify-git-commit');
1146
+ process.exit(0);
1147
+ }
1148
+ }, 100);
1149
+ for await (const chunk of process.stdin){
1150
+ hasInput = true;
1151
+ clearTimeout(timeout);
1152
+ input += chunk;
1153
+ }
1154
+ if (!input.trim()) {
1155
+ return;
1156
+ }
1157
+ const toolInput = JSON.parse(input);
1158
+ const command = toolInput.tool_input?.command || '';
1159
+ if (!command || !/git commit/.test(command)) {
1160
+ console.log(input);
1161
+ return;
1162
+ }
1163
+ const msgMatch = command.match(/-m\s+["']([^"']+)["']/) || command.match(/-m\s+(\S+)/);
1164
+ const commitMsg = msgMatch ? msgMatch[1] : '';
1165
+ if (!commitMsg || /^\[(feat|fix|docs|style|refactor|test|chore|perf)\]/.test(commitMsg)) {
1166
+ console.log(input);
1167
+ return;
1168
+ }
1169
+ const notes = [];
1170
+ let branch = 'main';
1171
+ let ticket = '';
1172
+ try {
1173
+ const { execSync } = await import('child_process');
1174
+ branch = execSync('git rev-parse --abbrev-ref HEAD', {
1175
+ encoding: 'utf8'
1176
+ }).trim();
1177
+ const ticketMatch = branch.match(/[A-Z]+-[0-9]+/);
1178
+ if (ticketMatch) {
1179
+ ticket = ticketMatch[0];
1180
+ }
1181
+ } catch {}
1182
+ let type = 'chore';
1183
+ if (/^(add|implement|create|new)/i.test(commitMsg)) type = 'feat';
1184
+ else if (/^(fix|resolve|patch|correct)/i.test(commitMsg)) type = 'fix';
1185
+ else if (/^(update|modify|change|improve)/i.test(commitMsg)) type = 'refactor';
1186
+ else if (/^(doc|documentation|readme)/i.test(commitMsg)) type = 'docs';
1187
+ else if (/^(test|testing|spec)/i.test(commitMsg)) type = 'test';
1188
+ else if (/^(style|format|lint)/i.test(commitMsg)) type = 'style';
1189
+ else if (/^(perf|optimize|speed)/i.test(commitMsg)) type = 'perf';
1190
+ let formattedMsg = ticket ? `[${type}] ${commitMsg} (${ticket})` : `[${type}] ${commitMsg}`;
1191
+ if (!/Co-Authored-By/.test(command)) {
1192
+ formattedMsg += `\n\n🤖 Generated with Claude Flow\nCo-Authored-By: claude-flow <noreply@ruv.io>`;
1193
+ }
1194
+ const modifiedCommand = command.replace(/-m\s+["'][^"']+["']|-m\s+\S+/, `-m "$(cat <<'EOF'\n${formattedMsg}\nEOF\n)"`);
1195
+ notes.push(`[Auto-formatted: ${type} type${ticket ? ` + ${ticket}` : ''}]`);
1196
+ const output = {
1197
+ ...toolInput,
1198
+ tool_input: {
1199
+ ...toolInput.tool_input,
1200
+ command: modifiedCommand
1201
+ },
1202
+ modification_notes: notes.join(' ')
1203
+ };
1204
+ console.log(JSON.stringify(output, null, 2));
1205
+ }
995
1206
  function showHooksHelp() {
996
1207
  console.log('Claude Flow Hooks (with .swarm/memory.db persistence):\n');
997
1208
  console.log('Pre-Operation Hooks:');
@@ -1026,6 +1237,22 @@ function showHooksHelp() {
1026
1237
  console.log(' --export-metrics Export performance metrics');
1027
1238
  console.log(' session-restore Load previous session state');
1028
1239
  console.log(' notify Custom notifications');
1240
+ console.log('\n===== NEW: PreToolUse Modification Hooks (v2.0.10+) =====');
1241
+ console.log(' modify-bash Modify Bash tool inputs (reads/writes JSON via stdin/stdout)');
1242
+ console.log(' • Safety: Adds -i flag to rm commands');
1243
+ console.log(' • Aliases: ll → ls -lah, la → ls -la');
1244
+ console.log(' • Path correction: Redirects test files to /tmp');
1245
+ console.log(' • Secret detection: Warns about sensitive keywords');
1246
+ console.log('');
1247
+ console.log(' modify-file Modify Write/Edit tool inputs (reads/writes JSON via stdin/stdout)');
1248
+ console.log(' • Root folder protection: Moves files to appropriate directories');
1249
+ console.log(' • Organization: Tests → /tests/, Sources → /src/, Docs → /docs/');
1250
+ console.log(' • Format hints: Suggests Prettier, Black, etc.');
1251
+ console.log('');
1252
+ console.log(' modify-git-commit Modify git commit messages (reads/writes JSON via stdin/stdout)');
1253
+ console.log(' • Conventional commits: Auto-adds [feat], [fix], [docs], etc.');
1254
+ console.log(' • Ticket extraction: Extracts JIRA tickets from branch names');
1255
+ console.log(' • Co-author: Adds Claude Flow co-author footer');
1029
1256
  console.log('\nExamples:');
1030
1257
  console.log(' hooks pre-command --command "npm test" --validate-safety true');
1031
1258
  console.log(' hooks pre-edit --file "src/app.js" --auto-assign-agents true');
@@ -1034,11 +1261,17 @@ function showHooksHelp() {
1034
1261
  console.log(' hooks session-end --generate-summary true --export-metrics true');
1035
1262
  console.log(' hooks agent-spawned --name "CodeReviewer" --type "reviewer"');
1036
1263
  console.log(' hooks notify --message "Build completed" --level "success"');
1264
+ console.log('');
1265
+ console.log(' # New modification hooks (stdin/stdout JSON):');
1266
+ console.log(' echo \'{"tool_input":{"command":"rm test.txt"}}\' | hooks modify-bash');
1267
+ console.log(' echo \'{"tool_input":{"file_path":"test.js"}}\' | hooks modify-file');
1268
+ console.log(' echo \'{"tool_input":{"command":"git commit -m \\"fix bug\\""}}\' | hooks modify-git-commit');
1037
1269
  console.log('\nCompatibility:');
1038
1270
  console.log(' • pre-command and pre-bash are aliases');
1039
1271
  console.log(' • post-command and post-bash are aliases');
1040
1272
  console.log(' • Both --dash-case and camelCase parameters supported');
1041
1273
  console.log(' • All parameters from settings.json template supported');
1274
+ console.log(' • New modification hooks work with Claude Code v2.0.10+ PreToolUse feature');
1042
1275
  }
1043
1276
  export default hooksAction;
1044
1277