🐛 Fix: Enhanced hooks pre-task exit with timeout protection

- Added timeout protection for ruv-swarm availability check (3s)
- Fallback to skip ruv-swarm hook if timeout occurs
- Force process exit with setTimeout to prevent hanging
- Handles npx remote execution scenarios properly

This addresses the hanging issue when running:
npx claude-flow@alpha hooks pre-task --description "task"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
rUvandClaude committed 2025-07-28 21:43:51 +00:00
1 parent 3dfd2ee160
commit 43ab723db6
5 files changed
+44 -28

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
#!/bin/sh
# Claude-Flow Smart Dispatcher - Detects and uses the best available runtime
VERSION="2.0.0-alpha.76"
VERSION="2.0.0-alpha.77"
# Determine the correct path based on how the script is invoked
if [ -L "$0" ]; then
+1 -1
View File
@@ -11,7 +11,7 @@ import { existsSync } from 'fs';
import { spawn } from 'child_process';
import process from 'process';
const VERSION = "2.0.0-alpha.76";
const VERSION = "2.0.0-alpha.77";
// Get script directory and root directory
const __filename = fileURLToPath(import.meta.url);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "claude-flow",
"version": "2.0.0-alpha.76",
"version": "2.0.0-alpha.77",
"description": "Enterprise-grade AI agent orchestration with ruv-swarm integration (Alpha Release)",
"main": "cli.mjs",
"bin": {
+2 -2
View File
@@ -5,14 +5,14 @@
import { HelpFormatter } from './help-formatter.js';
export const VERSION = '2.0.0-alpha.76';
export const VERSION = '2.0.0-alpha.77';
export const MAIN_HELP = `
🌊 Claude-Flow v${VERSION} - Enterprise-Grade AI Agent Orchestration Platform
🎯 ENTERPRISE FEATURES: Complete ruv-swarm integration with 87 MCP tools, neural networking, and production-ready infrastructure
🐝 NEW: Advanced Hive Mind System with Queen-led coordination, collective intelligence, and unlimited scaling
⚡ ALPHA 76: Fixed hooks pre-task command not exiting properly
⚡ ALPHA 77: Enhanced hooks pre-task exit handling with timeout protection
USAGE:
claude-flow <command> [options]
+39 -23
View File
@@ -137,29 +137,40 @@ async function preTaskCommand(subArgs, flags) {
console.log(` 💾 Saved to .swarm/memory.db`);
// Execute ruv-swarm hook if available
const isAvailable = await checkRuvSwarmAvailable();
if (isAvailable) {
console.log(`\n🔄 Executing ruv-swarm pre-task hook...`);
const hookResult = await execRuvSwarmHook('pre-task', {
description,
'task-id': taskId,
'auto-spawn-agents': autoSpawnAgents,
...(agentId ? { 'agent-id': agentId } : {}),
});
// Execute ruv-swarm hook if available (with timeout for npx scenarios)
try {
const checkPromise = checkRuvSwarmAvailable();
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 3000)
);
const isAvailable = await Promise.race([checkPromise, timeoutPromise]);
if (isAvailable) {
console.log(`\n🔄 Executing ruv-swarm pre-task hook...`);
const hookResult = await execRuvSwarmHook('pre-task', {
description,
'task-id': taskId,
'auto-spawn-agents': autoSpawnAgents,
...(agentId ? { 'agent-id': agentId } : {}),
});
if (hookResult.success) {
await store.store(
`task:${taskId}:ruv-output`,
{
output: hookResult.output,
timestamp: new Date().toISOString(),
},
{ namespace: 'hooks:ruv-swarm' },
);
if (hookResult.success) {
await store.store(
`task:${taskId}:ruv-output`,
{
output: hookResult.output,
timestamp: new Date().toISOString(),
},
{ namespace: 'hooks:ruv-swarm' },
);
printSuccess(`✅ Pre-task hook completed successfully`);
printSuccess(`✅ Pre-task hook completed successfully`);
}
}
} catch (err) {
// Skip ruv-swarm hook if it times out or fails
console.log(`\n⚠️ Skipping ruv-swarm hook (${err.message})`);
}
console.log(`\n🎯 TASK PREPARATION COMPLETE`);
@@ -169,8 +180,10 @@ async function preTaskCommand(subArgs, flags) {
memoryStore.close();
}
// Ensure the process exits cleanly
process.exit(0);
// Force exit after a short delay to ensure cleanup
setTimeout(() => {
process.exit(0);
}, 100);
} catch (err) {
printError(`Pre-task hook failed: ${err.message}`);
@@ -179,7 +192,10 @@ async function preTaskCommand(subArgs, flags) {
memoryStore.close();
}
process.exit(1);
// Force exit after a short delay to ensure cleanup
setTimeout(() => {
process.exit(1);
}, 100);
}
}